diff --git a/package.json b/package.json index 9da8b423..f1cd3ce0 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "tailwind-merge": "^2.6.0" }, "peerDependencies": { - "@radix-ui/react-switch": "^1.0.0", "framer-motion": "^11.0.0", "react": "^19.0.0", "react-dom": "^19.0.0", diff --git a/src/shared/ui/Switch/Switch.tsx b/src/shared/ui/Switch/Switch.tsx index f4ab79cc..b0051a59 100644 --- a/src/shared/ui/Switch/Switch.tsx +++ b/src/shared/ui/Switch/Switch.tsx @@ -1,23 +1,60 @@ -import * as SwitchPrimitives from '@radix-ui/react-switch'; +import { useState } from 'react'; import { COLORS, SwitchColor } from '@/shared/lib/colors'; -type Props = React.ComponentProps & { +type Props = Omit, 'onClick'> & { /** * color of the switch. * @default 'primary' */ color?: SwitchColor; + checked?: boolean; + defaultChecked?: boolean; + onCheckedChange?: (checked: boolean) => void; }; -export function Switch({ color = 'primary', ...props }: Props) { +export function Switch({ + color = 'primary', + checked, + defaultChecked = false, + onCheckedChange, + className, + disabled, + ...props +}: Props) { + const [uncontrolledChecked, setUncontrolledChecked] = useState(defaultChecked); + const isChecked = checked ?? uncontrolledChecked; + + const handleClick = () => { + if (disabled) return; + + const next = !isChecked; + if (checked === undefined) { + setUncontrolledChecked(next); + } + onCheckedChange?.(next); + }; + return ( - - - + + ); } diff --git a/vite.config.ts b/vite.config.ts index 387abd7c..46962363 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -35,7 +35,6 @@ export default defineConfig({ 'react-dom', 'react/jsx-runtime', 'framer-motion', - '@radix-ui/react-switch', 'tailwindcss', ], output: {