File size: 1,030 Bytes
b5b9c2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { cn } from "@/lib/utils";

export function Switch({
  checked,
  onCheckedChange,
  className,
  disabled,
}: {
  checked: boolean;
  onCheckedChange: (v: boolean) => void;
  className?: string;
  disabled?: boolean;
}) {
  return (
    <button
      type="button"
      role="switch"
      aria-checked={checked}
      disabled={disabled}
      className={cn(
        "peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center border border-border transition-colors",
        "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/30",
        "disabled:cursor-not-allowed disabled:opacity-50",
        checked ? "bg-foreground/15 border-foreground/30" : "bg-background",
        className,
      )}
      onClick={() => onCheckedChange(!checked)}
    >
      <span
        className={cn(
          "pointer-events-none block h-3.5 w-3.5 transition-transform",
          checked ? "translate-x-4 bg-foreground" : "translate-x-0.5 bg-muted-foreground",
        )}
      />
    </button>
  );
}