import { type ReactElement, useState, type ComponentProps } from "react"; import { Switch as SwitchPrimitive } from "@base-ui/react/switch"; import { cn } from "@/lib/utils"; /** * Switch — shadcn/WealthX * Base: npx shadcn\@latest add switch (latest) * Figma: Design-System---shadcn?node-id=3041-6197 * * WealthX additions: aria-invalid error state, SwitchCard with position variants. * Tokens: unchecked=input, checked=primary, error=destructive, thumb=background. */ export type SwitchProps = ComponentProps & { size?: "sm" | "default"; }; function Switch({ className, size = "default", ...props }: SwitchProps): ReactElement { return ( ); } /** * SwitchCard -- card wrapper with label + description + switch toggle. * Figma: SwitchCard (3041:6237) */ export type SwitchCardProps = Omit< ComponentProps, "children" > & { label: string; description?: string; error?: boolean; switchPosition?: "left" | "right"; size?: "sm" | "default"; }; function SwitchCard({ className, checked, defaultChecked, onCheckedChange, disabled, error, label, description, switchPosition = "right", size, ...props }: SwitchCardProps): ReactElement { const [internalChecked, setInternalChecked] = useState( defaultChecked ?? false, ); const isChecked = checked ?? internalChecked; const switchElement = ( { setInternalChecked(value); onCheckedChange?.(value, event); }} size={size} {...props} /> ); const contentElement = (
{label} {description ? ( {description} ) : null}
); return ( ); } export { Switch, SwitchCard };