UNPKG

@aurelia-mdc-web/switch

Version:

Wrapper for Material Components Web Switch

73 lines 2.76 kB
import { __decorate, __extends, __metadata } from "tslib"; import { MdcComponent } from '@aurelia-mdc-web/base'; import { MDCSwitchRenderFoundation } from '@material/switch'; import { inject, useView, PLATFORM, customElement } from 'aurelia-framework'; var switchId = 0; var MdcSwitch = /** @class */ (function (_super) { __extends(MdcSwitch, _super); function MdcSwitch(root) { var _this = _super.call(this, root) || this; _this.root = root; defineMdcSwitchElementApis(_this.root); _this.root.id = "mdc-switch-".concat(++switchId); return _this; } MdcSwitch.prototype.initialSyncWithDOM = function () { 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(); }; MdcSwitch.prototype.getDefaultFoundation = function () { return new MDCSwitchRenderFoundation(this.createAdapter()); }; MdcSwitch.prototype.createAdapter = function () { var _this = this; return { addClass: function (className) { _this.root.classList.add(className); }, hasClass: function (className) { return _this.root.classList.contains(className); }, isDisabled: function () { return _this.root.disabled; }, removeClass: function (className) { _this.root.classList.remove(className); }, setAriaChecked: function (ariaChecked) { return _this.root.setAttribute('aria-checked', ariaChecked); }, setDisabled: function (disabled) { _this.root.disabled = disabled; }, state: this, }; }; MdcSwitch.prototype.handleClick = function () { 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); return MdcSwitch; }(MdcComponent)); export { MdcSwitch }; function defineMdcSwitchElementApis(element) { Object.defineProperties(element, { selected: { get: function () { return this.au.controller.viewModel.selected; }, set: function (value) { this.au.controller.viewModel.selected = value; }, configurable: true } }); } //# sourceMappingURL=mdc-switch.js.map