import { Switch as ArkSwitch } from "@ark-ui/react/switch"; import { injectComponentStyle } from "@bysages/core"; import type { ComponentProps } from "react"; import { useElementId } from "../../internal/id"; type SwitchRootProps = ComponentProps & { /** One rung for the thumb; the track travels with it. */ size?: "sm" | "md" | "lg"; }; function SwitchRoot(props: SwitchRootProps) { const id = useElementId("switch", props); const { size = "md", ...rest } = props; return ; } export interface SwitchFacadeProps { value?: boolean; defaultValue?: boolean; label?: string; disabled?: boolean; invalid?: boolean; required?: boolean; readOnly?: boolean; /** One rung for the thumb; the track travels with it. */ size?: "sm" | "md" | "lg"; className?: string; onValueChange?: (value: boolean) => void; } function SwitchFacade({ value, defaultValue = false, label, disabled = false, invalid = false, required = false, readOnly = false, size = "md", className, onValueChange, }: SwitchFacadeProps) { return ( onValueChange?.(details.checked)} > {label ? {label} : null} ); } SwitchFacade.displayName = "SSwitch"; /** Ark's Switch, dressed in the paper-and-ink system: a track that rests * in the inset shade of the paper and fills flat with primary ink when on, * the thumb sliding on the spring. The API is Ark's own — Root, Label, * Control, Thumb, HiddenInput. */ type SwitchParts = Omit & { Root: typeof SwitchRoot }; /* Ark's namespace is frozen — spread copies the members so Root can be * the sized wrapper while the rest stay Ark's own parts. */ export const Switch = Object.assign(SwitchFacade, { ...ArkSwitch, Root: SwitchRoot, }) as typeof SwitchFacade & SwitchParts; injectComponentStyle("switch");