import type { CSSResultGroup } from 'lit'; import type { TerraFormControl } from '../../internal/terra-element.js'; import TerraElement from '../../internal/terra-element.js'; /** * @summary Switches allow the user to toggle an option on or off. * @documentation https://terra-ui.netlify.app/components/toggle * @status stable * @since 1.0 * * @slot - The switch's label. * @slot help-text - Text that describes how to use the switch. Alternatively, you can use the `help-text` attribute. * * @event terra-blur - Emitted when the control loses focus. * @event terra-change - Emitted when the control's checked state changes. * @event terra-input - Emitted when the control receives input. * @event terra-focus - Emitted when the control gains focus. * @event terra-invalid - Emitted when the form control has been checked for validity and its constraints aren't satisfied. * * @csspart base - The component's base wrapper. * @csspart control - The control that houses the switch's thumb. * @csspart thumb - The switch's thumb. * @csspart label - The switch's label. * @csspart form-control-help-text - The help text's wrapper. * * @cssproperty --width - The width of the switch. * @cssproperty --height - The height of the switch. * @cssproperty --thumb-size - The size of the thumb. */ export default class TerraToggle extends TerraElement implements TerraFormControl { static styles: CSSResultGroup; private readonly formControlController; private readonly hasSlotController; input: HTMLInputElement; private hasFocus; title: string; /** The name of the switch, submitted as a name/value pair with form data. */ name: string; /** The current value of the switch, submitted as a name/value pair with form data. */ value: string; /** The switch's size. */ size: 'small' | 'medium' | 'large'; /** Disables the switch. */ disabled: boolean; /** Draws the switch in a checked state. */ checked: boolean; /** The default value of the form control. Primarily used for resetting the form control. */ defaultChecked: boolean; /** * By default, form controls are associated with the nearest containing `