@aurelia-mdc-web/switch
Version:
Wrapper for Material Components Web Switch
74 lines • 3.22 kB
JavaScript
define(["require", "exports", "tslib", "@aurelia-mdc-web/base", "@material/switch", "aurelia-framework"], function (require, exports, tslib_1, base_1, switch_1, aurelia_framework_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MdcSwitch = void 0;
var switchId = 0;
var MdcSwitch = /** @class */ (function (_super) {
tslib_1.__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 switch_1.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 = tslib_1.__decorate([
(0, aurelia_framework_1.inject)(Element),
(0, aurelia_framework_1.useView)(aurelia_framework_1.PLATFORM.moduleName('./mdc-switch.html')),
(0, aurelia_framework_1.customElement)('mdc-switch'),
tslib_1.__metadata("design:paramtypes", [Object])
], MdcSwitch);
return MdcSwitch;
}(base_1.MdcComponent));
exports.MdcSwitch = 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