86 lines
3.5 KiB
TypeScript
86 lines
3.5 KiB
TypeScript
import ShoelaceElement from '../../internal/shoelace-element.js';
|
|
import type { CSSResultGroup } from 'lit';
|
|
import type { ShoelaceFormControl } from '../../internal/shoelace-element.js';
|
|
/**
|
|
* @summary Switches allow the user to toggle an option on or off.
|
|
* @documentation https://shoelace.style/components/switch
|
|
* @status stable
|
|
* @since 2.0
|
|
*
|
|
* @slot - The switch's label.
|
|
*
|
|
* @event sl-blur - Emitted when the control loses focus.
|
|
* @event sl-change - Emitted when the control's checked state changes.
|
|
* @event sl-input - Emitted when the control receives input.
|
|
* @event sl-focus - Emitted when the control gains focus.
|
|
* @event sl-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.
|
|
*
|
|
* @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 SlSwitch extends ShoelaceElement implements ShoelaceFormControl {
|
|
static styles: CSSResultGroup;
|
|
private readonly formControlController;
|
|
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 `<form>` element. This attribute allows you
|
|
* to place the form control outside of a form and associate it with the form that has this `id`. The form must be in
|
|
* the same document or shadow root for this to work.
|
|
*/
|
|
form: string;
|
|
/** Makes the switch a required field. */
|
|
required: boolean;
|
|
/** Gets the validity state object */
|
|
get validity(): ValidityState;
|
|
/** Gets the validation message */
|
|
get validationMessage(): string;
|
|
firstUpdated(): void;
|
|
private handleBlur;
|
|
private handleInput;
|
|
private handleInvalid;
|
|
private handleClick;
|
|
private handleFocus;
|
|
private handleKeyDown;
|
|
handleCheckedChange(): void;
|
|
handleDisabledChange(): void;
|
|
/** Simulates a click on the switch. */
|
|
click(): void;
|
|
/** Sets focus on the switch. */
|
|
focus(options?: FocusOptions): void;
|
|
/** Removes focus from the switch. */
|
|
blur(): void;
|
|
/** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */
|
|
checkValidity(): boolean;
|
|
/** Gets the associated form, if one exists. */
|
|
getForm(): HTMLFormElement | null;
|
|
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
reportValidity(): boolean;
|
|
/** Sets a custom validation message. Pass an empty string to restore validity. */
|
|
setCustomValidity(message: string): void;
|
|
render(): import("lit-html").TemplateResult<1>;
|
|
}
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'sl-switch': SlSwitch;
|
|
}
|
|
}
|