@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
68 lines (67 loc) • 3.28 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { html as uHtml } from 'uhtml';
// SPDX-License-Identifier: Apache-2.0
import GirafeHTMLElement from '../../base/GirafeHTMLElement.js';
import { UsedInTemplateOnly } from '../../decorators.js';
class HeaderComponent extends GirafeHTMLElement {
templateUrl = null;
styleUrls = null;
template = () => {
return uHtml `<style>
#header{box-sizing:border-box;align-items:center;gap:1rem;height:100%;padding:.15rem 1rem;display:flex}#logo{filter:none;width:auto;height:100%;max-height:100%;display:block}#app-title{color:var(--text-color);-webkit-line-clamp:2;-webkit-box-orient:vertical;min-width:0;font-size:1.3rem;font-weight:700;display:-webkit-box;overflow:hidden} (width<=991px){#app-title{display:none}}
</style>
<style>${this.customStyle}</style>
<div id="header">${this.config.branding.logo !== '' ? uHtml ` <img id="logo" alt="${this.logoAltText}" src="${this.logoSource}"> ` : ''} ${this.config.branding.showAppTitleInHeader ? uHtml `<div id="app-title" i18n="${this.config.branding.appTitle}">${this.config.branding.appTitle}</div>` : ''}</div>
${this.htmlUnsafe(this.feedbackTemplateHtml ?? '')}`;
};
constructor() {
super('header');
}
get config() {
return this.context.configManager.Config;
}
get logoSource() {
if (this.state.interface.darkFrontendMode) {
return this.config.branding.logoDarkMode;
}
return this.config.branding.logo;
}
get logoAltText() {
return `${this.config.branding.appTitle.toLowerCase().replaceAll(' ', '-')}-logo`;
}
setHtmlMetaData() {
const title = this.context.i18nManager.getTranslation(this.config.branding.appTitle);
const description = this.context.i18nManager.getTranslation(this.config.branding.description);
document.title = title;
document.querySelector('meta[name="description"]')?.setAttribute('content', description);
}
registerEvents() {
this.subscribe('language', () => this.setHtmlMetaData());
if (!this.state.interface.isMobile) {
this.subscribe('interface.darkFrontendMode', () => this.refreshRender());
}
}
connectedCallback() {
super.connectedCallback();
this.setHtmlMetaData();
this.render();
super.girafeTranslate();
if (this.state.interface.isMobile) {
// Header shouldn't be visible on mobile
this.hide();
}
this.registerEvents();
}
}
__decorate([
UsedInTemplateOnly()
], HeaderComponent.prototype, "logoSource", null);
__decorate([
UsedInTemplateOnly()
], HeaderComponent.prototype, "logoAltText", null);
export default HeaderComponent;