The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { Switch as SwitchPrimitive } from "@base-ui/react/switch"; |
| 2 | |
| 3 | import { cn } from "~/lib/utils"; |
| 4 | |
| 5 | function Switch({ |
| 6 | className, |
| 7 | size = "default", |
| 8 | mixed = false, |
| 9 | ...props |
| 10 | }: SwitchPrimitive.Root.Props & { size?: "default" | "sm"; mixed?: boolean }) { |
| 11 | return ( |
| 12 | <SwitchPrimitive.Root |
| 13 | className={cn( |
| 14 | "inline-flex h-[calc(var(--thumb-size)+2px)] w-[calc(var(--thumb-size)*2-2px)] shrink-0 cursor-pointer items-center rounded-full p-[2px] outline-none transition-[background-color,box-shadow] duration-200 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background data-checked:bg-primary data-unchecked:bg-input data-disabled:cursor-not-allowed data-disabled:opacity-64 data-[mixed]:bg-input", |
| 15 | size === "sm" |
| 16 | ? "[--thumb-size:--spacing(4)] sm:[--thumb-size:--spacing(3.5)]" |
| 17 | : "[--thumb-size:--spacing(5)] sm:[--thumb-size:--spacing(4)]", |
| 18 | className, |
| 19 | )} |
| 20 | data-size={size} |
| 21 | data-slot="switch" |
| 22 | data-mixed={mixed ? "" : undefined} |
| 23 | // Base UI overwrites aria-checked even with undefined; pass it only for mixed state. |
| 24 | {...(mixed ? { "aria-checked": "mixed" as const } : {})} |
| 25 | {...props} |
| 26 | > |
| 27 | <SwitchPrimitive.Thumb |
| 28 | className={cn( |
| 29 | "pointer-events-none block size-[calc(var(--thumb-size)-2px)] shrink-0 origin-left in-[[role=switch]:active,[data-slot=label]:active,[data-slot=field-label]:active]:not-data-disabled:scale-x-110 in-[[role=switch]:active,[data-slot=label]:active,[data-slot=field-label]:active]:rounded-[var(--thumb-size)/calc(var(--thumb-size)*1.1)] rounded-(--thumb-size) bg-background shadow-sm/5 dark:data-unchecked:bg-muted-foreground [transition:translate_.15s,border-radius_.15s,scale_.1s_.1s,transform-origin_.15s] data-checked:origin-right data-checked:translate-x-[calc(var(--thumb-size)-4px)]", |
| 30 | mixed && |
| 31 | "translate-x-[calc((var(--thumb-size)-4px)/2)] opacity-70 data-checked:translate-x-[calc((var(--thumb-size)-4px)/2)]", |
| 32 | )} |
| 33 | data-slot="switch-thumb" |
| 34 | /> |
| 35 | </SwitchPrimitive.Root> |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | export { Switch }; |