UNPKG

@postnord/web-components

Version:
92 lines (87 loc) 6.95 kB
/*! * Built with Stencil * By PostNord. */ 'use strict'; var index = require('./index-DWu-2oJc.js'); var index$1 = require('./index.cjs.js'); var alert_exclamation_circle = require('./alert_exclamation_circle-BiBEJK9P.js'); var alert_info_circle = require('./alert_info_circle-BaN88M1m.js'); const pnFieldsetCss = () => `${index.transformTag("pn-fieldset")}{display:inline-block}${index.transformTag("pn-fieldset")} .pn-fieldset{border:0;padding:0;margin:0;color:#2d2013;display:flex;flex-direction:column;font-size:1em}${index.transformTag("pn-fieldset")} .pn-fieldset-legend{float:left;font-weight:500;line-height:1.4;padding:0}${index.transformTag("pn-fieldset")} .pn-fieldset-message{color:#5e554a;font-size:0.875em;font-weight:400;margin:0.25em 0 0 0;display:flex;flex-direction:column;gap:0.25em}${index.transformTag("pn-fieldset")} .pn-fieldset-message[hidden]{display:none}${index.transformTag("pn-fieldset")} .pn-fieldset-error{display:flex;flex-direction:row;flex-wrap:nowrap;gap:0.25em}${index.transformTag("pn-fieldset")} .pn-fieldset-error[hidden]{display:none}${index.transformTag("pn-fieldset")} .pn-fieldset-error>.pn-fieldset-message{color:#a70707}${index.transformTag("pn-fieldset")} .pn-fieldset-items{padding:0.75em 0;display:flex;flex-direction:column;gap:0.75em}${index.transformTag("pn-fieldset")} .pn-fieldset[aria-invalid=true]>.pn-fieldset-legend,${index.transformTag("pn-fieldset")} .pn-fieldset[aria-invalid=true]>.pn-fieldset-message-wrapper{color:#a70707}${index.transformTag("pn-fieldset")} .pn-fieldset[aria-invalid=true]>.pn-fieldset-legend>${index.transformTag("pn-icon")} .pn-icon-svg>path,${index.transformTag("pn-fieldset")} .pn-fieldset[aria-invalid=true]>.pn-fieldset-message-wrapper>${index.transformTag("pn-icon")} .pn-icon-svg>path{fill:#a70707}${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-legend,${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-helpertext,${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-message,${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-message-wrapper{color:#2d2013}${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-legend>${index.transformTag("pn-icon")} .pn-icon-svg>path,${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-helpertext>${index.transformTag("pn-icon")} .pn-icon-svg>path,${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-message>${index.transformTag("pn-icon")} .pn-icon-svg>path,${index.transformTag("pn-fieldset")} .pn-fieldset:disabled>.pn-fieldset-message-wrapper>${index.transformTag("pn-icon")} .pn-icon-svg>path{fill:#2d2013}`; const PnFieldset = class { constructor(hostRef) { index.registerInstance(this, hostRef); } mo; id = `pn-fieldset-${index$1.uuidv4()}`; idHelpertext = `${this.id}-helpertext`; get hostElement() { return index.getElement(this); } /** * The legend provides a caption for the fieldset group. * This should be a question or heading that describes the inputs/fields. */ legend; /** Text message underneath the legend for more instruction or hints on how to fill in controls correctly. */ helpertext; /** Give the fieldset a HTML name. @category Native attributes */ name; /** * The id of the form you want the fieldset to be part of. * If you want the inputs inside to be associated with a specific form, you need to set on those elements directly. * @category Native attributes */ form; /** Disable all of the inputs inside of the fieldset. @category Native attributes */ disabled = false; /** Set the fieldset as `invalid`, will add red error styles. @category Features */ invalid = false; /** Error message, applies warning styles and icon. @category Features */ error; /** Set a custom ID for the fieldset. @since v7.25.0 @category HTML attributes */ pnId = this.id; /** Set a custom ID for the fieldset. @deprecated Use `pn-id` instead. @category HTML attributes */ fieldsetId = this.id; handleId() { this.idHelpertext = `${this.getId()}-helpertext`; } connectedCallback() { this.mo = new MutationObserver(() => index.forceUpdate(this.hostElement)); this.mo.observe(this.hostElement, { childList: true, subtree: true }); } disconnectedCallback() { if (this.mo) this.mo.disconnect(); } getId() { return this.pnId || this.fieldsetId || this.id; } hasHelpertext() { const helpertextSlot = this.hostElement.querySelector('[slot="helpertext"]'); return !!this.helpertext || helpertextSlot?.textContent?.trim().length > 0; } hasError() { const errorSlot = this.hostElement.querySelector('[slot="error"]'); return !!this.error || errorSlot?.textContent?.trim().length > 0; } isInvalid() { return this.invalid || this.hasError(); } getIcon() { if (this.disabled) return alert_info_circle.alert_info_circle; return alert_exclamation_circle.alert_exclamation_circle; } render() { return (index.h(index.Host, { key: '908a403f3fb8b4779393f4ca0a4f17f518ba53a7' }, index.h("fieldset", { key: '97b321f776944a0d27f1b1096a967b2c9d9c9fcd', id: this.getId(), name: this.name, form: this.form, class: "pn-fieldset", disabled: this.disabled, "aria-describedby": this.hasHelpertext() ? this.idHelpertext : undefined, "aria-invalid": this.isInvalid().toString() }, index.h("legend", { key: 'a230416f33f787624f90977054c6492f1516dba6', class: "pn-fieldset-legend" }, this.legend), index.h("p", { key: '6911c6e63588c36bc0e314d7b3c8b81df2282579', id: this.idHelpertext, class: "pn-fieldset-message", hidden: !this.hasHelpertext() }, index.h("span", { key: '3370e13a7cf93741a4aa76880533b11c320aea03' }, this.helpertext), index.h("slot", { key: '0365489d121f3fcfa1211e3c2dcf2881f849940d', name: "helpertext" })), index.h("div", { key: '23d806e61d39d509ad07f0f68c002a1962332bf4', class: "pn-fieldset-items" }, index.h("slot", { key: 'a2ead121001e5f751f779957fbbb44716e64274c' })), index.h("div", { key: '075c709c13a8363be1b1a0b661e3621419a69333', class: "pn-fieldset-error", role: "alert", hidden: !this.hasError() }, index.h("pn-icon", { key: '0c4e969436033de98814135853e51388862e0812', icon: this.getIcon(), color: "warning" }), index.h("p", { key: 'd94095bee0a7e4fdc3962db9666dd4ffba7dfa50', class: "pn-fieldset-message" }, index.h("span", { key: '0c3808a66242f11afdc1ea5053517e965eeb3a93' }, this.error), index.h("slot", { key: 'ad9604de305ce00ef164cc999562707e923bdd83', name: "error" })))))); } static get watchers() { return { "fieldsetId": [{ "handleId": 0 }], "pnId": [{ "handleId": 1 }] }; } }; PnFieldset.style = pnFieldsetCss(); exports.pn_fieldset = PnFieldset;