import * as SwitchPrimitive from '@radix-ui/react-switch'; import { forwardRef, type ComponentPropsWithoutRef } from 'react'; import { cn } from '@/lib/utils'; import { usePlatform } from '@/platform'; export interface SwitchProps extends Omit, 'onChange'> { label?: string; description?: string; onChange?: (checked: boolean) => void; haptic?: boolean; } export const Switch = forwardRef( ({ className, label, description, onChange, onCheckedChange, haptic = true, ...props }, ref) => { const { haptic: platformHaptic } = usePlatform(); const handleCheckedChange = (checked: boolean) => { if (haptic) { platformHaptic.impact('light'); } onCheckedChange?.(checked); onChange?.(checked); }; const switchElement = ( ); if (!label) { return switchElement; } return ( ); }, ); Switch.displayName = 'Switch';