{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pin-input",
  "title": "Pin Input",
  "description": "A shadcn-style pin input component built with Ark UI primitives.",
  "dependencies": ["@ark-ui/react"],
  "registryDependencies": ["button-group"],
  "files": [
    {
      "path": "src/components/ui/pin-input.tsx",
      "content": "\"use client\";\n\nimport { ark } from \"@ark-ui/react/factory\";\nimport {\n  PinInput as PinInputPrimitive,\n  usePinInput,\n  usePinInputContext,\n} from \"@ark-ui/react/pin-input\";\nimport { type ComponentProps, Fragment } from \"react\";\nimport {\n  ButtonGroup,\n  ButtonGroupSeparator,\n} from \"@/components/ui/button-group\";\nimport { cn } from \"@/lib/utils\";\n\nexport { usePinInput, usePinInputContext };\n\nexport const PinInputRoot = ({\n  className,\n  count = 6,\n  children,\n  ...props\n}: PinInputPrimitive.RootProps) => (\n  <PinInputPrimitive.Root\n    className={cn(\"group/pin-input flex w-full flex-col gap-1.5\", className)}\n    count={count}\n    data-slot=\"pin-input\"\n    {...props}\n  >\n    {children}\n    <PinInputPrimitive.HiddenInput />\n  </PinInputPrimitive.Root>\n);\n\nexport type PinInputLabelComponentProps = PinInputPrimitive.LabelProps;\n\nexport const PinInputLabel = ({\n  className,\n  ...props\n}: PinInputLabelComponentProps) => (\n  <PinInputPrimitive.Label\n    className={cn(\n      \"text-sm font-medium text-foreground leading-none select-none\",\n      \"group-data-disabled/pin-input:pointer-events-none group-data-disabled/pin-input:opacity-64\",\n      \"group-data-invalid/pin-input:text-destructive\",\n      \"group-data-readonly/pin-input:text-muted-foreground\",\n      className,\n    )}\n    data-slot=\"pin-input-label\"\n    {...props}\n  />\n);\n\nexport const PinInputControl = ({\n  ...props\n}: PinInputPrimitive.ControlProps) => <PinInputPrimitive.Control {...props} />;\n\n/** Shared focus / invalid / disabled / read-only (Ark sets data-* and aria-invalid on each cell). */\nconst pinInputStatesClassName = cn(\n  \"outline-none ring-ring/24 transition-[border-color,box-shadow,color,opacity]\",\n  \"focus-visible:z-1 focus-visible:border-ring focus-visible:ring-3\",\n  \"aria-invalid:border-destructive/36 aria-invalid:focus-visible:border-destructive aria-invalid:focus-visible:ring-3 aria-invalid:focus-visible:ring-destructive/20\",\n  \"data-invalid:border-destructive/36 data-invalid:focus-visible:border-destructive data-invalid:focus-visible:ring-3 data-invalid:focus-visible:ring-destructive/20\",\n  \"dark:aria-invalid:border-destructive/50 dark:aria-invalid:focus-visible:ring-destructive/40\",\n  \"dark:data-invalid:border-destructive/50 dark:data-invalid:focus-visible:ring-destructive/40\",\n  \"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-64 disabled:focus-visible:ring-0 disabled:focus-visible:ring-offset-0\",\n  \"data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:opacity-64 data-disabled:focus-visible:ring-0 data-disabled:focus-visible:ring-offset-0\",\n  \"read-only:cursor-default read-only:bg-muted/40 read-only:text-muted-foreground dark:read-only:bg-muted/25\",\n);\n\nexport const PinInput = ({\n  className,\n  ...props\n}: PinInputPrimitive.InputProps) => (\n  <PinInputPrimitive.Input\n    className={cn(pinInputStatesClassName, className)}\n    data-slot=\"pin-slot\"\n    {...props}\n  />\n);\n\nexport type PinInputRootProviderComponentProps =\n  PinInputPrimitive.RootProviderProps;\n\nexport const PinInputRootProvider = (\n  props: PinInputRootProviderComponentProps,\n) => (\n  <PinInputPrimitive.RootProvider\n    data-slot=\"pin-input-root-provider\"\n    {...props}\n  >\n    {props.children}\n    <PinInputPrimitive.HiddenInput />\n  </PinInputPrimitive.RootProvider>\n);\n\nexport type PinInputContextComponentProps = PinInputPrimitive.ContextProps;\n\nexport const PinInputContext = (props: PinInputContextComponentProps) => (\n  <PinInputPrimitive.Context {...props} />\n);\n\nexport type PinInputSeparatorProps = ComponentProps<typeof ark.span>;\n\nexport const PinInputSeparator = ({\n  className,\n  children,\n  ...props\n}: PinInputSeparatorProps) => (\n  <ark.span\n    aria-hidden\n    className={cn(\n      \"select-none px-0.5 text-center font-medium text-muted-foreground text-sm\",\n      className,\n    )}\n    data-slot=\"pin-input-separator\"\n    {...props}\n  >\n    {children ?? \"-\"}\n  </ark.span>\n);\n\n/**\n * Pin cells on the native input (not `Input` + asChild): `Input`’s wrapper is\n * `inline-flex w-full`, which inside `ButtonGroup` (`w-fit`) collapses intrinsic width.\n */\nconst pinCellClass = (variant: \"grouped\" | \"separated\") =>\n  cn(\n    \"box-border h-8 w-8 min-h-8 min-w-8 max-h-8 max-w-8 shrink-0 grow-0 basis-8 px-0 text-center tabular-nums text-sm font-medium leading-8 text-foreground\",\n    \"placeholder:text-muted-foreground/72\",\n    variant === \"separated\" &&\n      \"rounded-lg border border-input bg-background shadow-xs/5 not-dark:bg-clip-padding dark:bg-input/32\",\n    variant === \"grouped\" &&\n      \"rounded-lg border border-input bg-background not-dark:bg-clip-padding dark:bg-input/32\",\n  );\n\nexport const PinInputSlots = ({\n  variant = \"separated\",\n  separatorBetweenCount,\n}: {\n  variant: \"grouped\" | \"separated\";\n  separatorBetweenCount?: number;\n}) => {\n  const { count } = usePinInputContext();\n\n  const separatorCount = separatorBetweenCount\n    ? Math.floor(count / separatorBetweenCount)\n    : count;\n\n  const cell = (index: number) => (\n    <PinInput className={pinCellClass(variant)} index={index} key={index} />\n  );\n\n  if (variant === \"grouped\") {\n    if (separatorBetweenCount && separatorBetweenCount > 0) {\n      return (\n        <PinInputControl className=\"flex w-max max-w-full flex-wrap items-center gap-2\">\n          {Array.from({ length: separatorCount }, (_, i) => (\n            <Fragment key={`g-${i}`}>\n              {i > 0 ? <PinInputSeparator /> : null}\n              <ButtonGroup>\n                {Array.from({ length: separatorBetweenCount }, (_, j) => {\n                  const idx = j + i * separatorBetweenCount;\n                  return (\n                    <Fragment key={idx}>\n                      {j > 0 ? <ButtonGroupSeparator /> : null}\n                      {cell(idx)}\n                    </Fragment>\n                  );\n                })}\n              </ButtonGroup>\n            </Fragment>\n          ))}\n        </PinInputControl>\n      );\n    }\n\n    return (\n      <PinInputControl asChild>\n        <ButtonGroup>\n          {Array.from({ length: count }, (_, i) => (\n            <Fragment key={i}>\n              {i > 0 ? <ButtonGroupSeparator /> : null}\n              {cell(i)}\n            </Fragment>\n          ))}\n        </ButtonGroup>\n      </PinInputControl>\n    );\n  }\n\n  return (\n    <PinInputControl className=\"flex w-max max-w-full flex-wrap items-center gap-2\">\n      {separatorBetweenCount && separatorBetweenCount > 0\n        ? Array.from({ length: separatorCount }, (_, i) => (\n            <Fragment key={`s-${i}`}>\n              {i > 0 ? <PinInputSeparator /> : null}\n              {Array.from({ length: separatorBetweenCount }, (_, j) =>\n                cell(j + i * separatorBetweenCount),\n              )}\n            </Fragment>\n          ))\n        : Array.from({ length: separatorCount }, (_, i) => cell(i))}\n    </PinInputControl>\n  );\n};\n",
      "type": "registry:ui",
      "target": "src/components/ui/pin-input.tsx"
    }
  ],
  "type": "registry:ui"
}
