@salla.sa/twilight-components
Version:
Salla Web Component
48 lines (47 loc) • 2.81 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { Host, h } from "@stencil/core";
import Cancel from "../../assets/svg/cancel.svg";
export class SallaMaintenanceAlert {
componentWillLoad() {
this.title = salla.config.get('maintenance_details.title');
this.message = salla.config.get('maintenance_details.message');
// Use matchMedia instead of window.innerWidth to avoid forced reflow (Lighthouse/PageSpeed)
const isMobile = typeof window !== 'undefined' && !window.matchMedia('(min-width: 768px)').matches;
this.buttonTitle = isMobile ? salla.config.get('maintenance_details.button_title') : salla.config.get('maintenance_details.button_full_title');
}
closeAlert() {
salla.storage.set('hide_salla-maintenance-alert_at', Date.now());
this.host.style.display = 'none';
}
render() {
return (h(Host, { key: '4e41b03a4ebe9b05b15f499128fbaef8a2665a1e', class: "s-maintenance-alert-wrapper" }, h("button", { key: 'c45b83d1381d7e98adca32d92531c181ae9281e4', class: "s-maintenance-alert-close", innerHTML: Cancel, onClick: () => this.closeAlert() }), h("div", { key: 'c48a139c8bfc999bfce517ac689c2c5be8a8a70a', class: "s-maintenance-alert-content" }, h("div", { key: '75a52a15cc98759c7646a37e61822c7392256743', class: "s-maintenance-alert-container" }, h("div", { key: 'c2151b20d570186d3be79ea440d03e3044766544', class: "s-maintenance-alert-icon" }, h("img", { key: '9752b18e5fce36412448a941ba90b3332ac185fa', src: salla.url.cdn('images/alert.png'), alt: "Alert" })), h("div", { key: '23d13d46adb0d89c31aa28666a0664253cbd5d6b', class: "s-maintenance-alert-text" }, h("h2", { key: 'abdb593bfd90571dee3ee9f918640fbf508a2d69' }, this.title), h("p", { key: '6c0bd117d161add2abadfadd5f344572c2596f6f' }, this.message))), h("div", { key: '5d6c815b7fa86822665a16a588fa02da19e62ca8' }, h("a", { key: '90c6ff46c169e685cff7becae06b7e67042e9d41', class: "s-maintenance-alert-btn", href: salla.config.get('maintenance_details.button_url') }, this.buttonTitle)))));
}
componentDidLoad() {
//auto-hide the alert if close button is clicked before one hour
let hidden_at = salla.storage.get('hide_salla-maintenance-alert_at');
if (hidden_at && ((Date.now() - hidden_at) / 1000 / 60) < 60) {
this.closeAlert();
}
}
static get is() { return "salla-maintenance-alert"; }
static get originalStyleUrls() {
return {
"$": ["salla-maintenance-alert.scss"]
};
}
static get styleUrls() {
return {
"$": ["salla-maintenance-alert.css"]
};
}
static get states() {
return {
"title": {},
"message": {},
"buttonTitle": {}
};
}
static get elementRef() { return "host"; }
}