| 1 | "use client"; |
| 2 | |
| 3 | import * as React from "react"; |
| 4 | import { cn } |
| 5 | import { OTPInput, OTPInputContext |
| 6 | import { MinusIcon } |
| 7 | |
| 8 | function InputOTP({ |
| 9 | className, |
| 10 | containerClassName, |
| 11 | ...props |
| 12 | }: React. |
| 13 | containerClassName?: string |
| 14 | }) { |
| 15 | return ( |
| 16 | <OTPInput |
| 17 | data-slot="input-otp" |
| 18 | containerClassName={cn( |
| 19 | "cn-input-otp flex items-center has-disabled:opacity-50", |
| 20 | containerClassName, |
| 21 | )} |
| 22 | spellCheck={false} |
| 23 | className={cn(" |
| 24 | {...props} |
| 25 | /> |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | function InputOTPGroup({ className |
| 30 | return ( |
| 31 | <div |
| 32 | data-slot="input-otp-group" |
| 33 | className={cn( |
| 34 | "flex items-center rounded-lg has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20 dark:has-aria-invalid:ring-destructive/40", |
| 35 | className, |
| 36 | )} |
| 37 | {...props} |
| 38 | /> |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | function InputOTPSlot({ |
| 43 | index, |
| 44 | className, |
| 45 | ...props |
| 46 | }: React. |
| 47 | index: number |
| 48 | }) { |
| 49 | const inputOTPContext = |
| 50 | const { char, |
| 51 | |
| 52 | return ( |
| 53 | <div |
| 54 | data-slot="input-otp-slot" |
| 55 | data-active={isActive} |
| 56 | className={cn( |
| 57 | "relative flex size-8 items-center justify-center border-y border-r border-input text-sm transition-all outline-none first:rounded-l-lg first:border-l last:rounded-r-lg aria-invalid:border-destructive data-[active=true]:z-10 data-[active=true]:border-ring data-[active=true]:ring-3 data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:border-destructive data-[active=true]:aria-invalid:ring-destructive/20 dark:bg-input/30 dark:data-[active=true]:aria-invalid:ring-destructive/40", |
| 58 | className, |
| 59 | )} |
| 60 | {...props} |
| 61 | > |
| 62 | {char} |
| 63 | {hasFakeCaret && ( |
| 64 | <div className="pointer-events-none absolute inset-0 flex items-center justify-center |
| 65 | <div className="h-4 w-px animate-caret-blink bg-foreground duration-1000 |
| 66 | </div> |
| 67 | )} |
| 68 | </div> |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | function InputOTPSeparator({ ... |
| 73 | return ( |
| 74 | <div |
| 75 | data-slot="input-otp-separator" |
| 76 | className="flex items-center [&_svg:not([class*='size-'])]:size-4" |
| 77 | role="separator" |
| 78 | {...props} |
| 79 | > |
| 80 | <MinusIcon /> |
| 81 | </div> |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | export { InputOTP, InputOTPGroup |