UNPKG

dap-design-system

Version:

Official design system for the DÁP (dap.gov.hu)

134 lines (133 loc) 3.92 kB
var p = (o, t, l) => new Promise((i, e) => { var s = (a) => { try { d(l.next(a)); } catch (h) { e(h); } }, u = (a) => { try { d(l.throw(a)); } catch (h) { e(h); } }, d = (a) => a.done ? i(a.value) : Promise.resolve(a.value).then(s, u); d((l = l.apply(o, t)).next()); }); import { property as n } from "../../node_modules/@lit/reactive-element/decorators/property.js"; var c = Object.defineProperty, r = (o, t, l, i) => { for (var e = void 0, s = o.length - 1, u; s >= 0; s--) (u = o[s]) && (e = u(t, l, e) || e); return e && c(t, l, e), e; }; const f = [ "value", "checked", "selected", "disabled", "readonly" ]; function v(o) { class t extends o { constructor(...i) { super(...i), this.disabled = !1, this.required = !1, this.readonly = !1, this.silent = !0, this.invalid = !1, this.autocomplete = "off", this.formElement = null, this.internals = this.attachInternals(); } get innerInput() { return this.input || this.$input; } static get formAssociated() { return !0; } connectedCallback() { super.connectedCallback(), this.formElement = this.closest("form"), this.defaultValue || (this.defaultValue = this.value); } attributeChangedCallback(i, e, s) { if (super.attributeChangedCallback(i, e, s), f.includes(i) && s !== e) switch (i) { case "value": this.nodeName !== "DAP-DS-BUTTON" && this.internals.setFormValue(s); break; case "checked": this.internals.setFormValue(s !== null ? "on" : null); } } formResetCallback() { this.internals.setValidity({}), this.internals.setFormValue(this.defaultValue); } onInput() { this.emit("dds-input", { value: this.innerInput.value }); } onBlur() { this.emit("dds-blur"); } onFocus() { this.emit("dds-focus"); } onChange() { this.emit("dds-change", { value: this.innerInput.value }); } onKeydown(i) { this.emit("dds-keydown", { value: this.innerInput.value, event: i }); } handleInvalid(i) { this.silent && i.preventDefault(); } firstUpdated(i) { return p(this, null, function* () { var e; this.$input = (e = this.shadowRoot) == null ? void 0 : e.getElementById("input"), this.nodeName !== "DAP-DS-BUTTON" && (this.internals.setFormValue(this.value), this.setValidity()); }); } setValidity() { this.innerInput && (this.innerInput.checkValidity() ? this.internals.setValidity({}) : this.internals.setValidity( this.innerInput.validity, this.validationMessage, this.innerInput )); } get validity() { return this.innerInput.validity; } get validationMessage() { return " "; } get willValidate() { return this.innerInput.willValidate; } checkValidity() { return this.innerInput.checkValidity(); } reportValidity() { return this.innerInput.reportValidity(); } } return r([ n({ reflect: !0 }) ], t.prototype, "name"), r([ n() ], t.prototype, "defaultValue"), r([ n({ reflect: !0 }) ], t.prototype, "form"), r([ n({ type: Boolean, reflect: !0 }) ], t.prototype, "disabled"), r([ n({ type: Boolean, reflect: !0, attribute: !0 }) ], t.prototype, "required"), r([ n({ type: Boolean, reflect: !0 }) ], t.prototype, "readonly"), r([ n({ type: Boolean }) ], t.prototype, "silent"), r([ n({ type: Boolean, reflect: !0 }) ], t.prototype, "invalid"), r([ n({ reflect: !0 }) ], t.prototype, "status"), r([ n() ], t.prototype, "autocomplete"), r([ n({ attribute: !0, reflect: !0 }) ], t.prototype, "value"), r([ n({ attribute: !1 }) ], t.prototype, "internals"), t; } export { v as FormElementMixin }; //# sourceMappingURL=formElementMixin.js.map