Switch
docs/switchFreeComponent
switch component for SolidJS
Live preview
live · rendered by the registry
Rendered by docs on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://solidcn.dev/r/switch.jsonSource
1import { Switch as KobalteSwitch } from "@kobalte/core/switch";2import type { Component, ComponentProps } from "solid-js";3import { splitProps } from "solid-js";4import { cn } from "~/lib/utils";56export type SwitchProps = ComponentProps<typeof KobalteSwitch> & {7 label?: string;8 class?: string;9};1011export const Switch: Component<SwitchProps> = (props) => {12 const [local, rest] = splitProps(props, ["class", "label"]);1314 return (15 <KobalteSwitch class={cn("flex items-center gap-2", local.class)} {...rest}>16 <KobalteSwitch.Input class="sr-only" />17 <KobalteSwitch.Control18 class={cn(19 "inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent",20 "transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",21 "disabled:cursor-not-allowed disabled:opacity-50",22 "bg-input data-[checked]:bg-primary",23 )}24 >25 <KobalteSwitch.Thumb26 class={cn(27 "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform",28 "translate-x-0 data-[checked]:translate-x-5",29 )}30 />31 </KobalteSwitch.Control>32 {local.label && (33 <KobalteSwitch.Label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">34 {local.label}35 </KobalteSwitch.Label>36 )}37 </KobalteSwitch>38 );39};
More from docs
All 44 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | docs | Components | Free | no deps | |
| Alert Dialogalert-dialog | docs | Components | Free | no deps | |
| Avataravatar | docs | Components | Free | no deps | |
| Badgebadge | docs | Components | Free | no deps | |
| Breadcrumbbreadcrumb | docs | Components | Free | no deps | |
| Buttonbutton | docs | Components | Free | no deps | |
| Calendarcalendar | docs | Components | Free | no deps | |
| Cardcard | docs | Components | Free | no deps |
