UNPKG

@aurelia-mdc-web/switch

Version:

Wrapper for Material Components Web Switch

65 lines 2.16 kB
import { __decorate, __metadata } from "tslib"; import { MdcComponent } from '@aurelia-mdc-web/base'; import { MDCSwitchRenderFoundation } from '@material/switch'; import { inject, useView, PLATFORM, customElement } from 'aurelia-framework'; let switchId = 0; let MdcSwitch = class MdcSwitch extends MdcComponent { constructor(root) { super(root); this.root = root; defineMdcSwitchElementApis(this.root); this.root.id = `mdc-switch-${++switchId}`; } initialSyncWithDOM() { if (this.selected) { this.root.classList.add('mdc-switch--selected'); this.root.setAttribute('aria-checked', 'true'); } this.foundation?.initFromDOM(); } getDefaultFoundation() { return new MDCSwitchRenderFoundation(this.createAdapter()); } createAdapter() { return { addClass: className => { this.root.classList.add(className); }, hasClass: className => this.root.classList.contains(className), isDisabled: () => this.root.disabled, removeClass: className => { this.root.classList.remove(className); }, setAriaChecked: ariaChecked => this.root.setAttribute('aria-checked', ariaChecked), setDisabled: disabled => { this.root.disabled = disabled; }, state: this, }; } handleClick() { this.foundation?.handleClick(); this.emit('change', {}, true); } }; MdcSwitch = __decorate([ inject(Element), useView(PLATFORM.moduleName('./mdc-switch.html')), customElement('mdc-switch'), __metadata("design:paramtypes", [Object]) ], MdcSwitch); export { MdcSwitch }; function defineMdcSwitchElementApis(element) { Object.defineProperties(element, { selected: { get() { return this.au.controller.viewModel.selected; }, set(value) { this.au.controller.viewModel.selected = value; }, configurable: true } }); } //# sourceMappingURL=mdc-switch.js.map