Switch
uiable/switchFreeComponent
Switch component.
Live preview
live · rendered by the registry
Rendered by uiable on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://uiable.com/r/switch.jsonSource
1"use client";23import { Switch as SwitchPrimitive } from "@base-ui/react/switch";45import { cn } from "@/lib/utils";67function Switch({8 className,9 size = "default",10 ...props11}: SwitchPrimitive.Root.Props & {12 size?: "sm" | "default";13}) {14 return (15 <SwitchPrimitive.Root16 data-slot="switch"17 data-size={size}18 className={cn(19 "ring-1 ring-border data-checked:ring-primary data-checked:bg-primary data-unchecked:bg-card focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive/50 dark:aria-invalid:border-destructive/50 dark:data-unchecked:bg-input/80 peer group/switch relative inline-flex shrink-0 items-center rounded-full border-2 border-transparent transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:ring-3 aria-invalid:ring-3 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-[size=default]:h-[18.4px] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6",20 className21 )}22 {...props}23 >24 <SwitchPrimitive.Thumb25 data-slot="switch-thumb"26 className="bg-border data-checked:bg-white dark:data-unchecked:bg-white dark:data-checked:bg-white pointer-events-none block rounded-full ring-0 transition-all group-data-[size=default]/switch:size-3.5 group-data-[size=sm]/switch:size-2.5 group-data-[size=default]/switch:data-checked:translate-x-full group-data-[size=sm]/switch:data-checked:translate-x-full group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0"27 />28 </SwitchPrimitive.Root>29 );30}3132export { Switch };
What it pulls in
npm packages
Files it writes
More from uiable
All 730 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | uiable | Components | Free | 2 deps | |
| Alertalert | uiable | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | uiable | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | uiable | Components | Free | no deps | |
| Attachmentattachment | uiable | Components | Free | 2 deps | |
| Avataravatar | uiable | Components | Free | 1 dep | |
| Badgebadge | uiable | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | uiable | Components | Free | 2 deps |
