@postnord/web-components
Version:
PostNord Web Components
79 lines (75 loc) • 4.22 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
import { t as transformTag, r as registerInstance, g as getElement, f as forceUpdate, h, a as Host } from './index-CAEP792y.js';
import { awaitTopbar, en } from './index.js';
import { a as arrow_left } from './arrow_left-CQaMdITw.js';
const pnHeaderCss = () => `${transformTag("pn-header")}{display:block}${transformTag("pn-header")} h1{color:#2d2013;margin:0}${transformTag("pn-header")} p{color:#5e554a;margin:0}${transformTag("pn-header")} .pn-header-breadcrumbs{width:100%}${transformTag("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}${transformTag("pn-header")} .pn-header-container>${transformTag("pn-text-link")}{display:block}${transformTag("pn-header")} .pn-header-content{flex:1 1 auto;display:flex;flex-direction:column;gap:1em}${transformTag("pn-header")} .pn-header [slot=buttons]{display:flex;flex-direction:column;gap:1em}`;
const translations = {
sv: 'Tillbaka',
en: 'Back',
da: 'Tilbage',
fi: 'Takaisin',
no: 'Tilbake',
};
const PnHeader = class {
constructor(hostRef) {
registerInstance(this, hostRef);
}
mo;
hasBreadcrumb = false;
hasButtons = false;
get hostElement() { return getElement(this); }
/** The `h1` text content. */
heading;
/** Set a inner container max-width, any width CSS value is accepted. */
maxWidth;
setMaxWidth() {
if (!this.maxWidth)
return;
this.hostElement.style.setProperty('--max-width', this.maxWidth);
}
/** The href for the go back link. If this is provided a button be displayed. */
goBackHref;
/** The text for the back link. */
goBackText;
/** Set the language manually, only use this prop if the pnTopbar is not loaded. Supported: sv, en, da, fi and no. */
language = null;
connectedCallback() {
this.mo = new MutationObserver(() => {
forceUpdate(this.hostElement);
this.checkSlots();
});
this.mo.observe(this.hostElement, { subtree: true, childList: true });
}
disconnectedCallback() {
this.mo?.disconnect();
}
async componentWillLoad() {
this.checkSlots();
this.setMaxWidth();
if (this.language === null)
await awaitTopbar(this.hostElement);
}
checkSlots() {
this.hasBreadcrumb = !!this.hostElement.querySelector('[slot="breadcrumb"]');
this.hasButtons = !!this.hostElement.querySelector('[slot="buttons"]');
}
showBreadcrumb() {
return this.hasBreadcrumb || !!this.goBackHref?.length;
}
getButtonText() {
return this.goBackText || translations[this.language || en];
}
render() {
return (h(Host, { key: 'f19310a092999791304499d72c1b8e566949c0d3' }, h("header", { key: 'c6b50a1d93bf18f2050b37a9bdf69d3706b8aea4', class: "pn-header" }, h("div", { key: '7bfa1bd37978daf85d266b7306a71705bdc8cac5', class: "pn-header-container" }, h("div", { key: '09ed187b0f201d435c99b3c6e0f245ca48857d47', class: "pn-header-breadcrumbs", hidden: !this.showBreadcrumb() }, this.goBackHref && (h("pn-text-link", { key: 'ba657cb77da06d42009738c64d815a23d8dae527', label: this.getButtonText(), href: this.goBackHref, icon: arrow_left, leftIcon: true })), h("slot", { key: '278bf254489dbd76f53e047cd16c247bcfd696eb', name: "breadcrumb" })), h("div", { key: 'e9b2e873fb9ed01fabbd669aa7cace973a55cbfa', class: "pn-header-content" }, this.heading && h("h1", { key: 'baec009bf6807009ea53d184be9a8c15ea0253a0' }, this.heading), h("slot", { key: '7a777967b19a19077486d88d775b4a1c4f9d3134' })), h("div", { key: '46fa0cc4120b341e4a03c60bb865e077c6231986', class: "pn-header-buttons", hidden: !this.hasButtons }, h("slot", { key: '8932d6bbb5e1647be6b666d1879b163575dfd760', name: "buttons" })), h("slot", { key: 'afc6e39f45ef72ba762772f84a66cc24fdbcf368', name: "menu" })))));
}
static get watchers() { return {
"maxWidth": [{
"setMaxWidth": 0
}]
}; }
};
PnHeader.style = pnHeaderCss();
export { PnHeader as pn_header };