41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import * as SwitchPrimitive from '@radix-ui/react-switch'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
interface SwitchProps {
|
|
checked: boolean
|
|
onCheckedChange: (checked: boolean) => void
|
|
label?: string
|
|
description?: string
|
|
disabled?: boolean
|
|
}
|
|
|
|
export function Switch({ checked, onCheckedChange, label, description, disabled }: SwitchProps) {
|
|
return (
|
|
<div className="flex items-center justify-between gap-3">
|
|
{(label || description) && (
|
|
<div className="flex-1 min-w-0">
|
|
{label && <p className="text-sm font-medium text-tg-text">{label}</p>}
|
|
{description && <p className="text-xs text-tg-hint mt-0.5">{description}</p>}
|
|
</div>
|
|
)}
|
|
<SwitchPrimitive.Root
|
|
checked={checked}
|
|
onCheckedChange={onCheckedChange}
|
|
disabled={disabled}
|
|
className={cn(
|
|
'relative h-6 w-11 rounded-full transition-colors focus-visible:outline-none',
|
|
'data-[state=checked]:bg-tg-btn data-[state=unchecked]:bg-gray-300',
|
|
'disabled:opacity-50 disabled:cursor-not-allowed'
|
|
)}
|
|
>
|
|
<SwitchPrimitive.Thumb
|
|
className={cn(
|
|
'block h-5 w-5 rounded-full bg-white shadow-md transition-transform',
|
|
'data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0.5'
|
|
)}
|
|
/>
|
|
</SwitchPrimitive.Root>
|
|
</div>
|
|
)
|
|
}
|