UNPKG

@postnord/web-components

Version:

PostNord Web Components

61 lines (56 loc) 2.37 kB
/*! * Built with Stencil * By PostNord. */ import { proxyCustomElement, HTMLElement, forceUpdate, h, Host } from '@stencil/core/internal/client'; const pnAccordionCss = "pn-accordion{position:relative;background-color:#ffffff;display:flex;align-items:stretch;flex-direction:column;gap:0.25em}pn-accordion>pn-accordion-row+pn-accordion-row:after{content:\"\";position:absolute;top:-0.125em;left:0.25em;width:calc(100% - 0.5em);height:0;border-top:0.0625em solid #d3cecb}"; const PnAccordionStyle0 = pnAccordionCss; const PnAccordion$1 = /*@__PURE__*/ proxyCustomElement(class PnAccordion extends HTMLElement { constructor() { super(); this.__registerHost(); } mo; closeEvent = new CustomEvent('rowstate', { detail: false }); get hostElement() { return this; } /** Only allow a single row to be open at once. */ single = false; connectedCallback() { this.mo = new MutationObserver(() => forceUpdate(this.hostElement)); this.mo.observe(this.hostElement, { childList: true, subtree: true }); } disconnectedCallback() { this.mo.disconnect(); } handleSingleRow({ detail }) { if (!this.single) return; const element = detail.element; const activeRow = element.closest('pn-accordion-row'); const rows = Array.from(this.hostElement.querySelectorAll('pn-accordion-row')); rows.forEach(row => !row.isSameNode(activeRow) && row.dispatchEvent(this.closeEvent)); } render() { return (h(Host, { key: '800bf9af052f84af2f2fa3ec4e2351e8fd54da89' }, h("slot", { key: '53c8eac1eda11eda881f50b37476f3600ea3897b' }))); } static get style() { return PnAccordionStyle0; } }, [4, "pn-accordion", { "single": [4] }, [[0, "togglerow", "handleSingleRow"]]]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["pn-accordion"]; components.forEach(tagName => { switch (tagName) { case "pn-accordion": if (!customElements.get(tagName)) { customElements.define(tagName, PnAccordion$1); } break; } }); } const PnAccordion = PnAccordion$1; const defineCustomElement = defineCustomElement$1; export { PnAccordion, defineCustomElement }; //# sourceMappingURL=pn-accordion.js.map