UNPKG

@aurelia-mdc-web/floating-label

Version:

Wrapper for Material Components Web Floating Label

53 lines 2.51 kB
import { __decorate, __extends } from "tslib"; import { inject, customElement, useView, PLATFORM } from 'aurelia-framework'; import { MDCFloatingLabelFoundation } from '@material/floating-label'; import { MdcComponent } from '@aurelia-mdc-web/base'; import { estimateScrollWidth } from '@material/dom/ponyfill'; var MdcFloatingLabel = /** @class */ (function (_super) { __extends(MdcFloatingLabel, _super); function MdcFloatingLabel() { return _super !== null && _super.apply(this, arguments) || this; } MdcFloatingLabel.prototype.shake = function (shouldShake) { var _a; (_a = this.foundation) === null || _a === void 0 ? void 0 : _a.shake(shouldShake); }; /** * Styles the label to float/dock. * @param shouldFloat If true, floats the label by adding a CSS class; otherwise, docks it by removing the class. */ MdcFloatingLabel.prototype.float = function (shouldFloat) { var _a; (_a = this.foundation) === null || _a === void 0 ? void 0 : _a.float(shouldFloat); }; /** * Styles the label as required. * @param isRequired If true, adds an asterisk to the label, indicating that it is required. */ MdcFloatingLabel.prototype.setRequired = function (isRequired) { var _a; (_a = this.foundation) === null || _a === void 0 ? void 0 : _a.setRequired(isRequired); }; MdcFloatingLabel.prototype.getWidth = function () { return this.foundation.getWidth(); }; MdcFloatingLabel.prototype.getDefaultFoundation = function () { var _this = this; var adapter = { addClass: function (className) { return _this.root.classList.add(className); }, removeClass: function (className) { return _this.root.classList.remove(className); }, getWidth: function () { return estimateScrollWidth(_this.root); }, registerInteractionHandler: function (evtType, handler) { return _this.listen(evtType, handler); }, deregisterInteractionHandler: function (evtType, handler) { return _this.unlisten(evtType, handler); }, }; return new MDCFloatingLabelFoundation(adapter); }; MdcFloatingLabel = __decorate([ inject(Element), customElement('mdc-floating-label'), useView(PLATFORM.moduleName('./mdc-floating-label.html')) ], MdcFloatingLabel); return MdcFloatingLabel; }(MdcComponent)); export { MdcFloatingLabel }; //# sourceMappingURL=mdc-floating-label.js.map