import { useId } from "@radix-ui/react-id"; import * as Label from "@radix-ui/react-label"; import * as PrimitiveSwitch from "@radix-ui/react-switch"; import React, { useState } from "react"; import classNames from "@lib/classNames"; type SwitchProps = React.ComponentProps & { label: string; }; export default function Switch(props: SwitchProps) { const { label, onCheckedChange, ...primitiveProps } = props; const [checked, setChecked] = useState(props.defaultChecked || false); const onPrimitiveCheckedChange = (change: boolean) => { if (onCheckedChange) { onCheckedChange(change); } setChecked(change); }; const id = useId(); return (
{label && ( {label} )}
); }