{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "form-survey",
  "type": "registry:component",
  "title": "Survey Form",
  "description": "One question at a time with an NPS scale, lettered choices and keyboard shortcuts. Picks confirm with a quick blink and advance on their own, ending on a summary with the score group.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "forms",
    "form",
    "survey",
    "nps",
    "keyboard",
    "questionnaire",
    "feedback"
  ],
  "docs": "https://hyperblur.dev/effects/form-survey",
  "files": [
    {
      "path": "registry/hyperblur/form-survey.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/form-survey.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface FormSurveyQuestion {\n  id: string;\n  type: \"nps\" | \"choice\" | \"multi\" | \"text\";\n  title: string;\n  options?: string[];\n  required?: boolean;\n  placeholder?: string;\n}\n\nexport type FormSurveyAnswers = Record<string, number | string | string[]>;\n\nexport interface FormSurveyProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSubmit\" | \"title\"> {\n  questions?: FormSurveyQuestion[];\n  title?: string;\n  accent?: string;\n  autoAdvance?: boolean;\n  onAnswer?: (id: string, value: number | string | string[]) => void;\n  onSubmit?: (answers: FormSurveyAnswers) => void | Promise<void>;\n}\n\nconst defaultQuestions: FormSurveyQuestion[] = [\n  { id: \"nps\", type: \"nps\", title: \"How likely are you to recommend Fieldnote to a colleague?\", required: true },\n  { id: \"use\", type: \"choice\", title: \"What do you use Fieldnote for most?\", options: [\"Meeting notes\", \"Research interviews\", \"Project docs\", \"Personal journal\"], required: true },\n  { id: \"pay\", type: \"multi\", title: \"Which of these would you pay extra for?\", options: [\"Offline mode\", \"Team spaces\", \"Audio transcripts\", \"Custom domains\"] },\n  { id: \"fix\", type: \"text\", title: \"What is the one thing we should fix first?\", placeholder: \"Search is slow when a notebook has more than 500 pages...\" },\n];\n\nconst css = `\n.hb-xh4 {\n  --hb-xh4-a: #ff6b4a;\n  box-sizing: border-box;\n  width: 100%;\n  max-width: 460px;\n  margin: 0 auto;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xh4 *, .hb-xh4 *::before, .hb-xh4 *::after { box-sizing: border-box; }\n.hb-xh4-card {\n  position: relative;\n  overflow: hidden;\n  border: 1px solid #262626;\n  border-radius: 20px;\n  background: radial-gradient(120% 80% at 100% 0%, color-mix(in srgb, var(--hb-xh4-a) 10%, transparent), transparent 60%), #0e0e0e;\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 30px 60px -30px rgba(0,0,0,0.9);\n}\n.hb-xh4-card:focus { outline: none; }\n.hb-xh4-bar { height: 3px; background: #1d1d1d; }\n.hb-xh4-bar i { display: block; height: 100%; background: var(--hb-xh4-a); transform-origin: left; transform: scaleX(var(--hb-xh4-p)); transition: transform 0.6s cubic-bezier(0.65, 0, 0.35, 1); }\n.hb-xh4-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px 0; font-size: 12px; color: #7a7a7a; }\n.hb-xh4-head b { color: #d4d4d4; font-weight: 500; }\n.hb-xh4-nav { display: flex; gap: 4px; }\n.hb-xh4-arrow { display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid #262626; border-radius: 8px; background: #141414; color: #a1a1a1; cursor: pointer; transition: background 0.2s ease, color 0.2s ease; }\n.hb-xh4-arrow:hover:not(:disabled) { background: #1c1c1c; color: #fff; }\n.hb-xh4-arrow:disabled { opacity: 0.35; cursor: default; }\n.hb-xh4-arrow:focus-visible { outline: 2px solid var(--hb-xh4-a); outline-offset: 1px; }\n.hb-xh4-arrow svg { width: 13px; height: 13px; }\n.hb-xh4-q { padding: 18px 20px 20px; min-height: 230px; animation: hb-xh4-up 0.5s cubic-bezier(0.22, 1, 0.36, 1); }\n.hb-xh4-q[data-dir=\"back\"] { animation-name: hb-xh4-down; }\n.hb-xh4-num { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; color: var(--hb-xh4-a); }\n.hb-xh4-num svg { width: 12px; height: 12px; }\n.hb-xh4-title { margin: 8px 0 18px; font-family: var(--font-grotesk, inherit); font-size: 20px; font-weight: 500; line-height: 1.25; letter-spacing: -0.02em; color: #f5f5f5; }\n.hb-xh4-title span { color: #6b6b6b; font-size: 13px; font-weight: 400; letter-spacing: 0; }\n.hb-xh4-nps { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }\n.hb-xh4-score { height: 38px; padding: 0; border: 1px solid #272727; border-radius: 9px; background: #141414; color: #cfcfcf; font: inherit; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; cursor: pointer; transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, border-color 0.2s ease, color 0.2s ease; }\n.hb-xh4-score:hover { border-color: var(--hb-xh4-s); color: #fff; transform: translateY(-2px); }\n.hb-xh4-score[aria-checked=\"true\"] { background: var(--hb-xh4-s); border-color: var(--hb-xh4-s); color: #0b0b0b; transform: translateY(-3px); box-shadow: 0 8px 16px -8px var(--hb-xh4-s); }\n.hb-xh4-score:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n.hb-xh4-ends { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11.5px; color: #6f6f6f; }\n.hb-xh4-opts { display: grid; gap: 7px; }\n.hb-xh4-opt { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px 0 8px; border: 1px solid #262626; border-radius: 11px; background: #131313; color: #dedede; font: inherit; font-size: 14px; text-align: left; cursor: pointer; transition: border-color 0.2s ease, background 0.2s ease; }\n.hb-xh4-opt:hover { border-color: #383838; background: #171717; }\n.hb-xh4-opt[aria-checked=\"true\"], .hb-xh4-opt[aria-pressed=\"true\"] { border-color: var(--hb-xh4-a); background: color-mix(in srgb, var(--hb-xh4-a) 10%, #131313); color: #fff; }\n.hb-xh4-opt[data-blink=\"true\"] { animation: hb-xh4-blink 0.36s steps(2, jump-none) 2; }\n.hb-xh4-opt:focus-visible { outline: 2px solid var(--hb-xh4-a); outline-offset: 2px; }\n.hb-xh4-key { display: grid; place-items: center; width: 24px; height: 24px; flex: none; border: 1px solid #333; border-radius: 6px; background: #0c0c0c; font-family: var(--font-mono, ui-monospace, monospace); font-size: 11px; color: #9a9a9a; transition: all 0.2s ease; }\n.hb-xh4-opt[aria-checked=\"true\"] .hb-xh4-key, .hb-xh4-opt[aria-pressed=\"true\"] .hb-xh4-key { background: var(--hb-xh4-a); border-color: var(--hb-xh4-a); color: #160805; }\n.hb-xh4-opt-label { flex: 1; min-width: 0; }\n.hb-xh4-opt svg { width: 15px; height: 15px; color: var(--hb-xh4-a); }\n.hb-xh4-area { width: 100%; min-height: 96px; padding: 12px 14px; border: 0; border-bottom: 2px solid #2b2b2b; border-radius: 0; background: transparent; color: #f2f2f2; font: inherit; font-family: var(--font-grotesk, inherit); font-size: 17px; line-height: 1.45; resize: none; outline: none; transition: border-color 0.25s ease; }\n.hb-xh4-area::placeholder { color: #4d4d4d; }\n.hb-xh4-area:focus { border-bottom-color: var(--hb-xh4-a); }\n.hb-xh4-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; }\n.hb-xh4-hint { font-size: 12px; color: #6b6b6b; }\n.hb-xh4-hint kbd { display: inline-block; padding: 1px 5px; margin: 0 2px; border: 1px solid #333; border-bottom-width: 2px; border-radius: 5px; font-family: var(--font-mono, ui-monospace, monospace); font-size: 10.5px; color: #a1a1a1; }\n.hb-xh4-ok { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--hb-xh4-a); color: #170805; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 8px 20px -10px var(--hb-xh4-a); transition: transform 0.15s cubic-bezier(0.3, 0.7, 0.4, 1), filter 0.2s ease; }\n.hb-xh4-ok:hover { filter: brightness(1.07); }\n.hb-xh4-ok:active { transform: scale(0.97); }\n.hb-xh4-ok:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n.hb-xh4-ok svg { width: 14px; height: 14px; }\n.hb-xh4-err { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; background: rgba(240,82,96,0.1); color: #ff9aa3; font-size: 12px; animation: hb-xh4-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }\n.hb-xh4-done { display: grid; gap: 14px; padding: 26px 22px 24px; min-height: 260px; align-content: center; animation: hb-xh4-up 0.6s cubic-bezier(0.22, 1, 0.36, 1); }\n.hb-xh4-badge { display: inline-flex; align-items: center; gap: 10px; justify-self: start; padding: 6px 12px 6px 6px; border-radius: 999px; background: #161616; border: 1px solid #262626; font-size: 12.5px; color: #cfcfcf; }\n.hb-xh4-badge b { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--hb-xh4-s); color: #0b0b0b; font-size: 13px; font-variant-numeric: tabular-nums; }\n.hb-xh4-done h3 { margin: 0; font-family: var(--font-grotesk, inherit); font-size: 24px; font-weight: 500; letter-spacing: -0.03em; line-height: 1.15; }\n.hb-xh4-done p { margin: 0; font-size: 13.5px; color: #8f8f8f; line-height: 1.5; }\n.hb-xh4-sum { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }\n.hb-xh4-sum li { display: flex; gap: 10px; font-size: 12.5px; color: #a1a1a1; }\n.hb-xh4-sum li span:first-child { flex: none; font-family: var(--font-mono, ui-monospace, monospace); color: var(--hb-xh4-a); }\n.hb-xh4-sum li span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #d9d9d9; }\n@keyframes hb-xh4-up { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }\n@keyframes hb-xh4-down { from { opacity: 0; transform: translateY(-24px); } to { opacity: 1; transform: none; } }\n@keyframes hb-xh4-blink { 0% { opacity: 1; } 100% { opacity: 0.45; } }\n@keyframes hb-xh4-shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xh4 *, .hb-xh4 *::before, .hb-xh4 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nconst letters = \"ABCDEFGHIJ\";\n\nfunction npsColor(n: number) {\n  if (n <= 6) return [\"#f0525f\", \"#f05a5a\", \"#f26455\", \"#f36f50\", \"#f47b4b\", \"#f58846\", \"#f59541\"][n];\n  if (n <= 8) return n === 7 ? \"#f5b83d\" : \"#e8c93a\";\n  return n === 9 ? \"#7ed957\" : \"#3ddc84\";\n}\n\nfunction npsGroup(n: number) {\n  return n >= 9 ? \"Promoter\" : n >= 7 ? \"Passive\" : \"Detractor\";\n}\n\nexport function FormSurvey({\n  questions = defaultQuestions,\n  title = \"Quick survey\",\n  accent = \"#ff6b4a\",\n  autoAdvance = true,\n  onAnswer,\n  onSubmit,\n  className,\n  style,\n  ...rest\n}: FormSurveyProps) {\n  const [index, setIndex] = React.useState(0);\n  const [dir, setDir] = React.useState<\"next\" | \"back\">(\"next\");\n  const [answers, setAnswers] = React.useState<FormSurveyAnswers>({});\n  const [error, setError] = React.useState(0);\n  const [blink, setBlink] = React.useState(\"\");\n  const [done, setDone] = React.useState(false);\n  const timer = React.useRef<number | undefined>(undefined);\n  const card = React.useRef<HTMLDivElement>(null);\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  const q = questions[index];\n  const total = questions.length;\n  const answered = (qq: FormSurveyQuestion) => {\n    const a = answers[qq.id];\n    if (a === undefined) return false;\n    if (Array.isArray(a)) return a.length > 0;\n    if (typeof a === \"string\") return a.trim().length > 0;\n    return true;\n  };\n\n  const finish = async () => {\n    setDone(true);\n    await Promise.resolve(onSubmit?.(answers));\n  };\n\n  const move = (to: number) => {\n    window.clearTimeout(timer.current);\n    setBlink(\"\");\n    setError(0);\n    setDir(to > index ? \"next\" : \"back\");\n    setIndex(to);\n    window.requestAnimationFrame(() => card.current?.focus({ preventScroll: true }));\n  };\n\n  const advance = () => {\n    if (q.required && !answered(q)) {\n      setError((e) => e + 1);\n      return;\n    }\n    if (index === total - 1) finish();\n    else move(index + 1);\n  };\n\n  const answer = (value: number | string | string[], auto: boolean) => {\n    const nextAnswers = { ...answers, [q.id]: value };\n    setAnswers(nextAnswers);\n    setError(0);\n    onAnswer?.(q.id, value);\n    if (auto && autoAdvance) {\n      setBlink(String(value));\n      window.clearTimeout(timer.current);\n      timer.current = window.setTimeout(() => {\n        setBlink(\"\");\n        if (index === total - 1) {\n          setDone(true);\n          Promise.resolve(onSubmit?.(nextAnswers)).catch(() => undefined);\n        } else {\n          setDir(\"next\");\n          setIndex(index + 1);\n        }\n      }, 760);\n    }\n  };\n\n  const onKey = (e: React.KeyboardEvent) => {\n    if (done || (e.target as HTMLElement).tagName === \"TEXTAREA\") return;\n    if (e.metaKey || e.ctrlKey || e.altKey) return;\n    if (q.type === \"nps\" && /^\\d$/.test(e.key)) {\n      e.preventDefault();\n      answer(Number(e.key), true);\n      return;\n    }\n    if ((q.type === \"choice\" || q.type === \"multi\") && q.options) {\n      const i = letters.indexOf(e.key.toUpperCase());\n      if (i >= 0 && i < q.options.length) {\n        e.preventDefault();\n        const o = q.options[i];\n        if (q.type === \"choice\") answer(o, true);\n        else {\n          const cur = (answers[q.id] as string[] | undefined) ?? [];\n          answer(cur.includes(o) ? cur.filter((x) => x !== o) : [...cur, o], false);\n        }\n        return;\n      }\n    }\n    if (e.key === \"Enter\" && (e.target as HTMLElement).tagName !== \"BUTTON\") {\n      e.preventDefault();\n      advance();\n    }\n  };\n\n  const score = typeof answers.nps === \"number\" ? answers.nps : undefined;\n  const arrow = (d: string) => (\n    <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d={d} /></svg>\n  );\n\n  return (\n    <div className={[\"hb-xh4\", className].filter(Boolean).join(\" \")} style={{ ...style, \"--hb-xh4-a\": accent, \"--hb-xh4-p\": done ? 1 : index / total } as React.CSSProperties} {...rest}>\n      <style href=\"hb-form-survey\" precedence=\"default\">{css}</style>\n      <div ref={card} className=\"hb-xh4-card\" tabIndex={-1} onKeyDown={onKey} role=\"group\" aria-label={title}>\n        <div className=\"hb-xh4-bar\" aria-hidden=\"true\"><i /></div>\n        {done ? (\n          <div className=\"hb-xh4-done\" role=\"status\" style={{ \"--hb-xh4-s\": npsColor(score ?? 10) } as React.CSSProperties}>\n            {score !== undefined ? (\n              <span className=\"hb-xh4-badge\"><b>{score}</b>{npsGroup(score)}</span>\n            ) : null}\n            <h3>Thanks, that really helps.</h3>\n            <p>Your answers go straight to the product team. We read every one.</p>\n            <ul className=\"hb-xh4-sum\">\n              {questions.filter((x) => x.type !== \"nps\" && answered(x)).map((x, i) => {\n                const a = answers[x.id];\n                return (\n                  <li key={x.id}>\n                    <span>{String(i + 2).padStart(2, \"0\")}</span>\n                    <span>{Array.isArray(a) ? a.join(\", \") : String(a)}</span>\n                  </li>\n                );\n              })}\n            </ul>\n          </div>\n        ) : (\n          <>\n            <div className=\"hb-xh4-head\">\n              <span><b>{title}</b> · {index + 1} of {total}</span>\n              <div className=\"hb-xh4-nav\">\n                <button type=\"button\" className=\"hb-xh4-arrow\" aria-label=\"Previous question\" disabled={index === 0} onClick={() => move(index - 1)}>{arrow(\"M3 9l4-4 4 4\")}</button>\n                <button type=\"button\" className=\"hb-xh4-arrow\" aria-label=\"Next question\" disabled={index === total - 1 || (q.required && !answered(q))} onClick={() => move(index + 1)}>{arrow(\"M3 5l4 4 4-4\")}</button>\n              </div>\n            </div>\n            <div className=\"hb-xh4-q\" key={q.id} data-dir={dir}>\n              <span className=\"hb-xh4-num\">\n                {index + 1}\n                {arrow(\"M2 7h9M8 4l3 3-3 3\")}\n              </span>\n              <h3 className=\"hb-xh4-title\" id={`hb-xh4-t-${q.id}`}>\n                {q.title} {q.required ? null : <span>Optional</span>}\n              </h3>\n              {q.type === \"nps\" ? (\n                <>\n                  <div className=\"hb-xh4-nps\" role=\"radiogroup\" aria-labelledby={`hb-xh4-t-${q.id}`}>\n                    {Array.from({ length: 11 }, (_, n) => (\n                      <button\n                        key={n}\n                        type=\"button\"\n                        role=\"radio\"\n                        aria-checked={answers[q.id] === n}\n                        className=\"hb-xh4-score\"\n                        style={{ \"--hb-xh4-s\": npsColor(n) } as React.CSSProperties}\n                        onClick={() => answer(n, true)}\n                      >\n                        {n}\n                      </button>\n                    ))}\n                  </div>\n                  <div className=\"hb-xh4-ends\"><span>Not likely</span><span>Extremely likely</span></div>\n                </>\n              ) : null}\n              {(q.type === \"choice\" || q.type === \"multi\") && q.options ? (\n                <div className=\"hb-xh4-opts\" role={q.type === \"choice\" ? \"radiogroup\" : \"group\"} aria-labelledby={`hb-xh4-t-${q.id}`}>\n                  {q.options.map((o, i) => {\n                    const cur = answers[q.id];\n                    const on = q.type === \"choice\" ? cur === o : Array.isArray(cur) && cur.includes(o);\n                    return (\n                      <button\n                        key={o}\n                        type=\"button\"\n                        role={q.type === \"choice\" ? \"radio\" : undefined}\n                        aria-checked={q.type === \"choice\" ? on : undefined}\n                        aria-pressed={q.type === \"multi\" ? on : undefined}\n                        data-blink={blink === o}\n                        className=\"hb-xh4-opt\"\n                        onClick={() => {\n                          if (q.type === \"choice\") answer(o, true);\n                          else {\n                            const list = Array.isArray(cur) ? cur : [];\n                            answer(on ? list.filter((x) => x !== o) : [...list, o], false);\n                          }\n                        }}\n                      >\n                        <span className=\"hb-xh4-key\" aria-hidden=\"true\">{letters[i]}</span>\n                        <span className=\"hb-xh4-opt-label\">{o}</span>\n                        {on ? (\n                          <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"m3.5 8.5 3 3 6-7\" /></svg>\n                        ) : null}\n                      </button>\n                    );\n                  })}\n                </div>\n              ) : null}\n              {q.type === \"text\" ? (\n                <textarea\n                  className=\"hb-xh4-area\"\n                  aria-labelledby={`hb-xh4-t-${q.id}`}\n                  placeholder={q.placeholder ?? \"Type your answer here...\"}\n                  value={(answers[q.id] as string | undefined) ?? \"\"}\n                  onChange={(e) => answer(e.target.value.slice(0, 500), false)}\n                  onKeyDown={(e) => {\n                    if (e.key === \"Enter\" && !e.shiftKey) {\n                      e.preventDefault();\n                      advance();\n                    }\n                  }}\n                />\n              ) : null}\n              <div className=\"hb-xh4-row\">\n                {error ? (\n                  <span className=\"hb-xh4-err\" key={error} role=\"alert\">Please pick an answer to continue</span>\n                ) : (\n                  <span className=\"hb-xh4-hint\">\n                    {q.type === \"text\" ? <>press <kbd>Shift</kbd>+<kbd>Enter</kbd> for a new line</> : q.type === \"nps\" ? <>press <kbd>0</kbd> to <kbd>9</kbd></> : <>press <kbd>A</kbd> to <kbd>{letters[(q.options?.length ?? 1) - 1]}</kbd></>}\n                  </span>\n                )}\n                {q.type === \"multi\" || q.type === \"text\" || !autoAdvance ? (\n                  <button type=\"button\" className=\"hb-xh4-ok\" onClick={advance}>\n                    {index === total - 1 ? \"Submit\" : \"OK\"}\n                    {arrow(\"M3 7.5 6 10.5 11.5 4\")}\n                  </button>\n                ) : null}\n              </div>\n            </div>\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}