UNPKG

@postnord/web-components

Version:

PostNord Web Components

70 lines (66 loc) 4.93 kB
/*! * Built with Stencil * By PostNord. */ import { r as registerInstance, g as getElement, f as forceUpdate, h, a as Host } from './index-5606614b.js'; import { u as uuidv4 } from './helpers-88f72b54.js'; import { a as alert_exclamation_circle } from './alert_exclamation_circle-7e58e19d.js'; import { a as alert_info_circle } from './alert_info_circle-09cae69f.js'; const pnFieldsetCss = "pn-fieldset{display:inline-block}pn-fieldset .pn-fieldset{border:0;padding:0;margin:0;color:#2d2013;display:flex;flex-direction:column;font-size:1em}pn-fieldset .pn-fieldset-legend{float:left;font-weight:500;line-height:1.4;padding:0}pn-fieldset .pn-fieldset-helpertext{color:#5e554a;margin:0}pn-fieldset .pn-fieldset-items{padding:0.75em 0;display:flex;flex-direction:column;gap:0.75em}pn-fieldset .pn-fieldset-message-wrapper{display:flex;gap:0.75em;color:#2d2013;line-height:1.4;font-weight:400}pn-fieldset .pn-fieldset-message-wrapper[hidden]{display:none}pn-fieldset .pn-fieldset-message{margin:0}pn-fieldset .pn-fieldset[aria-invalid=true]>.pn-fieldset-legend,pn-fieldset .pn-fieldset[aria-invalid=true]>.pn-fieldset-helpertext,pn-fieldset .pn-fieldset[aria-invalid=true]>.pn-fieldset-message-wrapper{color:#a70707}pn-fieldset .pn-fieldset[aria-invalid=true]>.pn-fieldset-legend>pn-icon .pn-icon-svg>path,pn-fieldset .pn-fieldset[aria-invalid=true]>.pn-fieldset-helpertext>pn-icon .pn-icon-svg>path,pn-fieldset .pn-fieldset[aria-invalid=true]>.pn-fieldset-message-wrapper>pn-icon .pn-icon-svg>path{fill:#a70707}pn-fieldset .pn-fieldset:disabled>.pn-fieldset-legend,pn-fieldset .pn-fieldset:disabled>.pn-fieldset-helpertext,pn-fieldset .pn-fieldset:disabled>.pn-fieldset-message,pn-fieldset .pn-fieldset:disabled>.pn-fieldset-message-wrapper{color:#2d2013}pn-fieldset .pn-fieldset:disabled>.pn-fieldset-legend>pn-icon .pn-icon-svg>path,pn-fieldset .pn-fieldset:disabled>.pn-fieldset-helpertext>pn-icon .pn-icon-svg>path,pn-fieldset .pn-fieldset:disabled>.pn-fieldset-message>pn-icon .pn-icon-svg>path,pn-fieldset .pn-fieldset:disabled>.pn-fieldset-message-wrapper>pn-icon .pn-icon-svg>path{fill:#2d2013}"; const PnFieldsetStyle0 = pnFieldsetCss; const PnFieldset = class { constructor(hostRef) { registerInstance(this, hostRef); this.legend = undefined; this.helpertext = undefined; this.fieldsetId = this.id; this.form = undefined; this.name = undefined; this.disabled = false; this.invalid = false; this.error = undefined; } mo; id = `pn-fieldset-${uuidv4()}`; idHelpertext = `${this.id}-helpertext`; get hostElement() { return getElement(this); } handleId() { this.idHelpertext = `${this.fieldsetId}-helpertext`; } componentWillLoad() { this.handleId(); } componentDidLoad() { if (this.mo) this.mo.disconnect(); this.mo = new MutationObserver(() => forceUpdate(this.hostElement)); this.mo.observe(this.hostElement.querySelector('.pn-fieldset'), { childList: true, subtree: true }); } componentDidRender() { /** * Stencil has a known problem about rendering the `form` attribute. * Setting it via setAttribute solves it for now. * https://github.com/ionic-team/stencil/issues/2703 **/ if (this.form) { this.hostElement.querySelector('fieldset')?.setAttribute('form', this.form); } } hasError() { return this.invalid || !!this.error; } getSymbol() { if (this.disabled) return alert_info_circle; return alert_exclamation_circle; } render() { return (h(Host, { key: '2f9bd47d141fe715a0550ec9bdea9139a4e30cb8' }, h("fieldset", { key: 'dd2f2178cd03c01266cedab11efff9816a167a33', id: this.fieldsetId, class: "pn-fieldset", disabled: this.disabled, "aria-describedby": this.helpertext && this.idHelpertext, "aria-invalid": this.hasError().toString() }, h("legend", { key: '106f0a8fe2fedd06d196df94820179aacaeaa391', class: "pn-fieldset-legend" }, this.legend), this.helpertext && (h("p", { key: '177d95cccd6991035d5b3f99b447f547dfd8beda', id: this.idHelpertext, class: "pn-fieldset-helpertext" }, this.helpertext)), h("div", { key: '14f4316e932cc34cc191bcba9ad0cc3d0acbfca3', class: "pn-fieldset-items" }, h("slot", { key: '29b725ae5b831261b0935ae32acfd089d646f337' })), h("div", { key: '67f555a9c88d29d6291000147ce7d34cbbc05811', class: "pn-fieldset-message-wrapper", role: "alert", hidden: !this.error }, h("pn-icon", { key: '20b8f4d989aed460c16cf8b4b785563736082a9c', icon: this.getSymbol() }), h("p", { key: '18a46179b5f093d04f22e688aa9a0bcd1f8bda50', class: "pn-fieldset-message" }, this.error))))); } static get watchers() { return { "fieldsetId": ["handleId"] }; } }; PnFieldset.style = PnFieldsetStyle0; export { PnFieldset as pn_fieldset }; //# sourceMappingURL=pn-fieldset.entry.js.map