@postnord/web-components
Version:
PostNord Web Components
81 lines (75 loc) • 4.14 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-ec4ed1cc.js');
const helpers = require('./helpers-bff6a1c2.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: '8493b17c1f553672941e7bddf7382e3e80377c71' }, index.h("header", { key: '2026f9c75dde59abda45a0e376c24907657fe8e7', class: "pn-header" }, index.h("div", { key: 'dbf01bc588ed38cccb0f951fed4047c9e8192354', class: "pn-header-container" }, index.h("div", { key: '115a52c44b0e5addf49e4807b21adeb84a531de9', class: "pn-header-breadcrumbs", hidden: !this.showBreadcrumb() }, this.goBackHref && (index.h("pn-text-link", { key: 'b2cce5ed46b6dcdb10a72bb806c5a406b6ff5e15', label: this.goBackTextTranslated, href: this.goBackHref, icon: arrow_left.arrow_left, leftIcon: true })), index.h("slot", { key: '27a3d3c38b30cba6d51c79a2c0bd18c6afa13a4c', name: "breadcrumb" })), index.h("div", { key: '8134ae8b844e9db548cb3db6bf995479c404fff1', class: "pn-header-content" }, this.heading && index.h("h1", { key: '3bf46740c66ca137adbc50fe6cdde178e82bfdbc' }, this.heading), index.h("slot", { key: '94ee53b3dee5a388ef84ae91c54a5b96c14a2661' })), index.h("div", { key: 'd44728888d295fd84285b28102b348da90ba5d80', class: "pn-header-buttons", hidden: !this.hasButtons }, index.h("slot", { key: '7af9da3f81bedb69639f7f723c24d93caebaba24', name: "buttons" })), index.h("slot", { key: '6c55a22b94293e59c8fdb33906c2d4612d067cc4', name: "menu" })))));
}
static get watchers() { return {
"maxWidth": ["setMaxWidth"],
"language": ["setLanguage"]
}; }
};
PnHeader.style = PnHeaderStyle0;
exports.pn_header = PnHeader;
//# sourceMappingURL=pn-header.cjs.entry.js.map