{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "otp-input",
  "title": "OTP input",
  "description": "One cut cell per character of a code, with a blinking caret in the active one.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/otp-input.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Field, FieldDescription, FieldError, FieldLabel } from \"@ui-sdk/react/field\"\nimport { OTPInput as SdkOTPInput, OTPInputGroup, OTPInputSeparator, OTPInputSlot } from \"@ui-sdk/react/otp-input\"\nimport { burst } from \"@/registry/cyber/lib/glitch\"\nimport \"@/registry/cyber/ui/cyber/otp-input.css\"\n\n// A short code, one cut cell per character. It's a single input underneath,\n// so a pasted or autofilled code fills every cell at once and a screen\n// reader hears one field. The cell typing goes to carries a caret, filled\n// cells read in the signal color, and a readout beside the label counts\n// them in. The moment the last cell fills, the code slips its channels once.\n//\n// - `length` is how many characters; `groupSize` is how many sit together\n//   before a separator (threes, or halves of an even code, by default).\n// - `pattern`: \"digits\" (the default), \"letters\", \"alphanumeric\" or a\n//   regular expression. Letters show in capitals; the value keeps the case\n//   that was typed.\n// - `hint` describes the field; `error` marks it invalid with a message.\n//\n// Everything else goes to the SDK root: `value`, `onValueChange`,\n// `onValueCommit` (runs when the code is complete), `name`, a `controller`.\nfunction OtpInput({\n  label,\n  length = 6,\n  groupSize = length % 3 === 0 ? 3 : length % 2 === 0 && length > 4 ? length / 2 : length,\n  hint,\n  error,\n  disabled,\n  value,\n  defaultValue,\n  onValueChange,\n  onValueCommit,\n  ref,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkOTPInput>, \"children\" | \"maxLength\"> & {\n  label: string\n  length?: number\n  groupSize?: number\n  hint?: React.ReactNode\n  error?: string\n}) {\n  // The readout sits in the label's row, outside the SDK root (which is\n  // only the cells and the input laid over them), so the count is kept from\n  // the change callback: typing, a paste, a reset and an agent all pass it.\n  const [typed, setTyped] = React.useState(() => (defaultValue ?? \"\").length)\n  const filled = Math.min(length, value != null ? value.length : typed)\n  const digits = Math.max(2, String(length).length)\n  const root = React.useRef<HTMLDivElement | null>(null)\n\n  const groups: number[][] = []\n  for (let index = 0; index < length; index += groupSize) {\n    groups.push(Array.from({ length: Math.min(groupSize, length - index) }, (_, offset) => index + offset))\n  }\n\n  return (\n    <Field data-kit=\"field\" disabled={disabled} invalid={error ? true : undefined}>\n      <div data-kit=\"otp-input-head\">\n        <FieldLabel data-kit=\"label\">{label}</FieldLabel>\n        <span data-kit=\"otp-input-count\" aria-hidden>\n          {String(filled).padStart(digits, \"0\")}/{String(length).padStart(digits, \"0\")}\n        </span>\n      </div>\n      <SdkOTPInput\n        ref={(node) => {\n          root.current = node\n          if (typeof ref === \"function\") return ref(node)\n          if (ref) ref.current = node\n        }}\n        data-kit=\"otp-input\"\n        maxLength={length}\n        value={value}\n        defaultValue={defaultValue}\n        onValueChange={(next, details) => {\n          onValueChange?.(next, details)\n          if (!details.canceled) setTyped(next.length)\n        }}\n        onValueCommit={(code, details) => {\n          onValueCommit?.(code, details)\n          if (root.current) burst(root.current, 320)\n        }}\n        {...props}\n      >\n        {groups.map((group, at) => (\n          <React.Fragment key={group[0]}>\n            {at > 0 && <OTPInputSeparator data-kit=\"otp-input-separator\" />}\n            <OTPInputGroup data-kit=\"otp-input-group\">\n              {group.map((index) => (\n                <OTPInputSlot key={index} index={index} data-kit=\"otp-input-slot\" data-frame=\"br\" />\n              ))}\n            </OTPInputGroup>\n          </React.Fragment>\n        ))}\n      </SdkOTPInput>\n      {hint && <FieldDescription data-kit=\"hint\">{hint}</FieldDescription>}\n      {error ? (\n        <FieldError data-kit=\"field-error\" match>\n          {error}\n        </FieldError>\n      ) : (\n        <FieldError data-kit=\"field-error\" />\n      )}\n    </Field>\n  )\n}\n\nexport { OtpInput }\n",
      "type": "registry:ui",
      "target": "@ui/otp-input.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/otp-input.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n/* An OTP input is a row of cut cells with one invisible input laid over\n   them. The input takes focus but draws nothing, so the cell typing goes to\n   stands in for the focus ring: it takes the ring's own look, a doubled\n   edge in the signal color. */\n@layer cyber.ui {\n  [data-skin=\"cyber\"] [data-kit=\"otp-input-head\"] {\n    display: flex;\n    align-items: baseline;\n    justify-content: space-between;\n    gap: 12px;\n    min-width: 0;\n\n    & [data-kit=\"label\"][data-disabled] {\n      color: var(--cy-ink-mute);\n    }\n  }\n\n  /* Cells filled, of how many. A value, so it's the signal color; it steps\n     as the code goes in. */\n  [data-skin=\"cyber\"] [data-kit=\"otp-input-count\"] {\n    flex: none;\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-xs);\n    line-height: 1;\n    font-variant-numeric: tabular-nums;\n    color: var(--cy-signal);\n\n    [data-kit=\"otp-input-head\"]:has([data-disabled]) > & {\n      color: var(--cy-ink-mute);\n    }\n  }\n\n  /* The SDK's root: as wide as its cells, so the input over it is too. */\n  [data-skin=\"cyber\"] [data-kit=\"otp-input\"] {\n    display: flex;\n    align-items: center;\n    gap: 6px;\n    width: fit-content;\n    max-width: 100%;\n    min-width: 0;\n    cursor: text;\n\n    &[data-disabled] {\n      cursor: not-allowed;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"otp-input-group\"] {\n    display: flex;\n    gap: 4px;\n    min-width: 0;\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"otp-input-slot\"] {\n    --frame-cut: 5px;\n    --frame-line: var(--cy-line-ctl);\n    --frame-fill: var(--cy-panel);\n\n    flex: 0 1 38px;\n    display: grid;\n    place-items: center;\n    width: 38px;\n    min-width: 22px;\n    height: var(--cy-h-lg);\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-lg);\n    font-weight: 500;\n    line-height: 1;\n    text-transform: uppercase;\n    color: var(--cy-signal);\n    transition:\n      background-color var(--cy-t-fast) linear,\n      border-color var(--cy-t-fast) linear;\n\n    /* The input over the cells is what the pointer is on, so hover is read\n       from the root. */\n    @media (hover: hover) {\n      [data-kit=\"otp-input\"]:hover:not([data-disabled]) & {\n        --frame-line: var(--cy-line-hot);\n      }\n    }\n\n    /* Where typing goes. Empty, it holds the caret; filled, the character\n       there is the one the next key replaces, so it's lit like a selection. */\n    &[data-active] {\n      --frame-line: var(--cy-signal);\n      --frame-fill: var(--cy-fill-hover);\n      box-shadow: inset 0 0 0 1px var(--cy-signal);\n\n      &[data-filled] {\n        --frame-fill: var(--cy-signal-fill);\n      }\n    }\n\n    /* The caret is a border, not a fill, so it survives forced colors. */\n    &[data-fake-caret]::after {\n      content: \"\";\n      height: 18px;\n      border-inline-start: 2px solid var(--cy-signal);\n      animation: var(--cy-fx-blink) 1.1s linear infinite;\n    }\n\n    /* Forced colors drop the doubled edge, so the cell typing goes to gets\n       a real outline there. */\n    @media (forced-colors: active) {\n      &[data-active] {\n        outline: 2px solid Highlight;\n        outline-offset: -2px;\n      }\n    }\n\n    /* Invalid: the flag edge on every cell. The message under the field\n       carries the mark and the words. */\n    [data-kit=\"otp-input\"]:has([aria-invalid=\"true\"]) &:not([data-active], [data-disabled]) {\n      --frame-line: var(--cy-flag);\n    }\n\n    &[data-disabled] {\n      --frame-line: var(--cy-line-deco);\n      --frame-image: repeating-linear-gradient(135deg, transparent 0 5px, var(--cy-line-deco) 5px 6px);\n      color: var(--cy-ink-mute);\n    }\n  }\n\n  /* The last cell filling: the whole code slips its channels, once. The\n     component marks the root for the length of it (lib/glitch.ts). */\n  [data-skin=\"cyber\"] [data-kit=\"otp-input\"][data-glitching] [data-kit=\"otp-input-group\"] {\n    animation: var(--cy-fx-rgb) 320ms var(--cy-ease-snap);\n  }\n\n  /* A dash between groups. It's drawn, not typed. */\n  [data-skin=\"cyber\"] [data-kit=\"otp-input-separator\"] {\n    flex: none;\n    width: 8px;\n    border-block-start: 2px solid var(--cy-line-ctl);\n\n    &[data-disabled] {\n      border-color: var(--cy-line-deco);\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/otp-input.css"
    }
  ],
  "type": "registry:ui"
}
