AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

input-otp.tsx 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { OTPInput, OTPInputContext } from "input-otp"
  2. import { Minus } from "lucide-react"
  3. import * as React from "react"
  4. import { cn } from "@/lib/utils"
  5. const InputOTP = React.forwardRef<
  6. React.ElementRef<typeof OTPInput>,
  7. React.ComponentPropsWithoutRef<typeof OTPInput>
  8. >(({ className, containerClassName, ...props }, ref) => (
  9. <OTPInput
  10. ref={ref}
  11. containerClassName={cn(
  12. "flex items-center gap-2 has-[:disabled]:opacity-50",
  13. containerClassName
  14. )}
  15. className={cn("disabled:cursor-not-allowed", className)}
  16. {...props}
  17. />
  18. ))
  19. InputOTP.displayName = "InputOTP"
  20. const InputOTPGroup = React.forwardRef<
  21. React.ElementRef<"div">,
  22. React.ComponentPropsWithoutRef<"div">
  23. >(({ className, ...props }, ref) => (
  24. <div ref={ref} className={cn("flex items-center", className)} {...props} />
  25. ))
  26. InputOTPGroup.displayName = "InputOTPGroup"
  27. const InputOTPSlot = React.forwardRef<
  28. React.ElementRef<"div">,
  29. React.ComponentPropsWithoutRef<"div"> & { index: number }
  30. >(({ index, className, ...props }, ref) => {
  31. const inputOTPContext = React.useContext(OTPInputContext)
  32. const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index]
  33. return (
  34. <div
  35. ref={ref}
  36. className={cn(
  37. "relative flex h-9 w-9 items-center justify-center border-y border-r border-input text-sm shadow-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md",
  38. isActive && "z-10 ring-1 ring-ring",
  39. className
  40. )}
  41. {...props}
  42. >
  43. {char}
  44. {hasFakeCaret && (
  45. <div className="pointer-events-none absolute inset-0 flex items-center justify-center">
  46. <div className="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
  47. </div>
  48. )}
  49. </div>
  50. )
  51. })
  52. InputOTPSlot.displayName = "InputOTPSlot"
  53. const InputOTPSeparator = React.forwardRef<
  54. React.ElementRef<"div">,
  55. React.ComponentPropsWithoutRef<"div">
  56. >(({ ...props }, ref) => (
  57. <div ref={ref} role="separator" {...props}>
  58. <Minus />
  59. </div>
  60. ))
  61. InputOTPSeparator.displayName = "InputOTPSeparator"
  62. export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator }