{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-otp",
  "title": "Input OTP",
  "description": "A one-time-code input with individual animated cells, paste and autofill support, numeric or alphanumeric mode, masking, grouped cells, error shake and success states.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/input-otp/input-otp.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type InputOTPSize = \"sm\" | \"md\" | \"lg\";\nexport type InputOTPStatus = \"idle\" | \"error\" | \"success\";\n\nexport interface InputOTPProps {\n  length?: number;\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  onComplete?: (value: string) => void;\n  type?: \"numeric\" | \"alphanumeric\";\n  mask?: boolean;\n  groupSize?: number;\n  status?: InputOTPStatus;\n  label?: string;\n  helperText?: string;\n  errorText?: string;\n  size?: InputOTPSize;\n  theme?: \"dark\" | \"light\";\n  autoFocus?: boolean;\n  disabled?: boolean;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.28)\", bg: \"rgba(255,255,255,0.03)\", filled: \"rgba(255,255,255,0.06)\", border: \"rgba(255,255,255,0.12)\", borderHover: \"rgba(255,255,255,0.24)\", focus: \"rgba(245,244,241,0.9)\", error: \"#FF7A6B\", success: \"#F5F4F1\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.28)\", bg: \"#FFFFFF\", filled: \"rgba(10,10,10,0.04)\", border: \"rgba(10,10,10,0.16)\", borderHover: \"rgba(10,10,10,0.3)\", focus: \"rgba(10,10,10,0.9)\", error: \"#E5484D\", success: \"#0A0A0A\" },\n};\n\nconst SIZES: Record<InputOTPSize, { w: number; h: number; font: number; radius: number; gap: number; label: number }> = {\n  sm: { w: 36, h: 44, font: 18, radius: 11, gap: 8, label: 13 },\n  md: { w: 46, h: 56, font: 24, radius: 14, gap: 10, label: 14.5 },\n  lg: { w: 56, h: 68, font: 30, radius: 16, gap: 12, label: 16 },\n};\n\nexport function InputOTP({\n  length = 6,\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  onComplete,\n  type = \"numeric\",\n  mask = false,\n  groupSize,\n  status = \"idle\",\n  label,\n  helperText,\n  errorText,\n  size = \"md\",\n  theme = \"dark\",\n  autoFocus = false,\n  disabled = false,\n  className,\n}: InputOTPProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const [internal, setInternal] = React.useState(defaultValue);\n  const [focused, setFocused] = React.useState(false);\n  const [hovered, setHovered] = React.useState(-1);\n  const [shakeKey, setShakeKey] = React.useState(0);\n  const [prevStatus, setPrevStatus] = React.useState(status);\n  const controlled = value !== undefined;\n\n  const sanitize = React.useCallback(\n    (raw: string) => (type === \"numeric\" ? raw.replace(/\\D/g, \"\") : raw.replace(/[^a-zA-Z0-9]/g, \"\")).slice(0, length),\n    [type, length],\n  );\n  const current = sanitize(controlled ? value : internal);\n\n  if (status !== prevStatus) {\n    setPrevStatus(status);\n    if (status === \"error\") setShakeKey((k) => k + 1);\n  }\n\n  const commit = (next: string) => {\n    if (next === current) return;\n    if (!controlled) setInternal(next);\n    onValueChange?.(next);\n    if (next.length === length) onComplete?.(next);\n  };\n\n  const activeIndex = Math.min(current.length, length - 1);\n  const isError = status === \"error\";\n  const isSuccess = status === \"success\";\n\n  const groups = groupSize && groupSize > 0 && groupSize < length ? groupSize : 0;\n\n  return (\n    <div className={cn(\"inline-flex flex-col gap-3\", className)} style={{ fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      {label && (\n        <label id={`${uid}-label`} htmlFor={`${uid}-input`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.label }}>\n          {label}\n        </label>\n      )}\n\n      <motion.div\n        key={shakeKey}\n        className=\"relative inline-flex items-center\"\n        style={{ gap: s.gap }}\n        animate={shakeKey > 0 ? { x: [0, -9, 9, -6, 6, -3, 3, 0] } : undefined}\n        transition={{ duration: 0.42, ease: \"easeOut\" }}\n        onClick={() => !disabled && inputRef.current?.focus()}\n      >\n        {Array.from({ length }).map((_, i) => {\n          const char = current[i];\n          const isActive = focused && !disabled && i === activeIndex;\n          const showCaret = focused && i === current.length && current.length < length;\n          const ring = isError ? p.error : isSuccess ? p.success : isActive ? p.focus : hovered === i ? p.borderHover : p.border;\n          return (\n            <React.Fragment key={i}>\n              {groups > 0 && i > 0 && i % groups === 0 && (\n                <span aria-hidden=\"true\" style={{ width: Math.round(s.gap * 0.9), height: 2, borderRadius: 2, background: p.faint, flexShrink: 0 }} />\n              )}\n              <div\n                onMouseEnter={() => setHovered(i)}\n                onMouseLeave={() => setHovered(-1)}\n                className=\"relative flex items-center justify-center\"\n                style={{ width: s.w, height: s.h, borderRadius: s.radius, background: char ? p.filled : p.bg, border: `1px solid ${ring}`, boxShadow: isActive || isError || isSuccess ? `0 0 0 3px color-mix(in srgb, ${ring} 16%, transparent)` : \"0 0 0 0 transparent\", transition: \"border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease\", cursor: disabled ? \"default\" : \"text\" }}\n              >\n                <AnimatePresence mode=\"popLayout\" initial={false}>\n                  {char && (\n                    <motion.span\n                      key={`${i}-${char}`}\n                      initial={{ scale: 0.4, opacity: 0, y: 6 }}\n                      animate={{ scale: 1, opacity: 1, y: 0 }}\n                      exit={{ scale: 0.6, opacity: 0 }}\n                      transition={{ type: \"spring\", stiffness: 520, damping: 26 }}\n                      className=\"font-semibold tabular-nums\"\n                      style={{ color: p.text, fontSize: mask ? s.font * 0.6 : s.font, lineHeight: 1 }}\n                    >\n                      {mask ? \"●\" : char}\n                    </motion.span>\n                  )}\n                </AnimatePresence>\n                {showCaret && (\n                  <motion.span aria-hidden=\"true\" className=\"absolute\" style={{ width: 2, height: s.font, borderRadius: 2, background: p.text }} animate={{ opacity: [1, 1, 0, 0] }} transition={{ duration: 1.05, repeat: Infinity, times: [0, 0.5, 0.5, 1] }} />\n                )}\n              </div>\n            </React.Fragment>\n          );\n        })}\n\n        <input\n          ref={inputRef}\n          id={`${uid}-input`}\n          value={current}\n          disabled={disabled}\n          autoFocus={autoFocus}\n          autoComplete=\"one-time-code\"\n          inputMode={type === \"numeric\" ? \"numeric\" : \"text\"}\n          maxLength={length * 2}\n          aria-label={label ? undefined : \"One-time code\"}\n          aria-describedby={helperText || errorText ? `${uid}-help` : undefined}\n          aria-invalid={isError || undefined}\n          onChange={(e) => commit(sanitize(e.target.value))}\n          onFocus={(e) => {\n            setFocused(true);\n            const end = e.currentTarget.value.length;\n            requestAnimationFrame(() => e.currentTarget.setSelectionRange(end, end));\n          }}\n          onBlur={() => setFocused(false)}\n          onSelect={(e) => {\n            const el = e.currentTarget;\n            if (el.selectionStart !== el.value.length || el.selectionEnd !== el.value.length) el.setSelectionRange(el.value.length, el.value.length);\n          }}\n          className=\"absolute inset-0 h-full w-full cursor-text border-none bg-transparent opacity-0 outline-none\"\n          style={{ caretColor: \"transparent\", color: \"transparent\" }}\n        />\n      </motion.div>\n\n      <AnimatePresence mode=\"wait\" initial={false}>\n        {(isError && errorText) || helperText ? (\n          <motion.span key={isError && errorText ? \"err\" : \"help\"} id={`${uid}-help`} role={isError ? \"alert\" : undefined} initial={{ opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0 }} transition={{ duration: 0.16 }} style={{ color: isError && errorText ? p.error : p.muted, fontSize: s.label - 1.5, lineHeight: 1.4 }}>\n            {isError && errorText ? errorText : helperText}\n          </motion.span>\n        ) : null}\n      </AnimatePresence>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}