import type { EventCallback } from "../../core/state/emitter.js"; import type { TouchEvents } from "../../core/utils/mobile.js"; /** * Creates a new Switch component * @param config */ declare const createSwitch: (config?: SwitchConfig) => SwitchComponent; type SwitchPosition = "center" | "start" | "end"; /** Switch label position types */ type SwitchLabelPosition = "start" | "end"; /** Configuration interface for the Switch component */ interface SwitchConfig { /** Input name attribute */ name?: string; /** Initial checked state */ checked?: boolean; /** Whether input is required */ required?: boolean; /** Whether switch is disabled */ disabled?: boolean; /** Input value attribute */ value?: string; /** Label text, or a node placed inside the label (the web component passes a ``) */ label?: string | Node; /** Supporting text content */ supportingText?: string; /** Whether supporting text indicates an error */ error?: boolean; /** Additional CSS classes */ class?: string; /** ARIA label for accessibility */ ariaLabel?: string; /** * Put ariaLabel only on the input/handle, omitting the generated wrapper label. * @default false */ controlLabelOnly?: boolean; /** Prefix for class names */ prefix?: string; /** Component name */ componentName?: string; /** Icon HTML in the selected handle; 'none' for no icon. */ icon?: string; /** Icon HTML in the unselected handle, which then grows to 24dp (M3's icons on both states). */ unselectedIcon?: string; /** * Which side of the switch the label sits on * @default 'start' */ labelPosition?: SwitchLabelPosition; /** Index signature for additional properties */ [key: string]: unknown; } /** A checked-state change from native input activation. */ interface SwitchChangePayload { /** The new checked state. */ checked: boolean; /** The checked model value, matching getValue() at dispatch. */ value: boolean; /** The input's HTML value attribute, used for native form submission. */ valueAttribute: string; /** The original native change event, when supplied by the emitter. */ nativeEvent?: Event; } /** Emitter events: change, and the input's focus and blur. */ interface SwitchEvents extends TouchEvents { change: (payload: SwitchChangePayload) => void; focus: (event: FocusEvent) => void; blur: (event: FocusEvent) => void; } /** Switch component interface */ interface SwitchComponent { /** The root element of the switch */ element: HTMLElement; /** The input element */ input: HTMLInputElement; /** Gets the switch's checked state (boolean) for form compatibility */ getValue: () => boolean; /** Sets the switch's checked state */ setValue: (value: boolean | string) => SwitchComponent; /** Gets the HTML value attribute (rarely needed) */ getValueAttribute: () => string; /** Sets the HTML value attribute (rarely needed) */ setValueAttribute: (value: string) => SwitchComponent; /** Checks/activates the switch */ check: () => SwitchComponent; /** Unchecks/deactivates the switch */ uncheck: () => SwitchComponent; /** Toggles the switch's checked state */ toggle: () => SwitchComponent; /** Returns whether the switch is checked */ isChecked: () => boolean; /** Sets the switch's label text */ setLabel: (text: string) => SwitchComponent; /** Gets the switch's label text */ getLabel: () => string; /** Supporting text element */ supportingTextElement: HTMLElement | null; /** Sets supporting text content */ setSupportingText: (text: string, isError?: boolean) => SwitchComponent; /** Removes supporting text */ removeSupportingText: () => SwitchComponent; /** Puts the switch in or out of the error state: its class and aria-invalid */ setError: (error: boolean) => SwitchComponent; /** Whether the switch is in the error state */ isError: () => boolean; /** Subscribes to checked-state changes; native input events use input.addEventListener. */ on: (event: K, handler: SwitchEvents[K]) => SwitchComponent; /** Removes event listener */ off: (event: K, handler: SwitchEvents[K]) => SwitchComponent; /** Enables the switch */ enable: () => SwitchComponent; /** Disables the switch */ disable: () => SwitchComponent; /** Whether the switch is disabled */ isDisabled: () => boolean; /** Destroys the switch component and cleans up resources */ destroy: () => void; } interface ApiOptions { disabled: { enable: () => void; disable: () => void; isDisabled: () => boolean; }; lifecycle: { destroy: () => void; }; checkable: { check: () => void; uncheck: () => void; toggle: () => void; isChecked: () => boolean; }; } interface BaseComponent { element: HTMLElement; input?: HTMLInputElement; getValue?: () => boolean; setValue?: (value: boolean) => void; label?: { setText: (content: string) => void; getText: () => string; }; on?: (event: string, handler: EventCallback) => void; off?: (event: string, handler: EventCallback) => void; disabled?: { enable: () => void; disable: () => void; isDisabled: () => boolean; }; lifecycle?: { destroy: () => void; }; checkable?: { check: () => void; uncheck: () => void; toggle: () => void; isChecked: () => boolean; }; supportingTextElement?: HTMLElement | null; setSupportingText?: (text: string, isError?: boolean) => void; removeSupportingText?: () => void; setError?: (error: boolean) => void; isError?: () => boolean; } type ApiComponent = BaseComponent & Required>; /** Registers SwitchConfig with the global defaults map, so `setComponentDefaults("switch", ...)` is typed without core importing anything from this component. */ declare module "../../core/config/global" { interface ComponentConfigMap { switch?: Partial; } } export type { SwitchChangePayload, SwitchComponent, SwitchConfig, SwitchEvents }; export { createSwitch, createSwitch as default }; export { SWITCH_CLASSES, SWITCH_DEFAULTS, SWITCH_EVENTS, SWITCH_LABEL_POSITIONS, SWITCH_STATES } from "./constants.js";