{
  "$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 a row of boxes, one character each: the \"enter the 6-digit code we emailed you\" field. Built on Base UI's OTPField, which owns the hard parts: paste of the whole code into any box, the phone's \"from Messages\" autofill…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "form",
    "primitive"
  ],
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/otp-field.tsx",
      "target": "components/ui/otp-field.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/otp-field v1.1.2 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/otp-field\n// What changed since: https://ds.interlace.tools/c/otp-field#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — OtpField\n *\n * A one-time code typed into a row of boxes, one character each: the \"enter\n * the 6-digit code we emailed you\" field. Built on Base UI's OTPField, which\n * owns the hard parts: paste of the whole code into any box, the phone's\n * \"from Messages\" autofill (`autocomplete=\"one-time-code\"` on the first box),\n * arrow and backspace movement, and a hidden input that carries the value\n * into a form under `name`.\n *\n * ## Anatomy\n *\n *   OtpField                         (div — data-slot=\"otp-field\", data-complete, data-filled)\n *     ├─ OTPField.Input × length     (data-slot=\"otp-field-slot\", data-filled)\n *     └─ OTPField.Separator          (data-slot=\"otp-field-separator\" — between groups, when `groupSize` is set)\n *\n * ## Groups\n *\n * `groupSize={3}` splits a six-digit code into 3 + 3 with a short dash\n * between, which is how people read a code aloud. The dash is decorative.\n *\n * ## States\n *\n * A filled box gets a stronger border; the focused one the focus ring. When\n * `invalid` is set every box turns to the destructive border and carries\n * `aria-invalid`, so pair it with an error message the field is described\n * by. When the last box fills, `onValueComplete` fires; `autoSubmit`\n * submits the owning form instead.\n *\n * ## MIN_VIEWPORT — 320\n *\n * Six 2.75rem boxes with 0.5rem gaps are 19rem: they fit a 320px screen with\n * its gutters. Eight boxes or more should use `size=\"sm\"`.\n *\n * | Rule | Concept                 | Where in this file                                          |\n * | ---- | ----------------------- | ----------------------------------------------------------- |\n * | R4   | Extends the Base UI root | `OTPField.Root.Props` minus `children`                     |\n * | R6   | data-slot per part      | otp-field / -slot / -separator                              |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                           |\n * | R8   | Enums, not booleans     | `size` is `sm \\| default`                                   |\n * | R12  | Reuse over wrap         | Base UI owns paste, autofill, focus movement, hidden input  |\n * | R14  | Declares min viewport   | `data-min-viewport` + exported const                        |\n * | R18  | Tailwind only           | no inline style                                             |\n * | R19  | Tokens only             | `border-input`, `ring-ring`, `border-destructive`           |\n * | R25  | Client component        | Base UI state machine                                       |\n * | R26  | A11y                    | first box takes the field's label; the rest are \"Character n of N\" |\n */\n\nimport { OTPField } from '@base-ui/react/otp-field';\n\nimport { cn } from '@/lib/utils';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ntype OtpFieldProps = Omit<\n  React.ComponentProps<typeof OTPField.Root>,\n  'children' | 'length' | 'className'\n> & {\n  className?: string;\n  /** Number of boxes. @default 6 */\n  length?: number;\n  /** Put a dash after every `groupSize` boxes, such as 3 for \"123–456\". */\n  groupSize?: number;\n  /** @default 'default' */\n  size?: 'sm' | 'default';\n  /** Shows every box as invalid and sets `aria-invalid`. */\n  invalid?: boolean;\n  /** Accessible name of boxes 2…n. @default (n, total) => `Character ${n} of ${total}` */\n  slotLabel?: (n: number, total: number) => string;\n};\n\nconst SLOT =\n  'border-input bg-background text-foreground rounded-lg border text-center font-medium tabular-nums shadow-xs focus-visible:outline-hidden ' +\n  'transition-[border-color,box-shadow,transform] duration-(--duration-fast) ' +\n  'data-filled:border-foreground/40 motion-safe:data-filled:scale-[1.04] ' +\n  'focus-visible:border-ring focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:scale-100 ' +\n  'aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 ' +\n  'disabled:cursor-not-allowed disabled:opacity-50';\n\nconst SIZE = {\n  sm: 'h-10 w-9 min-w-0 shrink text-base',\n  default: 'h-12 w-11 min-w-0 shrink text-xl',\n} as const;\n\nfunction OtpField({\n  className,\n  length = 6,\n  groupSize,\n  size = 'default',\n  invalid = false,\n  slotLabel = (n, total) => `Character ${n} of ${total}`,\n  ...props\n}: OtpFieldProps) {\n  const slots: React.ReactNode[] = [];\n  for (let i = 0; i < length; i++) {\n    if (groupSize && i > 0 && i % groupSize === 0) {\n      slots.push(\n        <OTPField.Separator\n          key={`sep-${i}`}\n          data-slot=\"otp-field-separator\"\n          className=\"bg-muted-foreground/60 mx-1 h-0.5 w-3 shrink-0 rounded-full\"\n        />,\n      );\n    }\n    slots.push(\n      <OTPField.Input\n        key={i}\n        data-slot=\"otp-field-slot\"\n        aria-label={i === 0 ? undefined : slotLabel(i + 1, length)}\n        aria-invalid={invalid || undefined}\n        className={cn(SLOT, SIZE[size])}\n      />,\n    );\n  }\n\n  return (\n    <OTPField.Root\n      length={length}\n      data-slot=\"otp-field\"\n      data-size={size}\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('flex max-w-full items-center gap-2', className)}\n      {...props}\n    >\n      {slots}\n    </OTPField.Root>\n  );\n}\n\nexport { OtpField };\nexport type { OtpFieldProps };\n"
    }
  ],
  "meta": {
    "tier": "primitive",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.1.2",
    "since": "2.0.0"
  },
  "docs": "## @interlace/otp-field\n\nInstalled to `components/ui/otp-field.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/otp-field';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/otp-field\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
