import * as React from "react" import { View, Input, type BaseEventOrig } from "@tarojs/components" import { type InputProps } from "@tarojs/components/types/Input" import { Dot } from "lucide-react-taro" import { cn } from "@/lib/utils" const InputOTPContext = React.createContext<{ value: string maxLength: number isFocused: boolean } | null>(null) const InputOTP = React.forwardRef< any, { value?: string defaultValue?: string onChange?: (value: string) => void maxLength: number containerClassName?: string className?: string disabled?: boolean autoFocus?: boolean children: React.ReactNode } >(({ value: valueProp, defaultValue, onChange, maxLength, containerClassName, className, disabled, autoFocus, children }, ref) => { const [valueState, setValueState] = React.useState(defaultValue || "") const [isFocused, setIsFocused] = React.useState(false) const value = valueProp !== undefined ? valueProp : valueState const handleChange = (e: BaseEventOrig) => { const newValue = e.detail.value if (newValue.length <= maxLength) { if (valueProp === undefined) { setValueState(newValue) } onChange?.(newValue) } } return ( setIsFocused(true)} onBlur={() => setIsFocused(false)} maxlength={maxLength} type="number" disabled={disabled} focus={autoFocus} ref={ref} /> {children} ) }) InputOTP.displayName = "InputOTP" const InputOTPGroup = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) InputOTPGroup.displayName = "InputOTPGroup" const InputOTPSlot = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { index: number } >(({ index, className, ...props }, ref) => { const context = React.useContext(InputOTPContext) if (!context) return null const char = context.value[index] const isActive = context.isFocused && context.value.length === index const hasFakeCaret = isActive return ( {char} {hasFakeCaret && ( )} ) }) InputOTPSlot.displayName = "InputOTPSlot" const InputOTPSeparator = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ ...props }, ref) => ( )) InputOTPSeparator.displayName = "InputOTPSeparator" export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator }