The Coline design system: accessible React components for Coline Apps, themed live by the host workspace, and for Coline Sites in light and dark. Tailwind v4 stylesheet included. MIT.
| 5 |
| 6 | import { cn } from "../lib/utils" |
| 7 |
| 8 | function Switch({ |
| 9 | className, |
| 10 | size = "default", |
| 11 | ...props |
| 12 | }: React.ComponentProps<typeof SwitchPrimitive.Root> & { |
| 13 | size?: "sm" | "default" |
| 14 | }) { |
| 15 | return ( |
| 16 | <SwitchPrimitive.Root |
| 17 | data-slot="switch" |
| 18 | data-size={size} |
| 19 | className={cn( |
| 20 | "peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring aria-invalid:border-destructive aria-invalid:ring-[3px] aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-[state=checked]:bg-primary data-[state=unchecked]:bg-muted-foreground/30 data-disabled:cursor-not-allowed data-disabled:opacity-50", |
| 21 | className |
| 22 | )} |
| 23 | {...props} |
| 24 | > |
| 25 | <SwitchPrimitive.Thumb |
| 26 | data-slot="switch-thumb" |
| 27 | className="pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-[state=checked]:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-[state=checked]:translate-x-[calc(100%-2px)] dark:data-[state=checked]:bg-primary-foreground group-data-[size=default]/switch:data-[state=unchecked]:translate-x-0 group-data-[size=sm]/switch:data-[state=unchecked]:translate-x-0 dark:data-[state=unchecked]:bg-foreground" |
| 28 | /> |
| 29 | </SwitchPrimitive.Root> |
| 30 | ) |
| 31 | } |
| 32 |
| 33 | export { Switch } |
| 34 |