UNPKG

@postnord/web-components

Version:

PostNord Web Components

81 lines (75 loc) 4.14 kB
/*! * Built with Stencil * By PostNord. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-ec4ed1cc.js'); const helpers = require('./helpers-2e2349b4.js'); const arrow_left = require('./arrow_left-d8f2c601.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 = class { constructor(hostRef) { index.registerInstance(this, hostRef); 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 index.getElement(this); } setMaxWidth() { if (!this.maxWidth) return; this.hostElement.style.setProperty('--max-width', this.maxWidth); } setLanguage() { this.goBackTextTranslated = this.goBackText || translations[this.language || helpers.en]; } async componentWillLoad() { if (this.mo) this.mo.disconnect(); this.mo = new MutationObserver(() => { index.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 helpers.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 (index.h(index.Host, { key: 'cd686ea2ca013f125a319f5f2788c2c225dd9365' }, index.h("header", { key: '7e74404829674f2fe5ad3d3a4750eb747d186e7a', class: "pn-header" }, index.h("div", { key: '3ee0964a234ef68381ea198a17ced4798f5da125', class: "pn-header-container" }, index.h("div", { key: 'e356e0d7c0258bdbb1ebbe3cf3918e1bcf9d0b6a', class: "pn-header-breadcrumbs", hidden: !this.showBreadcrumb() }, this.goBackHref && (index.h("pn-text-link", { key: 'cab2b189eddbc8fa17dbe9da0a4bb48b071e826a', label: this.goBackTextTranslated, href: this.goBackHref, icon: arrow_left.arrow_left, leftIcon: true })), index.h("slot", { key: '414093ad797665dd8d0e6f23fcd12f095f487565', name: "breadcrumb" })), index.h("div", { key: '6e2ddd40d188968e23d3fdb92bf3d45ae6241856', class: "pn-header-content" }, this.heading && index.h("h1", { key: '0e92c8b16cc4a616dde6f2b14ccdff04c802c76b' }, this.heading), index.h("slot", { key: '1d4f83a9f13fa526a61442e4d4664587bd37ae83' })), index.h("div", { key: '31f07187103ed34d6122ee53d4665d96a24099e6', class: "pn-header-buttons", hidden: !this.hasButtons }, index.h("slot", { key: '855d81a1ea7c821ebe3d996ddae20b666c6200ef', name: "buttons" })), index.h("slot", { key: '0553519937c5937322c2e45f35790e38f91ef390', name: "menu" }))))); } static get watchers() { return { "maxWidth": ["setMaxWidth"], "language": ["setLanguage"] }; } }; PnHeader.style = PnHeaderStyle0; exports.pn_header = PnHeader; //# sourceMappingURL=pn-header.cjs.entry.js.map