{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "author": "DesignX ", "name": "digit-input", "type": "registry:component", "title": "Digit Input", "description": "One-time-code input where each digit rolls in with motion.", "dependencies": [ "motion@^14.0.0" ], "registryDependencies": [ "@dx/utils" ], "files": [ { "path": "dx/digit-input.tsx", "type": "registry:component", "target": "components/dx/digit-input.tsx", "content": "import * as React from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/**\n * DigitInputevery typed character rises into place. The real input stays\n * on top (transparent text) so selection, paste and a11y keep working.\n *\n */\n\ntype DigitInputProps = Omit, \"value\" | \"defaultValue\" | \"onChange\"> & {\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n /** Restrict input to digits. */\n numeric?: boolean;\n wrapperClassName?: string;\n};\n\nfunction DigitInput({\n value,\n defaultValue = \"\",\n onValueChange,\n numeric = false,\n placeholder = \"0\",\n className,\n wrapperClassName,\n ...props\n}: DigitInputProps) {\n const [internal, setInternal] = React.useState(defaultValue);\n const controlled = value !== undefined;\n const current = controlled ? value : internal;\n\n return (\n \n {\n const next = numeric ? e.target.value.replace(/\\D/g, \"\") : e.target.value;\n if (!controlled) setInternal(next);\n onValueChange?.(next);\n }}\n className={cn(\n \"caret-primary relative z-10 w-full bg-transparent py-2 text-center text-transparent outline-none selection:bg-info/20\",\n className,\n )}\n />\n
\n {current === \"\" && {placeholder}}\n \n {current.split(\"\").map((ch, i) => (\n \n {ch}\n \n ))}\n \n
\n \n );\n}\n\nexport { DigitInput };\nexport type { DigitInputProps };\n" } ], "categories": [ "motion" ], "meta": { "group": "dx", "docs": "https://dxuireact.com/docs/components/digit-input", "modernWebGuidance": "https://developer.chrome.com/docs/modern-web-guidance", "standards": [ "accessibility", "performance", "css-layout" ] } }