{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth-flow-otp-verify",
  "type": "registry:component",
  "title": "Auth Flow OTP Verify",
  "description": "A one-time code screen built on a single native input under a segmented rail: digits drop into their slots, a glowing bar glides to the next one and the code checks itself when complete. A delivery switch for text, email or call, a depleting resend ring, attempt limits and a verifying sweep complete the flow.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "auth",
    "auth",
    "otp",
    "verification",
    "one-time code",
    "2fa",
    "resend timer"
  ],
  "docs": "https://hyperblur.dev/effects/auth-flow-otp-verify",
  "files": [
    {
      "path": "registry/hyperblur/auth-flow-otp-verify.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/auth-flow-otp-verify.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type AuthFlowOtpChannel = \"sms\" | \"email\" | \"call\";\n\nexport interface AuthFlowOtpVerifyProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\" | \"defaultValue\" | \"onChange\"> {\n  title?: string;\n  length?: number;\n  destinations?: Partial<Record<AuthFlowOtpChannel, string>>;\n  defaultChannel?: AuthFlowOtpChannel;\n  defaultValue?: string;\n  resendSeconds?: number;\n  maxAttempts?: number;\n  onVerify?: (code: string, channel: AuthFlowOtpChannel) => boolean | void | Promise<boolean | void>;\n  onResend?: (channel: AuthFlowOtpChannel) => void;\n  onChannelChange?: (channel: AuthFlowOtpChannel) => void;\n  onBack?: () => void;\n  headingAs?: \"h1\" | \"h2\" | \"h3\";\n  accent?: string;\n}\n\nconst channelLabels: Record<AuthFlowOtpChannel, string> = { sms: \"Text\", email: \"Email\", call: \"Call\" };\n\nconst css = `\n@keyframes hb-vg1-drop {\n  0% { opacity: 0; transform: translate3d(0, -14px, 0) scale(.7); }\n  60% { opacity: 1; transform: translate3d(0, 2px, 0) scale(1.06); }\n  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }\n}\n@keyframes hb-vg1-shake {\n  0%, 100% { transform: translateX(0); }\n  18% { transform: translateX(-10px); }\n  36% { transform: translateX(8px); }\n  54% { transform: translateX(-5px); }\n  72% { transform: translateX(3px); }\n}\n@keyframes hb-vg1-sweep {\n  from { transform: translateX(-100%); }\n  to { transform: translateX(100%); }\n}\n@keyframes hb-vg1-blink { 50% { opacity: 0; } }\n@keyframes hb-vg1-draw { to { stroke-dashoffset: 0; } }\n@keyframes hb-vg1-rise {\n  from { opacity: 0; transform: translate3d(0, 8px, 0); }\n  to { opacity: 1; transform: translate3d(0, 0, 0); }\n}\n.hb-vg1 {\n  --hb-vg1-accent: #22d3ee;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  padding: 88px 20px;\n  overflow: hidden;\n  isolation: isolate;\n  container-type: inline-size;\n  background: #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-vg1 *, .hb-vg1 *::before, .hb-vg1 *::after { box-sizing: border-box; }\n.hb-vg1::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  z-index: -1;\n  background:\n    radial-gradient(ellipse 46% 38% at 50% 0%, color-mix(in srgb, var(--hb-vg1-accent) 18%, transparent), transparent 72%),\n    repeating-linear-gradient(90deg, rgba(255,255,255,.025) 0 1px, transparent 1px 64px);\n  -webkit-mask-image: linear-gradient(180deg, #000 30%, transparent);\n  mask-image: linear-gradient(180deg, #000 30%, transparent);\n}\n.hb-vg1-card {\n  position: relative;\n  max-width: 480px;\n  margin: 0 auto;\n  padding: 36px 36px 28px;\n  border: 1px solid #222;\n  border-radius: 22px;\n  background: linear-gradient(180deg, #141414, #0e0e0e);\n  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 40px 80px -40px rgba(0,0,0,.9), 0 0 0 1px rgba(0,0,0,.4);\n}\n.hb-vg1-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }\n.hb-vg1-step { color: #8f8f8f; font-size: 12px; font-weight: 550; letter-spacing: .08em; text-transform: uppercase; font-family: var(--font-mono), ui-monospace, monospace; }\n.hb-vg1-seg {\n  position: relative;\n  display: inline-grid;\n  grid-auto-flow: column;\n  grid-auto-columns: 1fr;\n  padding: 3px;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #0a0a0a;\n}\n.hb-vg1-thumb {\n  position: absolute;\n  top: 3px;\n  bottom: 3px;\n  left: 3px;\n  border-radius: 999px;\n  background: linear-gradient(180deg, #262626, #1c1c1c);\n  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 2px 6px rgba(0,0,0,.5);\n  transition: transform .42s cubic-bezier(.3, 1.3, .5, 1);\n}\n.hb-vg1-chan {\n  position: relative;\n  z-index: 1;\n  min-width: 58px;\n  padding: 6px 12px;\n  border: 0;\n  border-radius: 999px;\n  background: none;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 550;\n  cursor: pointer;\n  transition: color .2s ease;\n}\n.hb-vg1-chan[aria-checked=\"true\"] { color: #ededed; }\n.hb-vg1-chan:focus-visible { outline: 2px solid var(--hb-vg1-accent); outline-offset: 1px; }\n.hb-vg1-title { margin: 26px 0 0; font-size: 28px; font-weight: 650; letter-spacing: -.03em; line-height: 1.15; }\n.hb-vg1-sub { margin: 10px 0 0; color: #a1a1a1; font-size: 14.5px; line-height: 1.6; min-height: 46px; }\n.hb-vg1-sub strong { color: #ededed; font-weight: 550; font-family: var(--font-mono), ui-monospace, monospace; font-size: 13.5px; }\n.hb-vg1-field { position: relative; margin-top: 26px; }\n.hb-vg1-input {\n  position: absolute;\n  inset: 0;\n  z-index: 2;\n  width: 100%;\n  height: 100%;\n  border: 0;\n  background: transparent;\n  color: transparent;\n  caret-color: transparent;\n  font-size: 16px;\n  letter-spacing: 3em;\n  outline: none;\n  opacity: .01;\n  cursor: text;\n}\n.hb-vg1-rail {\n  position: relative;\n  display: grid;\n  grid-template-columns: repeat(var(--hb-vg1-n), 1fr);\n  overflow: hidden;\n  height: 72px;\n  border: 1px solid #262626;\n  border-radius: 16px;\n  background: linear-gradient(180deg, #0b0b0b, #101010);\n  box-shadow: inset 0 2px 8px rgba(0,0,0,.6);\n  transition: border-color .25s ease, box-shadow .25s ease;\n}\n.hb-vg1-field[data-focus=\"true\"] .hb-vg1-rail { border-color: color-mix(in srgb, var(--hb-vg1-accent) 60%, #262626); box-shadow: inset 0 2px 8px rgba(0,0,0,.6), 0 0 0 4px color-mix(in srgb, var(--hb-vg1-accent) 14%, transparent); }\n.hb-vg1-slot {\n  position: relative;\n  display: grid;\n  place-items: center;\n  font-family: var(--font-mono), ui-monospace, monospace;\n  font-size: 30px;\n  font-weight: 500;\n  font-variant-numeric: tabular-nums;\n  color: #ededed;\n}\n.hb-vg1-slot + .hb-vg1-slot::before {\n  content: \"\";\n  position: absolute;\n  left: 0;\n  top: 22%;\n  bottom: 22%;\n  width: 1px;\n  background: #1f1f1f;\n}\n.hb-vg1-slot[data-mid=\"true\"]::before { top: 36%; bottom: 36%; width: 8px; left: -4px; height: auto; border-radius: 2px; background: #2a2a2a; }\n.hb-vg1-digit { display: inline-block; animation: hb-vg1-drop .38s cubic-bezier(.3, 1.4, .5, 1) both; }\n.hb-vg1-dot { width: 6px; height: 6px; border-radius: 50%; background: #2c2c2c; }\n.hb-vg1-caret { width: 2px; height: 30px; border-radius: 2px; background: var(--hb-vg1-accent); animation: hb-vg1-blink 1s steps(1) infinite; }\n.hb-vg1-bar {\n  position: absolute;\n  bottom: 0;\n  left: 0;\n  height: 3px;\n  width: calc(100% / var(--hb-vg1-n));\n  border-radius: 3px 3px 0 0;\n  background: var(--hb-vg1-accent);\n  box-shadow: 0 0 18px var(--hb-vg1-accent);\n  transform: translateX(calc(var(--hb-vg1-i) * 100%));\n  transition: transform .34s cubic-bezier(.3, 1.2, .5, 1), opacity .2s ease;\n}\n.hb-vg1-field[data-focus=\"false\"] .hb-vg1-bar { opacity: .35; }\n.hb-vg1-scan {\n  position: absolute;\n  inset: 0;\n  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--hb-vg1-accent) 26%, transparent), transparent);\n  animation: hb-vg1-sweep 1s cubic-bezier(.6, 0, .4, 1) infinite;\n}\n.hb-vg1[data-status=\"error\"] .hb-vg1-rail { border-color: #7f1d1d; animation: hb-vg1-shake .45s cubic-bezier(.36, .07, .19, .97); }\n.hb-vg1[data-status=\"error\"] .hb-vg1-slot { color: #fca5a5; }\n.hb-vg1[data-status=\"error\"] .hb-vg1-bar { background: #f87171; box-shadow: 0 0 18px #f87171; }\n.hb-vg1[data-status=\"success\"] .hb-vg1-rail { border-color: #14532d; background: linear-gradient(180deg, #08130c, #0b1a10); }\n.hb-vg1[data-status=\"success\"] .hb-vg1-slot { color: #86efac; }\n.hb-vg1[data-status=\"success\"] .hb-vg1-bar { opacity: 0; }\n.hb-vg1-msg { display: flex; align-items: center; gap: 8px; min-height: 22px; margin-top: 12px; color: #8f8f8f; font-size: 13px; }\n.hb-vg1-msg[data-tone=\"error\"] { color: #fca5a5; }\n.hb-vg1-msg[data-tone=\"success\"] { color: #86efac; animation: hb-vg1-rise .4s cubic-bezier(.2, .8, .2, 1) both; }\n.hb-vg1-check path { stroke-dasharray: 24; stroke-dashoffset: 24; animation: hb-vg1-draw .5s .1s cubic-bezier(.65, 0, .35, 1) forwards; }\n.hb-vg1-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 22px; padding-top: 20px; border-top: 1px solid #1f1f1f; }\n.hb-vg1-hint { color: #8f8f8f; font-size: 13px; }\n.hb-vg1-hint kbd { padding: 1px 6px; border: 1px solid #2a2a2a; border-bottom-width: 2px; border-radius: 5px; background: #151515; color: #cfcfcf; font: 500 11px/1.4 var(--font-mono), ui-monospace, monospace; }\n.hb-vg1-back { padding: 0; border: 0; border-radius: 4px; background: none; color: var(--hb-vg1-accent); font: inherit; font-weight: 550; cursor: pointer; }\n.hb-vg1-back:hover { text-decoration: underline; text-underline-offset: 3px; }\n.hb-vg1-back:focus-visible { outline: 2px solid var(--hb-vg1-accent); outline-offset: 2px; }\n.hb-vg1-resend {\n  display: inline-flex;\n  align-items: center;\n  gap: 10px;\n  padding: 6px 14px 6px 6px;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  background: #121212;\n  color: #ededed;\n  font: inherit;\n  font-size: 13px;\n  font-weight: 550;\n  cursor: pointer;\n  transition: border-color .2s ease, background .2s ease, transform .15s ease;\n}\n.hb-vg1-resend:hover:not(:disabled) { border-color: #3a3a3a; background: #171717; }\n.hb-vg1-resend:active:not(:disabled) { transform: scale(.97); }\n.hb-vg1-resend:disabled { color: #8f8f8f; cursor: default; }\n.hb-vg1-resend:focus-visible { outline: 2px solid var(--hb-vg1-accent); outline-offset: 2px; }\n.hb-vg1-ring { position: relative; display: grid; place-items: center; width: 26px; height: 26px; }\n.hb-vg1-ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }\n.hb-vg1-ring-track { stroke: #262626; }\n.hb-vg1-ring-fill { stroke: var(--hb-vg1-accent); transition: stroke-dashoffset 1s linear; }\n.hb-vg1-ring span { font: 600 9.5px/1 var(--font-mono), ui-monospace, monospace; font-variant-numeric: tabular-nums; }\n@media (max-width: 520px) {\n  .hb-vg1-card { padding: 26px 20px 22px; }\n  .hb-vg1-top { flex-direction: column; align-items: flex-start; }\n  .hb-vg1-rail { height: 60px; }\n  .hb-vg1-slot { font-size: 24px; }\n  .hb-vg1-foot { flex-direction: column; align-items: flex-start; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vg1 *, .hb-vg1 *::before, .hb-vg1 *::after { animation: none !important; transition: none !important; }\n  .hb-vg1-check path { stroke-dashoffset: 0; }\n}\n`;\n\ntype Status = \"idle\" | \"verifying\" | \"error\" | \"success\" | \"locked\";\n\nfunction settle(result: boolean | void | Promise<boolean | void>) {\n  return result instanceof Promise ? result : new Promise<boolean | void>((resolve) => window.setTimeout(() => resolve(result), 900));\n}\n\nexport function AuthFlowOtpVerify({\n  title = \"Enter the code we sent\",\n  length = 6,\n  destinations = { sms: \"+1 (415) ••• ••82\", email: \"m•••@northwind.io\", call: \"+1 (415) ••• ••82\" },\n  defaultChannel = \"sms\",\n  defaultValue = \"\",\n  resendSeconds = 30,\n  maxAttempts = 3,\n  onVerify,\n  onResend,\n  onChannelChange,\n  onBack,\n  headingAs = \"h2\",\n  accent = \"#22d3ee\",\n  className = \"\",\n  style,\n  ...rest\n}: AuthFlowOtpVerifyProps) {\n  const Heading = headingAs;\n  const uid = React.useId();\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const channels = (Object.keys(channelLabels) as AuthFlowOtpChannel[]).filter((c) => destinations[c]);\n  const [channel, setChannel] = React.useState<AuthFlowOtpChannel>(channels.includes(defaultChannel) ? defaultChannel : channels[0] ?? \"sms\");\n  const [code, setCode] = React.useState(defaultValue.replace(/\\D/g, \"\").slice(0, length));\n  const [focus, setFocus] = React.useState(false);\n  const [status, setStatus] = React.useState<Status>(\"idle\");\n  const [attempts, setAttempts] = React.useState(0);\n  const [left, setLeft] = React.useState(resendSeconds);\n  const [notice, setNotice] = React.useState(\"\");\n\n  React.useEffect(() => {\n    if (left <= 0) return;\n    const id = window.setTimeout(() => setLeft((s) => s - 1), 1000);\n    return () => window.clearTimeout(id);\n  }, [left]);\n\n  const verify = React.useCallback(\n    (value: string) => {\n      setStatus(\"verifying\");\n      setNotice(\"Checking code\");\n      settle(onVerify ? onVerify(value, channel) : true).then(\n        (ok) => {\n          if (ok === false) {\n            const next = attempts + 1;\n            setAttempts(next);\n            if (next >= maxAttempts) {\n              setStatus(\"locked\");\n              setNotice(\"Too many attempts. Request a new code to continue.\");\n            } else {\n              setStatus(\"error\");\n              setNotice(`That code didn't match. ${maxAttempts - next} ${maxAttempts - next === 1 ? \"attempt\" : \"attempts\"} left.`);\n              window.setTimeout(() => {\n                setCode(\"\");\n                inputRef.current?.focus();\n              }, 450);\n            }\n          } else {\n            setStatus(\"success\");\n            setNotice(\"Verified. Signing you in\");\n          }\n        },\n        () => {\n          setStatus(\"error\");\n          setNotice(\"We couldn't reach the server. Try again.\");\n        },\n      );\n    },\n    [attempts, channel, maxAttempts, onVerify],\n  );\n\n  const change = (e: React.ChangeEvent<HTMLInputElement>) => {\n    if (status === \"verifying\" || status === \"success\" || status === \"locked\") return;\n    const next = e.target.value.replace(/\\D/g, \"\").slice(0, length);\n    setCode(next);\n    if (status === \"error\") {\n      setStatus(\"idle\");\n      setNotice(\"\");\n    }\n    if (next.length === length) verify(next);\n  };\n\n  const pick = (c: AuthFlowOtpChannel) => {\n    if (status === \"success\") return;\n    setChannel(c);\n    onChannelChange?.(c);\n  };\n\n  const resend = () => {\n    if (left > 0 || status === \"success\") return;\n    onResend?.(channel);\n    setLeft(resendSeconds);\n    setAttempts(0);\n    setCode(\"\");\n    setStatus(\"idle\");\n    setNotice(`New code sent by ${channelLabels[channel].toLowerCase()}.`);\n    inputRef.current?.focus();\n  };\n\n  const onSegKey = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (e.key !== \"ArrowRight\" && e.key !== \"ArrowLeft\") return;\n    e.preventDefault();\n    const i = channels.indexOf(channel);\n    const next = channels[(i + (e.key === \"ArrowRight\" ? 1 : channels.length - 1)) % channels.length];\n    pick(next);\n    const el = e.currentTarget.querySelector<HTMLButtonElement>(`[data-c=\"${next}\"]`);\n    el?.focus();\n  };\n\n  const half = length % 2 === 0 ? length / 2 : -1;\n  const active = Math.min(code.length, length - 1);\n  const C = 2 * Math.PI * 11;\n  const ratio = resendSeconds > 0 ? left / resendSeconds : 0;\n  const verb = channel === \"email\" ? \"emailed\" : channel === \"call\" ? \"will read it to\" : \"texted\";\n  const vars = { \"--hb-vg1-accent\": accent, \"--hb-vg1-n\": length, \"--hb-vg1-i\": active, ...style } as React.CSSProperties;\n  const tone = status === \"error\" || status === \"locked\" ? \"error\" : status === \"success\" ? \"success\" : \"info\";\n\n  return (\n    <section\n      className={`hb-vg1 ${className}`}\n      style={vars}\n      data-status={status}\n      aria-labelledby={`${uid}-t`}\n      onKeyDown={(e) => {\n        if (e.key === \"Escape\" && onBack) onBack();\n      }}\n      {...rest}\n    >\n      <style href=\"hb-auth-flow-otp-verify\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vg1-card\">\n        <div className=\"hb-vg1-top\">\n          <span className=\"hb-vg1-step\">Step 2 of 2</span>\n          {channels.length > 1 ? (\n            <div className=\"hb-vg1-seg\" role=\"radiogroup\" aria-label=\"Delivery method\" onKeyDown={onSegKey}>\n              <span className=\"hb-vg1-thumb\" aria-hidden=\"true\" style={{ width: `calc((100% - 6px) / ${channels.length})`, transform: `translateX(${channels.indexOf(channel) * 100}%)` }} />\n              {channels.map((c) => (\n                <button key={c} type=\"button\" role=\"radio\" data-c={c} aria-checked={c === channel} tabIndex={c === channel ? 0 : -1} className=\"hb-vg1-chan\" onClick={() => pick(c)}>\n                  {channelLabels[c]}\n                </button>\n              ))}\n            </div>\n          ) : null}\n        </div>\n        <Heading id={`${uid}-t`} className=\"hb-vg1-title\">{status === \"success\" ? \"You're verified\" : title}</Heading>\n        <p className=\"hb-vg1-sub\">\n          {channel === \"call\" ? (\n            <>We {verb} <strong>{destinations[channel]}</strong> in a moment. Type the {length} digits you hear.</>\n          ) : (\n            <>We {verb} a {length}-digit code to <strong>{destinations[channel]}</strong>. It expires in 10 minutes.</>\n          )}\n        </p>\n        <div className=\"hb-vg1-field\" data-focus={focus}>\n          <input\n            ref={inputRef}\n            className=\"hb-vg1-input\"\n            value={code}\n            onChange={change}\n            onFocus={() => setFocus(true)}\n            onBlur={() => setFocus(false)}\n            inputMode=\"numeric\"\n            autoComplete=\"one-time-code\"\n            pattern=\"[0-9]*\"\n            maxLength={length}\n            aria-label={`${length}-digit verification code`}\n            aria-describedby={`${uid}-m`}\n            aria-invalid={status === \"error\" || undefined}\n            disabled={status === \"success\" || status === \"locked\"}\n          />\n          <div className=\"hb-vg1-rail\" aria-hidden=\"true\">\n            {Array.from({ length }, (_, i) => (\n              <span key={i} className=\"hb-vg1-slot\" data-mid={i === half}>\n                {code[i] ? (\n                  <span key={`${i}-${code[i]}`} className=\"hb-vg1-digit\">{code[i]}</span>\n                ) : focus && i === code.length ? (\n                  <span className=\"hb-vg1-caret\" />\n                ) : (\n                  <span className=\"hb-vg1-dot\" />\n                )}\n              </span>\n            ))}\n            <span className=\"hb-vg1-bar\" />\n            {status === \"verifying\" ? <span className=\"hb-vg1-scan\" /> : null}\n          </div>\n        </div>\n        <div id={`${uid}-m`} className=\"hb-vg1-msg\" data-tone={tone} role=\"status\" aria-live=\"polite\">\n          {status === \"success\" ? (\n            <svg className=\"hb-vg1-check\" width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n            </svg>\n          ) : null}\n          {notice || \"Paste the code or type it. It checks itself when complete.\"}\n        </div>\n        <div className=\"hb-vg1-foot\">\n          <span className=\"hb-vg1-hint\">\n            Wrong {channel === \"email\" ? \"address\" : \"number\"}?{\" \"}\n            <button type=\"button\" className=\"hb-vg1-back\" onClick={() => onBack?.()}>Go back</button> or press <kbd>Esc</kbd>\n          </span>\n          <button type=\"button\" className=\"hb-vg1-resend\" onClick={resend} disabled={left > 0 || status === \"success\"}>\n            <span className=\"hb-vg1-ring\" aria-hidden=\"true\">\n              <svg width=\"26\" height=\"26\" viewBox=\"0 0 26 26\" fill=\"none\" strokeWidth=\"2.2\">\n                <circle className=\"hb-vg1-ring-track\" cx=\"13\" cy=\"13\" r=\"11\" />\n                <circle className=\"hb-vg1-ring-fill\" cx=\"13\" cy=\"13\" r=\"11\" strokeLinecap=\"round\" strokeDasharray={C.toFixed(2)} strokeDashoffset={(C * (1 - ratio)).toFixed(2)} />\n              </svg>\n              <span>{left > 0 ? left : \"↻\"}</span>\n            </span>\n            {left > 0 ? \"Resend soon\" : \"Resend code\"}\n          </button>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}