import * as SwitchPrimitive from "@radix-ui/react-switch" import * as React from "react" import { cn } from "../libs/utils" const sizes = { 'sm': ['h-5 w-8', 'size-3', 'translate-x-4'], 'md': ['h-6 w-11', 'size-4', 'translate-x-6'], 'lg': ['h-8 w-16', 'size-6', 'translate-x-9'], } interface SwitchProps { size?: 'sm' | 'md' | 'lg' value: boolean onChange: (value: boolean) => void children?: React.ReactNode className?: string disabled?: boolean } function Switch({ className, size = 'md', value, onChange, children, disabled }: SwitchProps) { const [trackSize, thumbSize, thumbTranslate] = sizes[size] const switchEl = ( ) if (children) { return (
{switchEl} {children}
) } return switchEl } export { Switch }