UNPKG

@postnord/web-components

Version:

PostNord Web Components

116 lines (111 loc) 5.3 kB
/*! * Built with Stencil * By PostNord. */ import { proxyCustomElement, HTMLElement, forceUpdate, h, Host } from '@stencil/core/internal/client'; import { e as en, j as awaitTopbar } from './helpers.js'; import { a as arrow_left } from './arrow_left.js'; import { d as defineCustomElement$3 } from './pn-icon2.js'; import { d as defineCustomElement$2 } from './pn-text-link2.js'; const pnHeaderCss = "pn-header{display:block}pn-header h1{color:#2d2013;margin:0}pn-header p{color:#5e554a;margin:0}pn-header .pn-header-breadcrumbs{width:100%}pn-header .pn-header-container{position:relative;width:100%;max-width:var(--max-width);margin:0 auto;padding:clamp(1em, 3vw, 2em) clamp(0.5em, 3vw, 2em);display:flex;flex-wrap:wrap;align-items:center;gap:1.5em}pn-header .pn-header-container>pn-text-link{display:block}pn-header .pn-header-content{flex:1 1 auto;display:flex;flex-direction:column;gap:1em}pn-header .pn-header [slot=buttons]{display:flex;flex-direction:column;gap:1em}"; const PnHeaderStyle0 = pnHeaderCss; const translations = { sv: 'Tillbaka', en: 'Back', da: 'Tilbage', fi: 'Takaisin', no: 'Tilbake', }; const PnHeader$1 = /*@__PURE__*/ proxyCustomElement(class PnHeader extends HTMLElement { constructor() { super(); this.__registerHost(); this.heading = undefined; this.maxWidth = undefined; this.goBackHref = undefined; this.goBackText = undefined; this.language = null; this.goBackTextTranslated = undefined; } mo; hasBreadcrumb = false; hasMenu = false; hasButtons = false; get hostElement() { return this; } setMaxWidth() { if (!this.maxWidth) return; this.hostElement.style.setProperty('--max-width', this.maxWidth); } setLanguage() { this.goBackTextTranslated = this.goBackText || translations[this.language || en]; } async componentWillLoad() { if (this.mo) this.mo.disconnect(); this.mo = new MutationObserver(() => { forceUpdate(this.hostElement); this.checkSlots(); }); this.mo.observe(this.hostElement, { childList: true, subtree: true }); this.checkSlots(); this.setMaxWidth(); this.setLanguage(); if (this.language) return; await awaitTopbar(this.hostElement); } checkSlots() { this.hasBreadcrumb = !!this.hostElement.querySelector('[slot="breadcrumb"]'); this.hasMenu = !!this.hostElement.querySelector('[slot="menu"]'); this.hasButtons = !!this.hostElement.querySelector('[slot="buttons"]'); } showBreadcrumb() { return this.hasBreadcrumb || !!this.goBackHref?.length; } render() { return (h(Host, { key: 'cd686ea2ca013f125a319f5f2788c2c225dd9365' }, h("header", { key: '7e74404829674f2fe5ad3d3a4750eb747d186e7a', class: "pn-header" }, h("div", { key: '3ee0964a234ef68381ea198a17ced4798f5da125', class: "pn-header-container" }, h("div", { key: 'e356e0d7c0258bdbb1ebbe3cf3918e1bcf9d0b6a', class: "pn-header-breadcrumbs", hidden: !this.showBreadcrumb() }, this.goBackHref && (h("pn-text-link", { key: 'cab2b189eddbc8fa17dbe9da0a4bb48b071e826a', label: this.goBackTextTranslated, href: this.goBackHref, icon: arrow_left, leftIcon: true })), h("slot", { key: '414093ad797665dd8d0e6f23fcd12f095f487565', name: "breadcrumb" })), h("div", { key: '6e2ddd40d188968e23d3fdb92bf3d45ae6241856', class: "pn-header-content" }, this.heading && h("h1", { key: '0e92c8b16cc4a616dde6f2b14ccdff04c802c76b' }, this.heading), h("slot", { key: '1d4f83a9f13fa526a61442e4d4664587bd37ae83' })), h("div", { key: '31f07187103ed34d6122ee53d4665d96a24099e6', class: "pn-header-buttons", hidden: !this.hasButtons }, h("slot", { key: '855d81a1ea7c821ebe3d996ddae20b666c6200ef', name: "buttons" })), h("slot", { key: '0553519937c5937322c2e45f35790e38f91ef390', name: "menu" }))))); } static get watchers() { return { "maxWidth": ["setMaxWidth"], "language": ["setLanguage"] }; } static get style() { return PnHeaderStyle0; } }, [4, "pn-header", { "heading": [1], "maxWidth": [1, "max-width"], "goBackHref": [1, "go-back-href"], "goBackText": [1, "go-back-text"], "language": [1], "goBackTextTranslated": [32] }, undefined, { "maxWidth": ["setMaxWidth"], "language": ["setLanguage"] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["pn-header", "pn-icon", "pn-text-link"]; components.forEach(tagName => { switch (tagName) { case "pn-header": if (!customElements.get(tagName)) { customElements.define(tagName, PnHeader$1); } break; case "pn-icon": if (!customElements.get(tagName)) { defineCustomElement$3(); } break; case "pn-text-link": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; } }); } const PnHeader = PnHeader$1; const defineCustomElement = defineCustomElement$1; export { PnHeader, defineCustomElement }; //# sourceMappingURL=pn-header.js.map