UNPKG

@aurelia-mdc-web/switch

Version:

Wrapper for Material Components Web Switch

67 lines 2.29 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() { var _a; if (this.selected) { this.root.classList.add('mdc-switch--selected'); this.root.setAttribute('aria-checked', 'true'); } (_a = this.foundation) === null || _a === void 0 ? void 0 : _a.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() { var _a; (_a = this.foundation) === null || _a === void 0 ? void 0 : _a.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