UNPKG

@material/web

Version:
151 lines (150 loc) 5.04 kB
/** * @license * Copyright 2021 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import '../../focus/md-focus-ring.js'; import '../../ripple/ripple.js'; import { LitElement, PropertyValues, TemplateResult } from 'lit'; /** * @fires input {InputEvent} Fired whenever `selected` changes due to user * interaction (bubbles and composed). * @fires change {Event} Fired whenever `selected` changes due to user * interaction (bubbles). */ export declare class Switch extends LitElement { /** @nocollapse */ static shadowRootOptions: ShadowRootInit; /** @nocollapse */ static readonly formAssociated = true; /** * Disables the switch and makes it non-interactive. */ disabled: boolean; /** * Puts the switch in the selected state and sets the form submission value to * the `value` property. */ selected: boolean; /** * Shows both the selected and deselected icons. */ icons: boolean; /** * Shows only the selected icon, and not the deselected icon. If `true`, * overrides the behavior of the `icons` property. */ showOnlySelectedIcon: boolean; /** * When true, require the switch to be selected when participating in * form submission. * * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation */ required: boolean; /** * The value associated with this switch on form submission. `null` is * submitted when `selected` is `false`. */ value: string; /** * The HTML name to use in form submission. */ get name(): string; set name(name: string); /** * The associated form element with which this element's value will submit. */ get form(): HTMLFormElement; /** * The labels this element is associated with. */ get labels(): NodeList; /** * Returns a ValidityState object that represents the validity states of the * switch. * * Note that switches will only set `valueMissing` if `required` and not * selected. * * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation */ get validity(): ValidityState; /** * Returns the native validation error message. * * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation#constraint_validation_process */ get validationMessage(): string; /** * Returns whether an element will successfully validate based on forms * validation rules and constraints. * * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation#constraint_validation_process */ get willValidate(): boolean; private readonly input; private hasCustomValidityError; private readonly internals; constructor(); /** * Checks the switch's native validation and returns whether or not the * element is valid. * * If invalid, this method will dispatch the `invalid` event. * * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity * * @return true if the switch is valid, or false if not. */ checkValidity(): boolean; /** * Checks the switch's native validation and returns whether or not the * element is valid. * * If invalid, this method will dispatch the `invalid` event. * * The `validationMessage` is reported to the user by the browser. Use * `setCustomValidity()` to customize the `validationMessage`. * * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity * * @return true if the switch is valid, or false if not. */ reportValidity(): boolean; /** * Sets the switch's native validation error message. This is used to * customize `validationMessage`. * * When the error is not an empty string, the switch is considered invalid * and `validity.customError` will be true. * * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity * * @param error The error message to display. */ setCustomValidity(error: string): void; protected update(changed: PropertyValues<Switch>): void; protected render(): TemplateResult; protected updated(): void; private getRenderClasses; private renderHandle; private renderIcons; /** * https://fonts.google.com/icons?selected=Material%20Symbols%20Outlined%3Acheck%3AFILL%400%3Bwght%40500%3BGRAD%400%3Bopsz%4024 */ private renderOnIcon; /** * https://fonts.google.com/icons?selected=Material%20Symbols%20Outlined%3Aclose%3AFILL%400%3Bwght%40500%3BGRAD%400%3Bopsz%4024 */ private renderOffIcon; private renderTouchTarget; private shouldShowIcons; private handleChange; private syncValidity; private getInput; /** @private */ formResetCallback(): void; /** @private */ formStateRestoreCallback(state: string): void; }