Quiz Question 1
One quiz or survey step — "Question 2 of 7" with a bar, the question as the heading, lettered radio rows or image tiles as a native keyboard-accessible group, and one advance button that never moves.
Use it in a prompt
Use forms/quiz-question from the FunnelDNA library. Follow the skill and theme contract. Ask me for the copy, images, and brand details you need; do not invent proof.
Paste into Claude or ChatGPT with FunnelDNA connected (MCP setup), or alongside the skill.
Use it in code
- Save
component.tsx(Code tab) ascomponents/funneldna/forms/quiz-question.tsx. - Import it and pass your copy and images (Props tab):
import { QuizQuestion } from "@/components/funneldna/forms/quiz-question"
It restyles from the theme tokens on any wrapper (Theme tab). The specimen source is a complete working example.
pieces/forms/quiz-question/component.tsx 506 lines
// Asks one quiz question with clear progress and easy answer choices, then moves the visitor to the next step.
"use client"
import * as React from "react"
import { Check, CircleAlert, LoaderCircle } from "lucide-react"
export type QuizQuestionProps = {
/** Templates accept {next}, {saved}, {current} and {total} as text. */
copy?: Partial<typeof defaultCopy>
/** Validated selection; takes precedence over onNext. A returned promise shows the saving label. */
onSubmit?: (values: string[]) => void | Promise<void>
/** Short name of the quiz, shown top right ("Your funnel plan"). */
quizName?: string
/** 1-based index of this question. */
current: number
total: number
/** The question. A string lets `highlight` mark one phrase. */
question: React.ReactNode
/** One continuous phrase inside `question` that gets the marker stroke. */
highlight?: string
/** One line under the question: why you ask, or how to pick. */
hint?: React.ReactNode
/** Form field name for the answer. */
name?: string
/** Two to six choices. */
choices: QuizChoice[]
/** Pick all that apply (checkboxes). */
multiple?: boolean
/** Pre-selected value(s), to restore the answer when the visitor comes back. */
defaultValue?: string | string[]
/** "Continue", or "Show My Plan" on the last step. */
nextLabel?: string
backLabel?: string
/** Shows a secondary Back button under the action. Omit on question 1. */
onBack?: () => void
/** Legacy alias for onSubmit. */
onNext?: (values: string[]) => void | Promise<void>
/** Announced under the button when nothing is selected. */
missingMessage?: string
/** @deprecated No longer rendered: the builder wires what happens after submit. */
savedLabel?: string
disabled?: boolean
/** Desktop keyboard hint under the button. */
showKeyboardTip?: boolean
/** Studio preview state. "success" is accepted for older callers and renders as default. */
state?: QuizQuestionState
className?: string
}
export function QuizQuestion({
copy: copyOverrides,
onSubmit,
quizName,
current,
total,
question,
highlight,
hint,
name = "answer",
choices,
multiple = false,
defaultValue,
nextLabel = "Continue",
backLabel = "Back",
onBack,
onNext,
missingMessage,
disabled = false,
showKeyboardTip = true,
state = "default",
className,
}: QuizQuestionProps) {
const copy = { ...defaultCopy, ...copyOverrides }
const submitValue = onSubmit === undefined ? onNext : onSubmit
const uid = React.useId()
const formRef = React.useRef<HTMLFormElement>(null)
const mounted = React.useRef(true)
const presetKey = JSON.stringify(toList(defaultValue))
const [selected, setSelected] = React.useState<string[]>(() => toList(defaultValue))
const [status, setStatus] = React.useState<Status>("idle")
const [shake, setShake] = React.useState(0)
React.useEffect(() => {
const preset = JSON.parse(presetKey) as string[]
if (state === "error") {
setSelected([])
setStatus("error")
} else {
setSelected(preset)
setStatus("idle")
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state, presetKey])
React.useEffect(() => {
mounted.current = true
return () => {
mounted.current = false
}
}, [])
const isDisabled = disabled || state === "disabled"
const cur = Math.min(Math.max(current, 1), Math.max(total, 1))
const tiles = choices.some((c) => c.image)
const lastLetter = String.fromCharCode(64 + Math.min(choices.length, 26))
const qId = `${uid}-q`
const hintId = `${uid}-hint`
const errId = `${uid}-err`
const choose = (value: string) => {
if (isDisabled || status === "loading") return
setSelected((prev) =>
multiple
? prev.includes(value)
? prev.filter((v) => v !== value)
: [...prev, value]
: [value]
)
setStatus("idle")
}
const submit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (isDisabled || status === "loading") return
if (!selected.length) {
setStatus("error")
setShake((n) => n + 1)
e.currentTarget.querySelector<HTMLInputElement>("input.qq-input")?.focus()
return
}
const result = submitValue?.([...selected])
if (!result) return
setStatus("loading")
try {
await result
} catch {
// No failure UI in this piece; the caller reports errors.
} finally {
if (mounted.current) setStatus("idle")
}
}
const onKeyDown = (e: React.KeyboardEvent<HTMLFormElement>) => {
if (isDisabled || e.metaKey || e.ctrlKey || e.altKey) return
const t = e.target as HTMLElement
if (t instanceof HTMLTextAreaElement) return
if (t instanceof HTMLInputElement && t.type !== "radio" && t.type !== "checkbox") return
if (e.key === "Enter" && t instanceof HTMLInputElement) {
e.preventDefault()
formRef.current?.requestSubmit()
return
}
if (e.key.length === 1) {
const idx = e.key.toUpperCase().charCodeAt(0) - 65
if (idx >= 0 && idx < Math.min(choices.length, 26)) {
e.preventDefault()
choose(choices[idx].value)
formRef.current?.querySelectorAll<HTMLInputElement>("input.qq-input")[idx]?.focus()
}
}
}
const describedBy =
[hint ? hintId : "", status === "error" ? errId : ""].filter(Boolean).join(" ") || undefined
const live = status === "loading" ? copy.savingAnnouncement : ""
return (
<div
className={["cf-quiz-question qq", className].filter(Boolean).join(" ")}
data-status={status}
data-tiles={tiles ? "" : undefined}
>
<style>{CSS}</style>
<form ref={formRef} noValidate onSubmit={submit} onKeyDown={onKeyDown}>
<div className="qq-meta">
<p className="qq-count">
{copy.questionLabel} <b>{cur}</b> {copy.ofLabel} {total}
</p>
{quizName && <p className="qq-name">{quizName}</p>}
</div>
<div
className="qq-track"
role="progressbar"
aria-label={copy.progress}
aria-valuemin={1}
aria-valuemax={total}
aria-valuenow={cur}
aria-valuetext={text(copy.progressValue, { current: cur, total })}
>
{Array.from({ length: Math.max(total, 1) }, (_, i) => {
const fill =
i < cur - 1 ? 100 : i === cur - 1 ? 50 : 0
return (
<span key={i} className="qq-seg" data-now={i === cur - 1 ? "" : undefined}>
<i style={{ width: `${fill}%` }} />
</span>
)
})}
</div>
<fieldset
className="qq-set"
aria-labelledby={qId}
aria-describedby={describedBy}
disabled={isDisabled}
>
<div className="qq-head">
<h2 id={qId} className="qq-q">
{withMarker(question, highlight)}
</h2>
{hint && (
<p id={hintId} className="qq-hint">
{hint}
</p>
)}
</div>
<div
className="qq-list"
data-tiles={tiles ? "" : undefined}
data-shake={shake ? (shake % 2 ? "a" : "b") : undefined}
style={{ "--cols": Math.min(choices.length, 4) } as React.CSSProperties}
>
{choices.map((choice, i) => {
const checked = selected.includes(choice.value)
const letter = String.fromCharCode(65 + Math.min(i, 25))
const descId = !tiles && choice.description ? `${uid}-d${i}` : undefined
const classes = [
"qq-row",
tiles && "qq-tile",
state === "hover" && i === 0 && !checked && "is-hover",
]
.filter(Boolean)
.join(" ")
return (
<label
key={choice.value}
className={classes}
data-checked={checked ? "" : undefined}
data-disabled={isDisabled ? "" : undefined}
style={{ "--i": i } as React.CSSProperties}
>
<input
className="qq-input qq-sr"
type={multiple ? "checkbox" : "radio"}
name={name}
value={choice.value}
checked={checked}
onChange={() => choose(choice.value)}
disabled={isDisabled}
aria-describedby={descId}
/>
{tiles ? (
<>
<span className="qq-media">
{choice.image && (
<img src={choice.image} alt={choice.alt ?? ""} loading="lazy" decoding="async" />
)}
</span>
<span className="qq-tilebar">
<span className="qq-key" aria-hidden>
{letter}
</span>
<span className="qq-text">
<span className="qq-label">{choice.label}</span>
</span>
<Indicator multiple={multiple} />
</span>
</>
) : (
<>
<span className="qq-key" aria-hidden>
{letter}
</span>
<span className="qq-text">
<span className="qq-label">{choice.label}</span>
{choice.description && (
<span id={descId} className="qq-desc">
{choice.description}
</span>
)}
</span>
<Indicator multiple={multiple} />
</>
)}
</label>
)
})}
</div>
</fieldset>
<div className="qq-actions">
<button
type="submit"
className={[
"qq-btn",
state === "hover" && "is-hover",
state === "active" && "is-active",
]
.filter(Boolean)
.join(" ")}
data-state={status}
disabled={isDisabled}
aria-disabled={status === "loading" ? true : undefined}
>
{status === "loading" ? (
<span className="qq-btnrow">
<LoaderCircle className="qq-icon qq-spin" aria-hidden />
<span>{copy.saving}</span>
</span>
) : (
<span className="qq-btnlabel">{nextLabel}</span>
)}
</button>
<div className="qq-status">
{status === "error" ? (
<p id={errId} role="alert" className="qq-alert">
<CircleAlert aria-hidden />
{missingMessage ??
(multiple ? copy.missingMultiple : copy.missingSingle)}
</p>
) : status === "idle" && !isDisabled && showKeyboardTip ? (
<p className="qq-tip">
{copy.keyboardStart} <kbd>{copy.keyboardFirst}</kbd>{copy.keyboardRange}<kbd>{lastLetter}</kbd> {copy.keyboardAnswer} <kbd>{copy.keyboardEnter}</kbd> {copy.keyboardContinue}
</p>
) : null}
</div>
{onBack && (
<div className="qq-backwrap">
<button type="button" className="qq-back" onClick={onBack} disabled={isDisabled}>
{backLabel}
</button>
</div>
)}
</div>
<p className="qq-sr" aria-live="polite">
{live}
</p>
</form>
</div>
)
}
export type QuizChoice = {
/** The value reported to `onNext`. */
value: string
label: string
/** One short supporting line under the label (list layout only). */
description?: string
/** Image URL. When any choice has one, the choices render as image tiles. */
image?: string
/** Alt text for the image; omit when the label already says what it shows. */
alt?: string
}
/** "success" is accepted for older callers and renders as default. */
export type QuizQuestionState = "default" | "hover" | "active" | "disabled" | "error" | "success"
type Status = "idle" | "error" | "loading"
const toList = (v?: string | string[]) => (Array.isArray(v) ? v : v ? [v] : [])
function withMarker(question: React.ReactNode, highlight?: string) {
if (typeof question !== "string" || !highlight) return question
const at = question.indexOf(highlight)
if (at < 0) return question
return (
<>
{question.slice(0, at)}
<span className="qq-mark">{highlight}</span>
{question.slice(at + highlight.length)}
</>
)
}
function Indicator({ multiple }: { multiple: boolean }) {
return (
<span className="qq-ind" data-multi={multiple ? "" : undefined} aria-hidden>
{multiple ? <Check strokeWidth={3.25} /> : <i />}
</span>
)
}
// UI colours and shadows derive from the theme.
const CSS = `
.cf-quiz-question{--qq-accent:var(--accent,#0f5fc2);--qq-ink:var(--ink,#101828);--qq-muted:var(--muted,#4a5565);--qq-card:var(--card,#ffffff);--qq-r:var(--radius,14px);--qq-red:var(--cta,#d92d20);--qq-red2:var(--cta-2,#b42318);width:100%;max-width:46rem;margin-inline:auto;font-family:var(--font-body,Arial,sans-serif);color:var(--qq-ink);-webkit-font-smoothing:antialiased;--qq-line:var(--card-border,oklch(from var(--ink) l c h / 0.22));--qq-marker:var(--marker,color-mix(in oklch,var(--accent) 12%,var(--card)));}
.cf-quiz-question[data-tiles]{max-width:62rem}
.cf-quiz-question input{accent-color:var(--success,var(--field-focus))}
.cf-quiz-question *,.cf-quiz-question *::before,.cf-quiz-question *::after{box-sizing:border-box}
:where(.cf-quiz-question) p,:where(.cf-quiz-question) h2{margin:0}
:where(.cf-quiz-question) .qq-sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);border:0;white-space:normal;clip-path:inset(50%);}
:where(.cf-quiz-question) .qq-meta{display:flex;align-items:baseline;justify-content:space-between;gap:16px;margin-bottom:14px}
:where(.cf-quiz-question) .qq-count{font-family:var(--font-display,Arial,sans-serif);font-weight:800;font-size:clamp(1rem,2.4vw,1.1875rem);letter-spacing:-.01em;white-space:nowrap}
:where(.cf-quiz-question) .qq-count b{color:var(--qq-accent);font-weight:900}
:where(.cf-quiz-question) .qq-name{min-width:0;font-weight:700;font-size:clamp(.9375rem,2.2vw,1.0625rem);color:var(--qq-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
:where(.cf-quiz-question) .qq-track{display:flex;gap:6px;padding:4px;border-radius:999px;background:var(--qq-card);border:1px solid var(--card-border,oklch(from var(--ink) l c h / 0.22));box-shadow:inset 0 1px 2px oklch(from var(--card) calc(l - 0.12) c h / 0.35),0 1px 2px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21);border-color:var(--card-border,oklch(from var(--ink) l c h / 0.12));}
:where(.cf-quiz-question) .qq-seg{position:relative;flex:1 1 0;height:10px;border-radius:999px;overflow:hidden;box-shadow:inset 0 1px 2px oklch(from var(--card) calc(l - 0.12) c h / 0.35);background:color-mix(in oklch,var(--ink) 12%,var(--card));}
:where(.cf-quiz-question) .qq-seg>i{position:relative;display:block;height:100%;border-radius:inherit;box-shadow:inset 0 1px 0 oklch(from var(--card) calc(l + 0.04) c h / 0.6);transition:width .6s cubic-bezier(.2,.8,.2,1);overflow:hidden;background:var(--accent-fill,var(--accent));}
:where(.cf-quiz-question) .qq-seg[data-now]>i::after{content:"";position:absolute;inset:0;transform:translateX(-100%);animation:qq-sheen 2.4s ease-in-out 3;background:none;}
@keyframes qq-sheen{60%,100%{transform:translateX(100%)}}
:where(.cf-quiz-question) .qq-set{border:0;padding:0;margin:0;min-width:0}
:where(.cf-quiz-question) .qq-head{display:flex;flex-direction:column;align-items:center;text-align:center;margin:clamp(30px,5vw,48px) 0 clamp(26px,4vw,36px)}
:where(.cf-quiz-question) .qq-q{font-family:var(--font-display,Arial,sans-serif);font-size:clamp(2.125rem,6vw,3.75rem);line-height:1.05;width:100%;margin:0 auto;text-wrap:balance;color:var(--qq-ink);font-weight:var(--display-weight,900);letter-spacing:var(--display-tracking,-.032em);text-transform:var(--display-case,none);}
:where(.cf-quiz-question) .qq-mark{background:linear-gradient(180deg in oklch,transparent 30%,var(--qq-marker) 30%,var(--qq-marker) 93%,transparent 93%);padding:0 .16em;margin:0 -.08em;border-radius:.55em .2em .6em .25em / .35em .55em .25em .5em;-webkit-box-decoration-break:clone;box-decoration-break:clone}
.cf-quiz-question .qq-hint{margin:clamp(14px,2.6vw,20px) auto 0;max-width:36ch;font-size:clamp(1.0625rem,2.3vw,1.3125rem);font-weight:500;line-height:1.45;color:var(--qq-muted);text-align:center;text-wrap:pretty}
:where(.cf-quiz-question) .qq-list{display:grid;gap:12px}
:where(.cf-quiz-question) .qq-list[data-tiles]{grid-template-columns:repeat(2,minmax(0,1fr))}
@media (min-width:720px){:where(.cf-quiz-question) .qq-list[data-tiles]{grid-template-columns:repeat(var(--cols,4),minmax(0,1fr));gap:16px}}
:where(.cf-quiz-question) .qq-list[data-shake=a]{animation:qq-shake-a .42s ease}
:where(.cf-quiz-question) .qq-list[data-shake=b]{animation:qq-shake-b .42s ease}
@keyframes qq-shake-a{20%{transform:translateX(-6px)}40%{transform:translateX(5px)}60%{transform:translateX(-3px)}80%{transform:translateX(2px)}}
@keyframes qq-shake-b{20%{transform:translateX(-6px)}40%{transform:translateX(5px)}60%{transform:translateX(-3px)}80%{transform:translateX(2px)}}
:where(.cf-quiz-question) .qq-row{position:relative;display:flex;align-items:center;gap:16px;min-height:76px;padding:15px 20px 15px 15px;border:1.5px solid var(--qq-line);cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent;transition:border-color .18s ease,box-shadow .18s ease,transform .18s ease,background-color .18s ease;animation:qq-in .45s cubic-bezier(.2,.8,.2,1) backwards;animation-delay:min(calc(var(--i,0) * 60ms),280ms);background:var(--card);border-color:var(--card-border,oklch(from var(--ink) l c h / 0.12));border-radius:var(--card-radius,var(--radius));box-shadow:var(--card-shadow,0 2px 4px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));color:var(--label-ink,var(--ink));}
@keyframes qq-in{from{opacity:.82;transform:translateY(8px)}}
.cf-quiz-question[data-status=error] .qq-row:not([data-checked]){border-color:var(--danger);box-shadow:var(--card-shadow,0 2px 4px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));}
:where(.cf-quiz-question) .qq-row:hover:not([data-disabled]):not([data-checked]),:where(.cf-quiz-question) .qq-row.is-hover{transform:translateY(-2px);border-color:var(--field-focus,var(--qq-accent));box-shadow:var(--card-shadow,0 2px 4px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));}
:where(.cf-quiz-question) .qq-row:hover:not([data-disabled]):not([data-checked]) .qq-key,:where(.cf-quiz-question) .qq-row.is-hover .qq-key{color:var(--ink);background:var(--card);border-color:var(--card-border,oklch(from var(--ink) l c h / 0.22));box-shadow:var(--card-shadow,inset 0 -2px 0 oklch(from var(--card) calc(l - 0.12) c h / 0.35),0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));}
:where(.cf-quiz-question) .qq-row:hover:not([data-disabled]):not([data-checked]) .qq-ind,:where(.cf-quiz-question) .qq-row.is-hover .qq-ind{box-shadow:0 0 0 4px oklch(from var(--qq-accent) l c h / 0.1);background:var(--field);color:var(--field-ink);border-color:var(--field-border,oklch(from var(--ink) l c h / 0.22));}
:where(.cf-quiz-question) .qq-row:active:not([data-disabled]){transform:translateY(1px)}
:where(.cf-quiz-question) .qq-row[data-checked]{background:var(--card);border-color:var(--success);box-shadow:var(--card-shadow,inset 0 0 0 1px var(--success));}
:where(.cf-quiz-question) .qq-row:has(.qq-input:focus-visible){outline:3px solid oklch(from var(--qq-accent) l c h / 0.45);outline-offset:3px}
:where(.cf-quiz-question) .qq-row[data-disabled]{cursor:not-allowed;box-shadow:none;background:var(--card);color:var(--ink);}
:where(.cf-quiz-question) .qq-row[data-disabled] .qq-desc{;color:var(--muted);}
:where(.cf-quiz-question) .qq-row[data-disabled][data-checked]{;background:var(--card);color:var(--ink);}
:where(.cf-quiz-question) .qq-key{display:grid;place-items:center;flex:none;width:42px;height:42px;border-radius:11px;font-family:var(--font-display,Arial,sans-serif);font-weight:800;font-size:18px;line-height:1;color:var(--qq-ink);border:1px solid var(--card-border,oklch(from var(--ink) l c h / 0.22));transform:translateY(-1px);transition:all .18s ease;background:var(--card);box-shadow:var(--card-shadow,inset 0 -2px 0 oklch(from var(--card) calc(l - 0.12) c h / 0.35),0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));}
:where(.cf-quiz-question) .qq-row[data-checked] .qq-key{transform:translateY(1px);background:var(--success-soft);color:var(--success);border-color:var(--success);box-shadow:var(--card-shadow,inset 0 -2px 0 oklch(from var(--card) calc(l - 0.12) c h / 0.35));}
:where(.cf-quiz-question) .qq-text{display:grid;gap:4px;flex:1 1 auto;min-width:0}
:where(.cf-quiz-question) .qq-label{font-family:var(--font-display,Arial,sans-serif);font-weight:800;font-size:clamp(1.125rem,2.6vw,1.375rem);line-height:1.22;letter-spacing:-.012em;text-wrap:pretty}
:where(.cf-quiz-question) .qq-desc{font-size:15px;font-weight:500;line-height:1.4;color:var(--qq-muted);text-wrap:pretty}
:where(.cf-quiz-question) .qq-ind{display:grid;place-items:center;flex:none;width:28px;height:28px;border-radius:999px;border:2px solid var(--field-border,oklch(from var(--ink) l c h / 0.22));transition:all .18s ease;background:var(--field);color:var(--field-ink);}
:where(.cf-quiz-question) .qq-ind[data-multi]{border-radius:8px}
:where(.cf-quiz-question) .qq-ind>i{width:12px;height:12px;border-radius:999px;background:var(--success);transform:scale(0);transition:transform .22s cubic-bezier(.3,1.6,.5,1)}
:where(.cf-quiz-question) .qq-ind>svg{width:16px;height:16px;opacity:0;transition:opacity .15s ease}
:where(.cf-quiz-question) .qq-row[data-checked] .qq-ind{background:var(--success-soft);border-color:var(--success);box-shadow:0 0 0 4px var(--success-soft)}
:where(.cf-quiz-question) .qq-row[data-checked] .qq-ind>i{transform:scale(1)}
:where(.cf-quiz-question) .qq-row[data-checked] .qq-ind[data-multi]{;background:var(--success-soft);color:var(--success);}
:where(.cf-quiz-question) .qq-row[data-checked] .qq-ind>svg{opacity:1}
@media (max-width:480px){:where(.cf-quiz-question) .qq-row{gap:12px;padding:13px 14px 13px 12px;min-height:70px}:where(.cf-quiz-question) .qq-key{width:36px;height:36px;font-size:16px;border-radius:9px}:where(.cf-quiz-question) .qq-ind{width:26px;height:26px}}
:where(.cf-quiz-question) .qq-tile{flex-direction:column;align-items:stretch;gap:10px;padding:10px;min-height:0}
:where(.cf-quiz-question) .qq-media{display:block;aspect-ratio:4/3;border-radius:calc(var(--qq-r) - 6px);overflow:hidden;background:transparent;}
:where(.cf-quiz-question) .qq-media img{display:block;width:100%;height:100%;object-fit:cover}
:where(.cf-quiz-question) .qq-tilebar{display:flex;align-items:center;gap:10px;padding:2px 4px 4px}
:where(.cf-quiz-question) .qq-tile .qq-key{width:32px;height:32px;font-size:15px;border-radius:8px}
:where(.cf-quiz-question) .qq-tile .qq-label{font-size:clamp(1rem,2vw,1.125rem)}
:where(.cf-quiz-question) .qq-tile .qq-ind{width:24px;height:24px}
:where(.cf-quiz-question) .qq-actions{margin-top:clamp(24px,3.5vw,32px)}
:where(.cf-quiz-question) .qq-btn{position:relative;display:flex;align-items:center;justify-content:center;width:100%;min-height:74px;margin:0;padding:12px 72px;border:1px solid var(--qq-red2);letter-spacing:-.01em;text-align:center;text-wrap:balance;cursor:pointer;transition:transform .14s ease,box-shadow .14s ease,filter .14s ease;background:linear-gradient(180deg in oklch,var(--button-bg,var(--cta)),var(--button-bg-2,oklch(from var(--button-bg,var(--cta)) calc(l - 0.05) c h)));color:var(--button-ink,var(--cta-ink));border-color:var(--button-bg-2,oklch(from var(--button-bg,var(--cta)) calc(l - 0.05) c h));border-radius:var(--button-radius,var(--radius));font:var(--button-weight,800) clamp(1.3125rem,3.4vw,1.625rem)/1.15 var(--button-font,var(--font-display));text-transform:var(--button-case,none);box-shadow:var(--button-shadow,inset 0 -2px 0 oklch(from var(--card) calc(l - 0.12) c h / 0.35),0 3px 4px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));}
:where(.cf-quiz-question) .qq-btnlabel{display:block;text-shadow:var(--button-text-shadow, 0 1px 0 oklch(from var(--button-bg, var(--cta)) calc(l - 0.2) c h / 0.75))}
:where(.cf-quiz-question) .qq-btnrow{display:inline-flex;align-items:center;justify-content:center;gap:10px}
:where(.cf-quiz-question) .qq-btn:hover:not(:disabled),:where(.cf-quiz-question) .qq-btn.is-hover{transform:translateY(-1px);filter:none;background:linear-gradient(180deg in oklch,var(--button-bg,var(--cta)),var(--button-bg-2,oklch(from var(--button-bg,var(--cta)) calc(l - 0.05) c h)));border-color:var(--button-bg-2,oklch(from var(--button-bg,var(--cta)) calc(l - 0.05) c h));box-shadow:var(--button-shadow,inset 0 -2px 0 oklch(from var(--card) calc(l - 0.12) c h / 0.35),0 3px 4px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));}
:where(.cf-quiz-question) .qq-btn:active:not(:disabled),:where(.cf-quiz-question) .qq-btn.is-active{transform:translateY(3px);filter:none;background:linear-gradient(180deg in oklch,var(--button-bg,var(--cta)),var(--button-bg-2,oklch(from var(--button-bg,var(--cta)) calc(l - 0.05) c h)));border-color:var(--button-bg-2,oklch(from var(--button-bg,var(--cta)) calc(l - 0.05) c h));box-shadow:var(--button-shadow,inset 0 -2px 0 oklch(from var(--card) calc(l - 0.12) c h / 0.35),0 3px 4px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));}
:where(.cf-quiz-question) .qq-btn:focus-visible{outline:3px solid var(--qq-accent);outline-offset:4px}
:where(.cf-quiz-question) .qq-btn[data-state=loading]{cursor:progress;filter:none}
:where(.cf-quiz-question) .qq-btn[data-state=loading]{padding-inline:20px}
:where(.cf-quiz-question) .qq-btn:disabled{cursor:not-allowed;filter:none;transform:none;background:var(--button-2-bg,var(--card));color:var(--button-2-ink,var(--ink));border-color:var(--button-2-border,oklch(from var(--ink) l c h / 0.22));border-radius:var(--button-radius,var(--radius));box-shadow:var(--button-shadow,none);}
:where(.cf-quiz-question) .qq-btn:disabled .qq-btnlabel{text-shadow:none}
:where(.cf-quiz-question) .qq-icon{width:24px;height:24px;flex:none}
:where(.cf-quiz-question) .qq-spin{animation:qq-spin .8s linear infinite}
@keyframes qq-spin{to{transform:rotate(360deg)}}
@media (max-width:480px){:where(.cf-quiz-question) .qq-btn{min-height:68px;padding-inline:62px}}
:where(.cf-quiz-question) .qq-status{display:flex;align-items:center;justify-content:center;min-height:52px;padding-top:14px;text-align:center}
:where(.cf-quiz-question) .qq-alert{display:inline-flex;align-items:center;gap:8px;padding:9px 16px;font-weight:700;font-size:15px;line-height:1.3;text-wrap:pretty;background:var(--danger-soft);border-color:var(--danger);border-radius:var(--card-radius,var(--radius));box-shadow:var(--card-shadow,0 2px 4px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21));color:var(--danger);border:1px solid var(--danger);}
:where(.cf-quiz-question) .qq-alert svg{width:18px;height:18px;flex:none}
:where(.cf-quiz-question) .qq-tip{display:none;align-items:center;justify-content:center;flex-wrap:wrap;gap:6px;font-size:14px;font-weight:500;color:var(--qq-muted)}
@media (min-width:640px){:where(.cf-quiz-question) .qq-tip{display:inline-flex}}
:where(.cf-quiz-question) .qq-tip kbd{display:inline-grid;place-items:center;min-width:26px;height:24px;padding:0 6px;border-radius:6px;border:1px solid var(--card-border,oklch(from var(--ink) l c h / 0.22));font-family:inherit;font-size:13px;font-weight:700;color:var(--qq-ink);background:var(--card);border-color:var(--card-border,oklch(from var(--ink) l c h / 0.22));box-shadow:0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.21);}
:where(.cf-quiz-question) .qq-backwrap{display:flex;justify-content:center;margin-top:2px}
:where(.cf-quiz-question) .qq-back{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:0 18px;border:1px solid var(--button-2-border, transparent);cursor:pointer;transition:border-color .15s ease,background-color .15s ease,transform .15s ease;background:var(--button-2-bg, var(--secondary, oklch(0.93 0.01 260)));color:var(--button-2-ink, var(--secondary-ink, var(--ink)));border-color:var(--button-2-border, transparent);border-radius:var(--button-radius,var(--radius));box-shadow:var(--button-2-shadow, var(--shadow-sm));font:var(--button-weight,700) 15px/normal var(--button-font,var(--font-body));text-transform:var(--button-case,none);}
:where(.cf-quiz-question) .qq-back:hover:not(:disabled){background:oklch(from var(--button-2-bg, var(--secondary, oklch(0.93 0.01 260))) calc(l - 0.03) c h);color:var(--button-2-ink, var(--secondary-ink, var(--ink)));border-color:var(--button-2-border, transparent);border-radius:var(--button-radius,var(--radius));box-shadow:var(--button-2-shadow, var(--shadow-sm));}
:where(.cf-quiz-question) .qq-back:active:not(:disabled){transform:translateY(1px)}
:where(.cf-quiz-question) .qq-back:focus-visible{outline:3px solid oklch(from var(--qq-accent) l c h / 0.45);outline-offset:3px}
:where(.cf-quiz-question) .qq-back:disabled{cursor:not-allowed;background:var(--button-2-bg, var(--secondary, oklch(0.93 0.01 260)));color:var(--button-2-ink, var(--secondary-ink, var(--ink)));border-color:var(--button-2-border, transparent);border-radius:var(--button-radius,var(--radius));box-shadow:none;}
@media (prefers-reduced-motion:reduce){.cf-quiz-question *,.cf-quiz-question *::before,.cf-quiz-question *::after{animation:none!important;transition-duration:.01ms!important}:where(.cf-quiz-question) .qq-row:hover,:where(.cf-quiz-question) .qq-row.is-hover,:where(.cf-quiz-question) .qq-btn:hover,:where(.cf-quiz-question) .qq-btn.is-hover{transform:none!important}:where(.cf-quiz-question) .qq-btn:hover .qq-arrow,:where(.cf-quiz-question) .qq-btn.is-hover .qq-arrow{transform:translateY(-50%)!important}}
`
export default QuizQuestion
const defaultCopy = {
"savedNext": "Saved, on to question {next}",
"savedResults": "Saved, see your results",
"savingAnnouncement": "Saving your answer.",
"savedAnnouncement": "{saved}.",
"questionLabel": "Question",
"ofLabel": "of",
"progress": "Quiz progress",
"progressValue": "Question {current} of {total}",
"saving": "Saving your answer…",
"missingMultiple": "Pick at least one answer to continue.",
"missingSingle": "Pick one answer to continue.",
"changeAnswer": "Changed your mind? Pick another answer.",
"keyboardStart": "Press",
"keyboardFirst": "A",
"keyboardRange": "–",
"keyboardAnswer": "to answer,",
"keyboardEnter": "Enter",
"keyboardContinue": "to continue"
}
function text(template: string, values: Record<string, string | number>) {
return template.replace(/\{(\w+)\}/g, (match, key: string) => String(values[key] ?? match))
}
pieces/forms/quiz-question/specimen.tsx 41 lines
import * as React from "react"
import { QuizQuestion, type QuizQuestionState } from "../quiz-question"
import defaults from "../../studio-defaults.json"
export const states = ["default", "hover", "active", "disabled", "error"]
export default function QuizQuestionSpecimen({ state = "default" }: { state?: string }) {
const items = defaults.sample.items
const choices = [
{ value: "plan", label: "Planning my funnel", description: items[0]?.detail },
{ value: "copy", label: "Writing my page copy", description: items[1]?.detail },
{ value: "check", label: "Checking every step", description: items[2]?.detail },
{
value: "all",
label: "All of the above",
description: "Plan, write, and check your funnel, start to finish.",
},
]
return (
<div>
<QuizQuestion
state={state as QuizQuestionState}
quizName="Your funnel plan"
current={2}
total={7}
question="What do you need help with before you launch?"
highlight="before you launch?"
hint="Choose the step you want to focus on."
name="focus"
choices={choices}
defaultValue="copy"
nextLabel="Continue"
backLabel="Back to question 1"
onBack={() => {}}
/>
</div>
)
}
| Name | Type | Details |
|---|---|---|
copy OptionalQuizQuestion |
Partial<typeof defaultCopy> |
|
onSubmit OptionalQuizQuestion |
(values: string[]) => void | Promise<void> |
|
quizName OptionalQuizQuestion |
string |
|
current RequiredQuizQuestion |
number |
|
total RequiredQuizQuestion |
number |
|
question RequiredQuizQuestion |
React.ReactNode |
|
highlight OptionalQuizQuestion |
string |
|
hint OptionalQuizQuestion |
React.ReactNode |
|
name OptionalQuizQuestion |
string |
Default "answer"
|
choices RequiredQuizQuestion |
QuizChoice[] |
|
multiple OptionalQuizQuestion |
boolean |
Default false
|
defaultValue OptionalQuizQuestion |
string | string[] |
|
nextLabel OptionalQuizQuestion |
string |
Default "Continue"
|
backLabel OptionalQuizQuestion |
string |
Default "Back"
|
onBack OptionalQuizQuestion |
() => void |
|
onNext OptionalQuizQuestion |
(values: string[]) => void | Promise<void> |
|
missingMessage OptionalQuizQuestion |
string |
|
savedLabel OptionalQuizQuestion |
string |
|
disabled OptionalQuizQuestion |
boolean |
Default false
|
showKeyboardTip OptionalQuizQuestion |
boolean |
Default true
|
state OptionalQuizQuestion |
QuizQuestionState |
Default "default"
|
className OptionalQuizQuestion |
string |
Theme roles it reads
Set by the theme bar, a preset or your brand. Colours come from the base tokens (--surface, --ink, --cta…) every piece uses.
--button-bg--button-bg-2--button-case--button-font--button-ink--button-radius--button-shadow--button-text-shadow--button-weight- Main CTA button: background, ink, font, weight, case, radius and shadow.
--button-2-bg--button-2-border--button-2-ink--button-2-shadow- Secondary button.
--card-border--card-radius--card-shadow- Cards and panels: radius, border and shadow.
--display-case--display-tracking--display-weight- Headlines: weight, letter case and tracking.
--field--field-border--field-focus--field-ink- Form inputs: background, ink, border, radius and focus colour.
--marker- The highlighter colour behind key phrases.
Image slots
Filled from the brand’s images; the specimen ships its own defaults.
This piece reads no image slots.
-
b77916eca54aa689.webp
image/webp · 8.32 KB
-
d435db6662febfcf.webp
image/webp · 10 KB
-
f0a5d3e1e61804ba.webp
image/webp · 11.6 KB