{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"four-digit-pin-input-with-masked-dots","type":"registry:component","title":"Four Digit PIN Input With Masked Dots","description":"","dependencies":[],"files":[{"path":"components/we-inc/four-digit-pin-input-with-masked-dots.tsx","type":"registry:component","content":"import { useRef, useState, type ClipboardEvent, type KeyboardEvent } from \"react\";\n\nconst LENGTH = 4;\n\nexport default function FourDigitPinInputWithMaskedDots() {\n  const [pin, setPin] = useState<string[]>([\"7\", \"3\", \"\", \"\"]);\n  const [show, setShow] = useState(false);\n  const boxes = useRef<(HTMLInputElement | null)[]>([]);\n  const filled = pin.filter(Boolean).length;\n\n  const focusAt = (i: number) => boxes.current[Math.max(0, Math.min(LENGTH - 1, i))]?.focus();\n  const put = (start: number, text: string) => {\n    const next = [...pin];\n    text.split(\"\").slice(0, LENGTH - start).forEach((c, k) => { next[start + k] = c; });\n    setPin(next);\n    focusAt(start + text.length);\n  };\n  const onKey = (i: number, e: KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"Backspace\" && !pin[i] && i > 0) {\n      e.preventDefault();\n      setPin(pin.map((x, j) => (j === i - 1 ? \"\" : x)));\n      focusAt(i - 1);\n    }\n  };\n\n  return (\n    <section className=\"bg-zinc-950 px-4 py-16\">\n      <div className=\"mx-auto max-w-sm rounded-[28px] border border-zinc-800 bg-zinc-900 px-6 py-10 text-center\">\n        <div className=\"mx-auto grid h-12 w-12 place-items-center rounded-full bg-amber-400/10 text-amber-300\" aria-hidden=\"true\">\n          <svg viewBox=\"0 0 24 24\" width=\"22\" height=\"22\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\"><rect x=\"4\" y=\"10\" width=\"16\" height=\"11\" rx=\"2.5\" /><path d=\"M8 10V7a4 4 0 0 1 8 0v3\" /></svg>\n        </div>\n        <h2 className=\"mt-4 text-lg font-semibold text-white\">Enter your card PIN</h2>\n        <p className=\"mt-1 text-sm text-zinc-300\">Debit card ending 4417</p>\n\n        <fieldset className=\"mt-8\">\n          <legend className=\"sr-only\">Four digit PIN</legend>\n          <div className=\"flex justify-center gap-4\">\n            {pin.map((d, i) => (\n              <input\n                key={i}\n                ref={(el) => { boxes.current[i] = el; }}\n                type={show ? \"text\" : \"password\"}\n                value={d}\n                onChange={(e) => {\n                  const only = e.target.value.replace(/\\D/g, \"\");\n                  if (only.length > 1) return put(i, only);\n                  setPin(pin.map((x, j) => (j === i ? only : x)));\n                  if (only) focusAt(i + 1);\n                }}\n                onKeyDown={(e) => onKey(i, e)}\n                onPaste={(e: ClipboardEvent<HTMLInputElement>) => { e.preventDefault(); put(i, e.clipboardData.getData(\"text\").replace(/\\D/g, \"\")); }}\n                inputMode=\"numeric\"\n                autoComplete=\"off\"\n                maxLength={LENGTH}\n                aria-label={`PIN digit ${i + 1} of ${LENGTH}`}\n                className={`h-14 w-14 rounded-full border-2 bg-zinc-950 text-center text-3xl font-semibold text-white caret-amber-300 focus:border-amber-300 focus:outline-none focus:ring-4 focus:ring-amber-300/20 ${d ? \"border-amber-400/70\" : \"border-zinc-700\"}`}\n              />\n            ))}\n          </div>\n        </fieldset>\n\n        <div className=\"mx-auto mt-6 flex max-w-[12rem] justify-between\" aria-hidden=\"true\">\n          {pin.map((d, i) => <span key={i} className={`h-1 w-9 rounded-full ${d ? \"bg-amber-400\" : \"bg-zinc-700\"}`} />)}\n        </div>\n        <p className=\"mt-3 text-sm text-zinc-300\" aria-live=\"polite\">{filled === LENGTH ? \"PIN complete\" : `${LENGTH - filled} digits to go`}</p>\n\n        <button type=\"button\" aria-pressed={show} onClick={() => setShow(!show)} className=\"mt-6 inline-flex h-10 items-center gap-2 rounded-full border border-zinc-700 px-4 text-sm font-medium text-zinc-200 hover:bg-zinc-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-300\">\n          <svg viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" aria-hidden=\"true\"><path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z\" /><circle cx=\"12\" cy=\"12\" r=\"3\" />{show && <path d=\"M3 3l18 18\" strokeLinecap=\"round\" />}</svg>\n          {show ? \"Hide digits\" : \"Show digits\"}\n        </button>\n      </div>\n    </section>\n  );\n}\n"}]}
