{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "passcode-pad",
  "title": "Passcode Pad",
  "author": "VenusUI",
  "description": "A lock-screen passcode keypad that shakes on a wrong code and unlocks on the right one.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/passcode-pad.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Delete, Lock, LockOpen } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface PasscodePadProps extends Omit<React.ComponentProps<\"div\">, \"onSubmit\"> {\n  /** Number of digits. */\n  length?: number\n  /** Checks a complete code; return true to unlock. Can be async. */\n  onSubmit: (code: string) => boolean | Promise<boolean>\n  /** Heading above the dots. */\n  title?: string\n  /** Shown once unlocked. */\n  successMessage?: string\n}\n\nconst KEYS = [\n  [\"1\", \"\"],\n  [\"2\", \"ABC\"],\n  [\"3\", \"DEF\"],\n  [\"4\", \"GHI\"],\n  [\"5\", \"JKL\"],\n  [\"6\", \"MNO\"],\n  [\"7\", \"PQRS\"],\n  [\"8\", \"TUV\"],\n  [\"9\", \"WXYZ\"],\n] as const\n\n/**\n * A lock-screen passcode pad. Tap the keys (or type digits; Backspace\n * deletes). A wrong code shakes the dots and clears; the right one unlocks.\n * Progress and the result are announced to screen readers.\n */\nfunction PasscodePad({ length = 4, onSubmit, title = \"Enter passcode\", successMessage = \"Unlocked\", className, ...props }: PasscodePadProps) {\n  const [digits, setDigits] = React.useState(\"\")\n  const [state, setState] = React.useState<\"idle\" | \"checking\" | \"wrong\" | \"unlocked\">(\"idle\")\n  const dotsRef = React.useRef<HTMLDivElement>(null)\n\n  const press = async (digit: string) => {\n    if (state === \"checking\" || state === \"unlocked\") return\n    const next = (state === \"wrong\" ? \"\" : digits) + digit\n    setState(\"idle\")\n    setDigits(next)\n    if (next.length < length) return\n    setState(\"checking\")\n    const ok = await onSubmit(next)\n    if (ok) {\n      setState(\"unlocked\")\n      return\n    }\n    setState(\"wrong\")\n    dotsRef.current?.animate(\n      [0, -12, 10, -8, 6, -3, 0].map((x) => ({ transform: `translateX(${x}px)` })),\n      { duration: 420, easing: \"ease-out\" }\n    )\n    setTimeout(() => setDigits(\"\"), 420)\n  }\n\n  const remove = () => {\n    if (state === \"checking\" || state === \"unlocked\") return\n    setState(\"idle\")\n    setDigits((d) => d.slice(0, -1))\n  }\n\n  const status =\n    state === \"unlocked\"\n      ? successMessage\n      : state === \"wrong\"\n        ? \"Wrong passcode. Try again.\"\n        : `${digits.length} of ${length} digits entered`\n\n  return (\n    <div\n      data-slot=\"passcode-pad\"\n      className={cn(\"flex w-full max-w-[18rem] flex-col items-center gap-7 select-none\", className)}\n      onKeyDown={(event) => {\n        if (/^\\d$/.test(event.key)) {\n          event.preventDefault()\n          void press(event.key)\n        } else if (event.key === \"Backspace\") {\n          event.preventDefault()\n          remove()\n        }\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-col items-center gap-3\">\n        <span\n          className={cn(\n            \"grid size-11 place-items-center rounded-full transition-colors\",\n            state === \"unlocked\" ? \"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400\" : \"bg-muted text-muted-foreground\"\n          )}\n        >\n          {state === \"unlocked\" ? <LockOpen aria-hidden=\"true\" className=\"size-5\" /> : <Lock aria-hidden=\"true\" className=\"size-5\" />}\n        </span>\n        <p className=\"text-base font-medium\">{state === \"unlocked\" ? successMessage : title}</p>\n        <div ref={dotsRef} aria-hidden=\"true\" className=\"flex gap-4\">\n          {Array.from({ length }, (_, i) => (\n            <span\n              key={i}\n              className={cn(\n                \"size-3.5 rounded-full border-2 transition-colors duration-150\",\n                state === \"unlocked\"\n                  ? \"border-emerald-500 bg-emerald-500\"\n                  : state === \"wrong\"\n                    ? \"border-red-500 bg-red-500\"\n                    : i < digits.length\n                      ? \"border-foreground bg-foreground\"\n                      : \"border-foreground/40\"\n              )}\n            />\n          ))}\n        </div>\n        <p role=\"status\" className=\"sr-only\">\n          {status}\n        </p>\n      </div>\n\n      <div role=\"group\" aria-label=\"Keypad\" className=\"grid grid-cols-3 gap-4\">\n        {KEYS.map(([digit, letters]) => (\n          <KeyButton key={digit} onPress={() => void press(digit)} label={digit} letters={letters} disabled={state === \"unlocked\"} />\n        ))}\n        <span />\n        <KeyButton onPress={() => void press(\"0\")} label=\"0\" letters=\"\" disabled={state === \"unlocked\"} />\n        <button\n          type=\"button\"\n          aria-label=\"Delete\"\n          onClick={remove}\n          disabled={state === \"unlocked\" || digits.length === 0}\n          className=\"grid size-[4.5rem] place-items-center rounded-full text-foreground outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-30\"\n        >\n          <Delete aria-hidden=\"true\" className=\"size-6\" />\n        </button>\n      </div>\n    </div>\n  )\n}\n\nfunction KeyButton({ onPress, label, letters, disabled }: { onPress: () => void; label: string; letters: string; disabled: boolean }) {\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      onClick={onPress}\n      disabled={disabled}\n      className=\"flex size-[4.5rem] flex-col items-center justify-center rounded-full bg-muted/70 text-foreground transition-colors outline-none hover:bg-muted active:bg-foreground/15 focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-40\"\n    >\n      <span className=\"text-[1.7rem] leading-none font-light\">{label}</span>\n      {letters ? <span className=\"mt-0.5 text-[9px] font-semibold tracking-[0.2em] text-foreground/65\">{letters}</span> : null}\n    </button>\n  )\n}\n\nexport { PasscodePad }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.1"
  },
  "categories": [
    "inputs",
    "forms"
  ],
  "type": "registry:ui"
}