input-otp
shadcn-solidjs/input-otpFreeComponent
shadcn-solidjs publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by shadcn-solidjs on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-solidjs.com/r/input-otp.jsonSource
1import type { DynamicProps, InputProps, RootProps } from "@corvu/otp-field";2import OtpField from "@corvu/otp-field";34import { cn } from "~/lib/utils.ts";5import IconMinus from "~icons/lucide/minus";67import type { Component, ComponentProps, ValidComponent } from "solid-js";8import { mergeProps, Show, splitProps } from "solid-js";910export const REGEXP_ONLY_DIGITS = "^\\d*$";11export const REGEXP_ONLY_CHARS = "^[a-zA-Z]*$";12export const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]*$";1314type InputOTPProps<T extends ValidComponent = "div"> = RootProps<T> & {15 class?: string;16};1718const InputOTP = <T extends ValidComponent = "div">(19 props: DynamicProps<T, InputOTPProps<T>>,20) => {21 const [local, others] = splitProps(props as InputOTPProps, ["class"]);22 return (23 <OtpField24 class={cn(25 "gap-2 flex items-center has-disabled:opacity-50",26 local.class,27 )}28 {...others}29 />30 );31};3233type InputOTPInputProps<T extends ValidComponent = "input"> = InputProps<T> & {34 class?: string;35};3637const InputOTPInput = <T extends ValidComponent = "input">(38 rawProps: DynamicProps<T, InputOTPInputProps<T>>,39) => {40 // corvu defaults `pattern` to digits-only; shadcn accepts any character41 // unless a pattern is given, so opt out of the primitive's default.42 const props = mergeProps({ pattern: null }, rawProps as InputOTPInputProps);43 const [local, others] = splitProps(props, ["class"]);44 return (45 <OtpField.Input46 data-slot="input-otp"47 class={cn("disabled:cursor-not-allowed", local.class)}48 {...others}49 />50 );51};5253const InputOTPGroup: Component<ComponentProps<"div">> = (props) => {54 const [local, others] = splitProps(props, ["class"]);55 return (56 <div57 data-slot="input-otp-group"58 class={cn("has-aria-invalid:ring-destructive/20 dark:has-aria-invalid:ring-destructive/40 has-aria-invalid:border-destructive rounded-lg has-aria-invalid:ring-3 flex items-center", local.class)}59 {...others}60 />61 );62};6364const InputOTPSlot: Component<ComponentProps<"div"> & { index: number }> = (65 props,66) => {67 const [local, others] = splitProps(props, ["class", "index"]);68 const context = OtpField.useContext();69 const char = () => context.value()[local.index];70 const isActive = () => context.activeSlots().includes(local.index);71 const showFakeCaret = () =>72 context.value().length === local.index && context.isInserting();7374 return (75 <div76 data-slot="input-otp-slot"77 data-active={isActive()}78// … truncated
What it pulls in
npm packages
More from shadcn-solidjs
All 85 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | shadcn-solidjs | Components | Free | 1 dep | |
| alertalert | shadcn-solidjs | Components | Free | 2 deps | |
| alert-dialogalert-dialog | shadcn-solidjs | Components | Free | 2 deps | |
| aspect-ratioaspect-ratio | shadcn-solidjs | Components | Free | no deps | |
| attachmentattachment | shadcn-solidjs | Components | Free | 2 deps | |
| avataravatar | shadcn-solidjs | Components | Free | 1 dep | |
| badgebadge | shadcn-solidjs | Components | Free | 2 deps | |
| breadcrumbbreadcrumb | shadcn-solidjs | Components | Free | 1 dep |
