{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "radix-switch", "type": "registry:ui", "title": "Radix Switch", "description": "A control that allows the user to toggle between checked and not checked.", "dependencies": [ "motion", "radix-ui" ], "files": [ { "path": "registry/radix/switch/index.tsx", "content": "'use client';\n\nimport * as React from 'react';\nimport { Switch as SwitchPrimitives } from 'radix-ui';\nimport { motion, type HTMLMotionProps } from 'motion/react';\n\nimport { cn } from '@/lib/utils';\n\ntype SwitchProps = React.ComponentProps &\n HTMLMotionProps<'button'> & {\n leftIcon?: React.ReactNode;\n rightIcon?: React.ReactNode;\n thumbIcon?: React.ReactNode;\n };\n\nfunction Switch({\n className,\n leftIcon,\n rightIcon,\n thumbIcon,\n onCheckedChange,\n ...props\n}: SwitchProps) {\n const [isChecked, setIsChecked] = React.useState(\n props?.checked ?? props?.defaultChecked ?? false,\n );\n const [isTapped, setIsTapped] = React.useState(false);\n\n React.useEffect(() => {\n if (props?.checked !== undefined) setIsChecked(props.checked);\n }, [props?.checked]);\n\n const handleCheckedChange = React.useCallback(\n (checked: boolean) => {\n setIsChecked(checked);\n onCheckedChange?.(checked);\n },\n [onCheckedChange],\n );\n\n return (\n \n setIsTapped(true)}\n onTapCancel={() => setIsTapped(false)}\n onTap={() => setIsTapped(false)}\n {...props}\n >\n {leftIcon && (\n \n {typeof leftIcon !== 'string' ? leftIcon : null}\n \n )}\n\n {rightIcon && (\n \n {typeof rightIcon !== 'string' ? rightIcon : null}\n \n )}\n\n \n \n {thumbIcon && typeof thumbIcon !== 'string' ? thumbIcon : null}\n \n \n \n \n );\n}\n\nexport { Switch, type SwitchProps };\n", "type": "registry:ui", "target": "components/animate-ui/radix/switch.tsx" } ] }