import { CommonProps, Refable } from "@trackunit/react-components"; import { MappedOmit, Size } from "@trackunit/shared-utils"; import { ChangeEvent, InputHTMLAttributes, MouseEventHandler, ReactElement } from "react"; export interface ToggleSwitchProps extends CommonProps, MappedOmit, "prefix" | "onChange" | "size" | "children">, Refable { /** * custom onChange event handler. */ onChange?: (toggled: boolean, event?: ChangeEvent) => void; /** * onClick event handler. * * _**Do not**_ pass onClick handlers to trigger the toggle behavior. Use the onChange handler instead. */ onClick?: MouseEventHandler; /** * Whether the ToggleSwitch is toggled(active) or not. */ toggled: boolean; /** * Size of the toggle. */ size?: Size; /** * Whether the track should have a focus outline. * * Set it to false when wrapped by a component that receives focus styles instead (for example in a filter/menu item) * * @default true */ showInputFocus?: boolean; /** * Tab index for the track element * * @default 0 */ tabIndex?: number; /** * Prevents the native checkbox toggle behavior of the toggle switch. */ preventDefaultOnClick?: boolean; /** * Tooltip label for the toggle switch. */ tooltipLabel?: string; } /** * The `` is a low-level checkbox input wrapper with `role="switch"`. * It renders just the switch control without label or description. * * **Not intended for standalone use** - use `ToggleSwitchOption` instead for forms. * This component is for building custom toggle implementations or wrapping in other components. * * ### When to use * - Building custom toggle components with different layouts * - Integrating a toggle into a component that provides its own label (e.g., menu items) * - Creating specialized switch controls * * ### When not to use * - Standard forms - use `ToggleSwitchOption` instead (includes label/description) * - Multiple selections - use `Checkbox` components instead * * @example Basic usage (in custom component) * ```tsx * import { ToggleSwitch } from "@trackunit/react-form-components"; * * const [isEnabled, setIsEnabled] = useState(false); * * setIsEnabled(toggled)} * /> * ``` * @example Inside a custom wrapper * ```tsx * import { ToggleSwitch } from "@trackunit/react-form-components"; * *
* Dark Mode * setDarkMode(toggled)} * size="small" * /> *
* ``` * @example Disabled state * ```tsx * import { ToggleSwitch } from "@trackunit/react-form-components"; * * {}} * disabled * /> * ``` * @param {ToggleSwitchProps} props - The props for the ToggleSwitch component * @returns {ReactElement} ToggleSwitch component */ export declare const ToggleSwitch: { ({ onChange, onClick, preventDefaultOnClick, className, "data-testid": dataTestId, showInputFocus, toggled, size, tabIndex, readOnly, disabled, tooltipLabel, ref, ...rest }: ToggleSwitchProps): ReactElement; displayName: string; };