@aurelia-mdc-web/form-field
Version:
Wrapper for Material Components Web Form Field
69 lines • 3.54 kB
JavaScript
import { __awaiter, __decorate, __extends, __generator, __metadata, __read, __spreadArray } from "tslib";
import { inject, useView, customElement, PLATFORM } from 'aurelia-framework';
import { cssClasses, MDCFormFieldFoundation } from '@material/form-field';
import { bindable } from 'aurelia-typed-observable-plugin';
import { MdcComponent } from '@aurelia-mdc-web/base';
/**
* @selector mdc-form-field
*/
var MdcFormField = /** @class */ (function (_super) {
__extends(MdcFormField, _super);
function MdcFormField() {
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
_this.cssClasses = cssClasses;
return _this;
}
// eslint-disable-next-line @typescript-eslint/require-await
MdcFormField.prototype.initialise = function () {
return __awaiter(this, void 0, void 0, function () {
var rippleUpgraded, input;
return __generator(this, function (_a) {
rippleUpgraded = this.root.querySelector('mdc-checkbox');
if (!rippleUpgraded) {
rippleUpgraded = this.root.querySelector('mdc-radio');
}
this.ripple = rippleUpgraded === null || rippleUpgraded === void 0 ? void 0 : rippleUpgraded.au['mdc-ripple'].viewModel;
input = this.root.querySelector('input, button');
if (input === null || input === void 0 ? void 0 : input.hasAttribute('id')) {
this.label = this.root.querySelector('label');
if (this.label) {
this.label.setAttribute('for', input.getAttribute('id'));
}
}
return [2 /*return*/];
});
});
};
MdcFormField.prototype.getDefaultFoundation = function () {
var _this = this;
// DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
// To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
var adapter = {
activateInputRipple: function () { var _a; return (_a = _this.ripple) === null || _a === void 0 ? void 0 : _a.activate(); },
deactivateInputRipple: function () { var _a; return (_a = _this.ripple) === null || _a === void 0 ? void 0 : _a.deactivate(); },
deregisterInteractionHandler: function (evtType, handler) { var _a; return (_a = _this.label) === null || _a === void 0 ? void 0 : _a.removeEventListener(evtType, handler); },
registerInteractionHandler: function (evtType, handler) { var _a; return (_a = _this.label) === null || _a === void 0 ? void 0 : _a.addEventListener(evtType, handler); },
};
return new MDCFormFieldFoundation(adapter);
};
__decorate([
bindable.booleanAttr,
__metadata("design:type", Boolean)
], MdcFormField.prototype, "nowrap", void 0);
__decorate([
bindable.booleanAttr,
__metadata("design:type", Boolean)
], MdcFormField.prototype, "alignEnd", void 0);
__decorate([
bindable.booleanAttr,
__metadata("design:type", Boolean)
], MdcFormField.prototype, "spaceBetween", void 0);
MdcFormField = __decorate([
inject(Element),
useView(PLATFORM.moduleName('./mdc-form-field.html')),
customElement(cssClasses.ROOT)
], MdcFormField);
return MdcFormField;
}(MdcComponent));
export { MdcFormField };
//# sourceMappingURL=mdc-form-field.js.map