{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "otp-field",
  "type": "registry:ui",
  "title": "Otp Field",
  "description": "A one-time code typed into one box per character: typing moves on, Backspace moves back, and a pasted code fills every box.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "radix-ui"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn"
  ],
  "files": [
    {
      "path": "registry/ui/otp-field.tsx",
      "type": "registry:ui",
      "target": "components/ui/otp-field.tsx",
      "content": "\"use client\";\n/**\n * @name otp-field\n * @category ui\n * @description A one-time code typed into one box per character: typing moves on, Backspace moves back, and a pasted code fills every box.\n * @when A short code sent by message or read from an authenticator. It posts as one value under `name`, and the browser can offer the code it has just received. Label it with `aria-label`, or put it in a field with FieldControl group. For a password use password-field; for any other short text use input.\n * @example\n * <OtpField name=\"code\" aria-label=\"Verification code\" onAutoSubmit={verify} autoSubmit />\n * <OtpField length={4} validationType=\"alphanumeric\" value={code} onValueChange={setCode} />\n */\nimport { unstable_OneTimePasswordField as OtpPrimitive } from \"radix-ui\";\nimport { createContext, use, type ComponentProps } from \"react\";\nimport { cn } from \"@/lib/cn\";\n\ntype Naming = (position: number, length: number) => string;\n\nconst defaultNaming: Naming = (position, length) => `Character ${position} of ${length}`;\n\nconst OtpFieldContext = createContext<{ length: number; inputLabel: Naming }>({ length: 6, inputLabel: defaultNaming });\n\nexport type OtpFieldProps = ComponentProps<typeof OtpPrimitive.Root> & {\n  /** How many characters the code has. */\n  length?: number;\n  /** The accessible name of each box, from its position (from 1) and the length. Translate it with the rest of the interface. */\n  inputLabel?: Naming;\n};\n\n/**\n * Holds the value: `value`, `defaultValue`, `onValueChange`; `onAutoSubmit` with `autoSubmit` when the last\n * character is typed. `validationType` is \"numeric\" (the default), \"alpha\", \"alphanumeric\" or \"none\". With no\n * children it draws `length` boxes; pass OtpFieldInput children to arrange them yourself (a gap in the middle).\n */\nexport function OtpField({ className, length = 6, inputLabel = defaultNaming, children, ...props }: OtpFieldProps) {\n  return (\n    <OtpFieldContext value={{ length, inputLabel }}>\n      <OtpPrimitive.Root data-slot=\"otp-field\" className={cn(\"flex w-fit max-w-full items-center gap-2\", className)} {...props}>\n        {children ?? Array.from({ length }, (_, index) => <OtpFieldInput key={index} index={index} />)}\n        <OtpPrimitive.HiddenInput />\n      </OtpPrimitive.Root>\n    </OtpFieldContext>\n  );\n}\n\nexport type OtpFieldInputProps = ComponentProps<typeof OtpPrimitive.Input> & {\n  /** The box's place in the code, from 0: it gives the box its name. */\n  index: number;\n};\n\n/** One box. */\nexport function OtpFieldInput({ className, index, ...props }: OtpFieldInputProps) {\n  const { length, inputLabel } = use(OtpFieldContext);\n  return (\n    <OtpPrimitive.Input\n      data-slot=\"otp-field-input\"\n      aria-label={inputLabel(index + 1, length)}\n      className={cn(\n        \"size-(--control-h) min-w-0 shrink rounded-control border border-input bg-background text-center text-base text-foreground transition-[border-color,opacity] duration-instant ease-out disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive motion-reduce:transition-none\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "A short code sent by message or read from an authenticator. It posts as one value under `name`, and the browser can offer the code it has just received. Label it with `aria-label`, or put it in a field with FieldControl group. For a password use password-field; for any other short text use input.",
    "example": "<OtpField name=\"code\" aria-label=\"Verification code\" onAutoSubmit={verify} autoSubmit />\n<OtpField length={4} validationType=\"alphanumeric\" value={code} onValueChange={setCode} />",
    "client": true
  }
}
