{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "otp-input",
  "title": "Otp Input",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/otp-input/OtpInput.tsx",
      "content": "import * as React from 'react'\nimport { Platform, TextInput, View, type TextInputProps, type ViewProps } from 'react-native'\nimport { Text } from '@/components/ui/text'\nimport { cn } from '@/lib/utils'\n\nconst OtpContext = React.createContext<{\n  characters: string[]\n  length: number\n  focused: boolean\n  activeIndex: number\n  invalid: boolean\n} | null>(null)\n\nexport interface OtpInputProps extends Omit<\n  TextInputProps,\n  | 'value'\n  | 'defaultValue'\n  | 'onChangeText'\n  | 'maxLength'\n  | 'multiline'\n  | 'children'\n  | 'style'\n  | 'caretHidden'\n  | 'secureTextEntry'\n  | 'placeholder'\n  | 'placeholderTextColor'\n> {\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  /** Runs once when the accepted value becomes complete, including an initially complete value. */\n  onComplete?: (value: string) => void\n  length?: number\n  disabled?: boolean\n  invalid?: boolean\n  /** Numeric input strips separators from pasted codes. Text input preserves non-whitespace characters. */\n  inputMode?: 'numeric' | 'text'\n  className?: string\n  style?: ViewProps['style']\n  children?: React.ReactNode\n}\n\nexport const OtpInput = React.forwardRef<React.ComponentRef<typeof TextInput>, OtpInputProps>(\n  (\n    {\n      value,\n      defaultValue = '',\n      onValueChange,\n      onComplete,\n      length = 6,\n      disabled = false,\n      invalid = false,\n      inputMode = 'numeric',\n      editable = true,\n      readOnly,\n      className,\n      style,\n      children,\n      onFocus,\n      onBlur,\n      onSelectionChange,\n      autoComplete,\n      autoCapitalize = 'none',\n      autoCorrect = false,\n      spellCheck = false,\n      accessibilityLabel = 'One-time code',\n      accessibilityState,\n      ...props\n    },\n    ref,\n  ) => {\n    if (!Number.isInteger(length) || length < 1) throw new RangeError('OtpInput length must be a positive integer')\n    const normalize = (text: string) =>\n      Array.from(inputMode === 'numeric' ? text.replace(/\\D/g, '') : text.replace(/\\s/g, ''))\n        .slice(0, length)\n        .join('')\n    const [internal, setInternal] = React.useState(() => normalize(defaultValue))\n    const [focused, setFocused] = React.useState(false)\n    const [selection, setSelection] = React.useState(0)\n    const completed = React.useRef<string | undefined>(undefined)\n    const resolved = normalize(value ?? internal)\n    const characters = Array.from(resolved)\n    const canEdit = editable && !disabled && !readOnly\n\n    React.useEffect(() => {\n      if (Array.from(resolved).length !== length) {\n        completed.current = undefined\n      } else if (completed.current !== resolved) {\n        completed.current = resolved\n        onComplete?.(resolved)\n      }\n    }, [resolved, length, onComplete])\n\n    return (\n      <OtpContext.Provider\n        value={{\n          characters,\n          length,\n          focused: focused && canEdit,\n          activeIndex: Math.min(selection, length - 1),\n          invalid,\n        }}\n      >\n        <View\n          className={cn('relative flex-row flex-wrap gap-[8px]', !canEdit && 'opacity-50', className)}\n          style={style}\n        >\n          <View pointerEvents=\"none\" aria-hidden className=\"max-w-full flex-row flex-wrap gap-[8px]\">\n            {children ?? Array.from({ length }, (_, index) => <OtpInputSlot key={index} index={index} />)}\n          </View>\n          <TextInput\n            {...props}\n            ref={ref}\n            value={resolved}\n            editable={canEdit}\n            readOnly={readOnly}\n            inputMode={inputMode}\n            autoComplete={autoComplete ?? (Platform.OS === 'android' ? 'sms-otp' : 'one-time-code')}\n            autoCorrect={autoCorrect}\n            autoCapitalize={autoCapitalize}\n            spellCheck={spellCheck}\n            caretHidden\n            underlineColorAndroid=\"transparent\"\n            multiline={false}\n            accessibilityLabel={accessibilityLabel}\n            accessibilityState={{ ...accessibilityState, disabled: !canEdit }}\n            style={{\n              position: 'absolute',\n              left: 0,\n              top: 0,\n              right: 0,\n              bottom: 0,\n              color: 'transparent',\n              backgroundColor: 'transparent',\n              fontSize: 17,\n            }}\n            onChangeText={(text) => {\n              if (!canEdit) return\n              const next = normalize(text)\n              if (value === undefined) setInternal(next)\n              setSelection(Array.from(next).length)\n              if (next !== resolved) onValueChange?.(next)\n            }}\n            onFocus={(event) => {\n              setFocused(true)\n              onFocus?.(event)\n            }}\n            onBlur={(event) => {\n              setFocused(false)\n              onBlur?.(event)\n            }}\n            onSelectionChange={(event) => {\n              setSelection(Array.from(resolved.slice(0, event.nativeEvent.selection.start)).length)\n              onSelectionChange?.(event)\n            }}\n          />\n        </View>\n      </OtpContext.Provider>\n    )\n  },\n)\nOtpInput.displayName = 'OtpInput'\n\nexport interface OtpInputSlotProps extends ViewProps {\n  index: number\n  className?: string\n  placeholder?: string\n}\n\nexport const OtpInputSlot = React.forwardRef<React.ComponentRef<typeof View>, OtpInputSlotProps>(\n  ({ index, className, placeholder = '', ...props }, ref) => {\n    const otp = React.useContext(OtpContext)\n    if (!otp) throw new Error('OtpInputSlot must be inside OtpInput')\n    if (!Number.isInteger(index) || index < 0 || index >= otp.length)\n      throw new RangeError('OtpInputSlot index must be within the code length')\n    const character = otp.characters[index]\n    return (\n      <View\n        ref={ref}\n        {...props}\n        className={cn(\n          'min-h-[56px] min-w-[48px] items-center justify-center rounded-md border border-input bg-background px-[8px] py-[12px]',\n          otp.focused && otp.activeIndex === index && 'border-ring',\n          otp.invalid && 'border-destructive',\n          className,\n        )}\n      >\n        <Text size=\"xl\" className={cn('text-center font-medium', !character && 'text-muted-foreground')}>\n          {character || placeholder}\n        </Text>\n      </View>\n    )\n  },\n)\nOtpInputSlot.displayName = 'OtpInputSlot'\n\nexport const OtpInputSeparator = React.forwardRef<React.ComponentRef<typeof View>, ViewProps & { className?: string }>(\n  ({ className, ...props }, ref) => (\n    <View ref={ref} {...props} className={cn('min-h-[56px] items-center justify-center', className)}>\n      <Text variant=\"muted\">–</Text>\n    </View>\n  ),\n)\nOtpInputSeparator.displayName = 'OtpInputSeparator'\n",
      "type": "registry:ui",
      "target": "~/components/ui/otp-input/OtpInput.tsx"
    },
    {
      "path": "packages/registry-native/components/otp-input/index.ts",
      "content": "export { OtpInput, OtpInputSlot, OtpInputSeparator } from './OtpInput'\nexport type { OtpInputProps, OtpInputSlotProps } from './OtpInput'\n",
      "type": "registry:ui",
      "target": "~/components/ui/otp-input/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/text.json"
  ],
  "description": "Single native text input for paste/autofill codes with composed display slots and complete-value callbacks.",
  "categories": [
    "control"
  ]
}