@salla.sa/twilight-components
Version:
Salla Web Component
70 lines (64 loc) • 5.43 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { s as setTranslations } from './translations.js';
var MoneyIcon = `<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.76604 2.86201C9.31804 2.61001 9.93304 2.41501 10.611 2.27701C11.289 2.13901 12 2.07001 12.744 2.07001C13.572 2.07001 14.364 2.15401 15.12 2.32201C15.84 2.49001 16.356 2.81401 16.668 3.29401C16.932 3.70201 17.064 4.26001 17.064 4.96801V13.032C17.064 13.416 16.95 13.752 16.722 14.04C16.506 14.304 16.227 14.493 15.885 14.607C15.543 14.721 15.204 14.742 14.868 14.67C14.196 14.514 13.488 14.436 12.744 14.436C12.084 14.436 11.442 14.502 10.818 14.634C10.23 14.754 9.70204 14.922 9.23404 15.138C8.68204 15.39 8.06704 15.585 7.38904 15.723C6.71104 15.861 6.00004 15.93 5.25604 15.93C4.42804 15.93 3.63604 15.846 2.88004 15.678C2.18404 15.522 1.68004 15.21 1.36804 14.742C1.08004 14.322 0.936035 13.752 0.936035 13.032V4.96801C0.936035 4.58401 1.05004 4.24801 1.27804 3.96001C1.49404 3.69601 1.77304 3.50701 2.11504 3.39301C2.45704 3.27901 2.79604 3.25801 3.13204 3.33001C3.80404 3.48601 4.51204 3.56401 5.25604 3.56401C5.91604 3.56401 6.55804 3.49801 7.18204 3.36601C7.77004 3.24601 8.29804 3.07801 8.76604 2.86201ZM11.25 9.00001C11.25 8.59201 11.148 8.21701 10.944 7.87501C10.74 7.53301 10.467 7.26001 10.125 7.05601C9.78304 6.85201 9.40804 6.75001 9.00004 6.75001C8.59204 6.75001 8.21704 6.85201 7.87504 7.05601C7.53304 7.26001 7.26004 7.53301 7.05604 7.87501C6.85204 8.21701 6.75004 8.59201 6.75004 9.00001C6.75004 9.40801 6.85204 9.78301 7.05604 10.125C7.26004 10.467 7.53304 10.74 7.87504 10.944C8.21704 11.148 8.59204 11.25 9.00004 11.25C9.40804 11.25 9.78304 11.148 10.125 10.944C10.467 10.74 10.74 10.467 10.944 10.125C11.148 9.78301 11.25 9.40801 11.25 9.00001ZM14.328 7.79401C14.076 7.75801 13.812 7.73401 13.536 7.72201C13.38 7.71001 13.245 7.75501 13.131 7.85701C13.017 7.95901 12.954 8.08801 12.942 8.24401C12.93 8.40001 12.975 8.53501 13.077 8.64901C13.179 8.76301 13.308 8.82601 13.464 8.83801C13.704 8.85001 13.938 8.87401 14.166 8.91001C14.322 8.93401 14.463 8.90101 14.589 8.81101C14.715 8.72101 14.787 8.59801 14.805 8.44201C14.823 8.28601 14.787 8.14501 14.697 8.01901C14.607 7.89301 14.484 7.81801 14.328 7.79401ZM4.53604 9.16201C4.29604 9.15001 4.06204 9.12601 3.83404 9.09001C3.67804 9.06601 3.53704 9.09901 3.41104 9.18901C3.28504 9.27901 3.21304 9.40201 3.19504 9.55801C3.17704 9.71401 3.21304 9.85501 3.30304 9.98101C3.39304 10.107 3.51604 10.182 3.67204 10.206C3.92404 10.242 4.18804 10.266 4.46404 10.278C4.62004 10.29 4.75504 10.245 4.86904 10.143C4.98304 10.041 5.04604 9.91201 5.05804 9.75601C5.07004 9.60001 5.02504 9.46501 4.92304 9.35101C4.82104 9.23701 4.69204 9.17401 4.53604 9.16201Z" fill="white"/>
</svg>
`;
const sallaLoyaltyPointsBannerCss = "";
const SallaLoyaltyPointsBanner$1 = /*@__PURE__*/ proxyCustomElement(class SallaLoyaltyPointsBanner extends HTMLElement {
constructor() {
super();
this.__registerHost();
this.pointsData = null;
this.productId = null;
}
async componentWillLoad() {
try {
await salla.onReady();
await salla.lang.onLoaded();
await setTranslations();
this.productId = this.host.dataset.productId || salla.config.get('page.id');
if (!this.productId) {
return;
}
const response = await salla.api
.request(`/loyalty/products/${this.productId}/points`)
.catch(() => null);
this.pointsData = response?.data || null;
}
catch (e) {
salla?.logger?.warn?.('salla-loyalty-points-banner: init failed', e);
}
}
render() {
if (!this.productId || !this.pointsData?.points) {
return null;
}
return (h(Host, null, h("div", { class: "s-loyalty-points-banner-container" }, h("div", { class: "s-loyalty-points-banner-icon" }, h("span", { class: "s-loyalty-points-banner-inner-icon", innerHTML: MoneyIcon })), h("p", null, h("span", { class: "s-loyalty-points-banner-label" }, salla.lang.get('pages.loyalty_program.earn'), ' '), h("span", { class: "s-loyalty-points-banner-label" }, `+${this.pointsData.points}`, " "), h("span", { class: "s-loyalty-points-banner-label" }, salla.lang.get('pages.loyalty_program.loyalty_point'), ' '), h("span", { class: "s-loyalty-points-banner-description" }, salla.lang.get('pages.loyalty_program.on_order_total_when_purchase'))))));
}
get host() { return this; }
static get style() { return sallaLoyaltyPointsBannerCss; }
}, [0, "salla-loyalty-points-banner", {
"pointsData": [32],
"productId": [32]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["salla-loyalty-points-banner"];
components.forEach(tagName => { switch (tagName) {
case "salla-loyalty-points-banner":
if (!customElements.get(tagName)) {
customElements.define(tagName, SallaLoyaltyPointsBanner$1);
}
break;
} });
}
defineCustomElement$1();
const SallaLoyaltyPointsBanner = SallaLoyaltyPointsBanner$1;
const defineCustomElement = defineCustomElement$1;
export { SallaLoyaltyPointsBanner, defineCustomElement };