@synergy-design-system/components
Version:
This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define
98 lines (97 loc) • 4.18 kB
TypeScript
/**
* ---------------------------------------------------------------------
* 🔒 AUTOGENERATED BY VENDORISM
* Removing this comment will prevent it from being managed by it.
* ---------------------------------------------------------------------
*/
import SynergyElement from '../../internal/synergy-element.js';
import type { CSSResultGroup } from 'lit';
import type { SynergyFormControl } from '../../internal/synergy-element.js';
/**
* @summary Switches allow the user to toggle an option on or off.
* @documentation https://synergy-design-system.github.io/?path=/docs/components-syn-switch--docs
* @status stable
* @since 2.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 syn-blur - Emitted when the control loses focus.
* @event syn-change - Emitted when the control's checked state changes.
* @event syn-input - Emitted when the control receives input.
* @event syn-focus - Emitted when the control gains focus.
* @event syn-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 SynSwitch extends SynergyElement implements SynergyFormControl {
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 `<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;
/** The switch's help text. If you need to display HTML, use the `help-text` slot instead. */
helpText: string;
/** 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").TemplateResult<1>;
}
declare global {
interface HTMLElementTagNameMap {
'syn-switch': SynSwitch;
}
}