@salla.sa/twilight-components
Version:
Salla Web Component
221 lines (220 loc) • 10.9 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { Host, h } from "@stencil/core";
import infoIcon from "../../assets/svg/info.svg";
import shoppingBag from "../../assets/svg/shopping-bag2.svg";
export class SallaBottomAlert {
constructor() {
this.storeId = salla.config.get('store.id');
this.template = salla.config.get('store.template');
this.loading = false;
this.templateData = {};
this.defaultMessage = salla.lang.get('common.elements.experimental_and_available_store');
this.defaultActionLabel = salla.lang.get('common.elements.know_more');
this.storeFeatures = salla.lang.get('common.elements.store_features');
this.storeDetails = salla.lang.get('common.elements.store_details');
this.storePrice = salla.lang.getWithDefault('common.elements.store_price', 'سعر المتجر');
this.theDeveloper = salla.lang.get('common.elements.the_developer');
this.templateInformation = salla.lang.get('common.elements.template_information');
this.buyTheTemplate = salla.lang.get('common.elements.buy_the_template');
this.isRtl = salla.config.get('theme.is_rtl', true);
this.type = 'popup';
this.icon = undefined;
this.message = undefined;
this.actionUrl = undefined;
this.actionLabel = undefined;
salla.lang.onLoaded(() => {
this.defaultMessage = salla.lang.get('common.elements.experimental_and_available_store');
this.defaultActionLabel = salla.lang.get('common.elements.know_more');
this.storeFeatures = salla.lang.get('common.elements.store_features');
this.storeDetails = salla.lang.get('common.elements.store_details');
this.templateInformation = salla.lang.get('common.elements.template_information');
this.buyTheTemplate = salla.lang.get('common.elements.buy_the_template');
salla.helpers.setNested(salla.lang.messages['ar.trans'], 'common.elements.store_price', 'سعر المتجر');
salla.helpers.setNested(salla.lang.messages['en.trans'], 'common.elements.store_price', 'Store Price');
salla.helpers.setNested(salla.lang.messages['ar.trans'], 'common.elements.the_developer', 'المطور');
salla.helpers.setNested(salla.lang.messages['en.trans'], 'common.elements.the_developer', 'the developer');
setTimeout(() => {
this.storePrice = salla.lang.get('common.elements.store_price');
this.theDeveloper = salla.lang.get('common.elements.the_developer');
}, 100);
});
}
open() {
return this.modal.open()
.then(() => this.handleTemplateRequest());
}
getDefaultMessage() {
return this.isRtl ? this.defaultMessage.substring(0, this.defaultMessage.lastIndexOf(" ")) : this.defaultMessage.split(" ").slice(0, -2).join(" ");
}
handleTemplateRequest() {
if (Object.keys(this.templateData).length) {
return;
}
this.modal.loading();
return salla.api.request(`/store/template`, {}, 'get', { 'Store-Identifier': this.storeId })
.then((res) => {
this.modal.setTitle(this.templateInformation);
this.templateData = res.data;
this.modal.stopLoading();
})
.catch(() => {
this.modal.close();
});
}
handleAction() {
if (this.type === 'link') {
window.location.href = this.actionUrl;
}
if (this.type === 'popup') {
this.open();
}
}
popup() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
return (h("salla-modal", { class: "s-bottom-alert-modal", ref: modal => this.modal = modal, "no-padding": true }, Object.keys(this.templateData).length ?
[h("div", { class: "s-bottom-alert-modal-inner s-scrollbar" }, Array.isArray((_a = this.templateData) === null || _a === void 0 ? void 0 : _a.screenshots) && ((_c = (_b = this.templateData) === null || _b === void 0 ? void 0 : _b.screenshots) === null || _c === void 0 ? void 0 : _c.length) ? h("div", { class: "s-bottom-alert-modal-cover" }, h("img", { src: (_d = this.templateData) === null || _d === void 0 ? void 0 : _d.screenshots[0], alt: "" })) : '', h("div", { class: { "s-bottom-alert-modal-content": true, "s-bottom-alert-modal-content-extra-padding": this.templateData.price } }, ((_e = this.templateData) === null || _e === void 0 ? void 0 : _e.description) ?
[h("div", { class: "s-bottom-alert-modal-content-title" }, this.storeDetails), h("div", { class: "s-bottom-alert-modal-content-description", innerHTML: (_f = this.templateData) === null || _f === void 0 ? void 0 : _f.description }), h("hr", null)
] : '', ((_g = this.templateData) === null || _g === void 0 ? void 0 : _g.features) ? [h("div", { class: "s-bottom-alert-modal-content-title" }, this.storeFeatures), h("div", { class: "s-bottom-alert-modal-content-features", innerHTML: (_h = this.templateData) === null || _h === void 0 ? void 0 : _h.features })
] : '', Array.isArray((_j = this.templateData) === null || _j === void 0 ? void 0 : _j.screenshots) && ((_l = (_k = this.templateData) === null || _k === void 0 ? void 0 : _k.screenshots) === null || _l === void 0 ? void 0 : _l.length) > 1 ?
h("salla-slider", { id: 'template-screenshots', type: 'carousel', class: "s-bottom-alert-modal-content-screenshots" }, h("div", { slot: 'items' }, (_m = this.templateData) === null || _m === void 0 ? void 0 : _m.screenshots.map((screenshot) => {
return h("div", { class: "s-bottom-alert-modal-content-screenshot" }, h("img", { src: screenshot, alt: "" }));
})))
: '', ((_o = this.templateData) === null || _o === void 0 ? void 0 : _o.extra_info) ?
h("div", { class: "s-bottom-alert-modal-content-description", innerHTML: (_p = this.templateData) === null || _p === void 0 ? void 0 : _p.description })
: ''), ((_q = this.templateData) === null || _q === void 0 ? void 0 : _q.link) ?
h("div", { class: "s-bottom-alert-modal-content-footer" }, this.templateData.price && h("div", { class: "s-bottom-alert-modal-price-wrapper" }, h("div", null, this.storePrice), h("div", { class: "s-bottom-alert-modal-price-wrapper-amount" }, salla.money((_r = this.templateData) === null || _r === void 0 ? void 0 : _r.price))), h("salla-button", { color: 'primary', size: "medium", width: 'wide', href: (_s = this.templateData) === null || _s === void 0 ? void 0 : _s.link }, h("i", { innerHTML: shoppingBag }), this.buyTheTemplate)) : '')] : ''));
}
render() {
const hasTemplate = this.template && typeof this.template === 'object' && Object.keys(this.template).length > 0;
const developer = hasTemplate && this.template.developer;
const hasDeveloper = developer !== undefined;
const developerName = hasDeveloper && (developer === null || developer === void 0 ? void 0 : developer.name);
const developerUrl = null; //hasDeveloper && developer.url;
return (h(Host, { class: "s-bottom-alert-wrapper" }, h("div", { class: "s-bottom-alert-content" }, h("div", { class: "s-bottom-alert-icon" }, this.icon ? h("i", { class: this.icon }) : h("i", { innerHTML: infoIcon })), h("div", { class: "s-bottom-alert-message" }, this.message ? (this.message) : hasTemplate ? (h("span", null, this.getDefaultMessage(), " ", h("a", { href: developerUrl ? developerUrl : "#", class: {
"s-bottom-alert-message-highlight": true,
"s-bottom-alert-message-link": developerUrl,
}, target: developerUrl ? "_blank" : "", "aria-label": "Developer" }, developerName ? developerName : this.theDeveloper), " ", h("span", { class: "s-bottom-alert-message-splitter" }, "|"), " ", this.storePrice, ":", " ", h("span", { class: "s-bottom-alert-message-highlight" }, salla.money(this.template.price)))) : (this.defaultMessage)), this.type !== 'banner' && (h("div", { class: "s-bottom-alert-action" }, h("salla-button", { href: this.actionUrl, size: "medium", onClick: () => this.handleAction(), width: "normal" }, this.actionLabel || this.defaultActionLabel))), this.type === 'popup' && this.popup())));
}
static get is() { return "salla-bottom-alert"; }
static get originalStyleUrls() {
return {
"$": ["salla-bottom-alert.scss"]
};
}
static get styleUrls() {
return {
"$": ["salla-bottom-alert.css"]
};
}
static get properties() {
return {
"type": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'link' | 'popup' | 'banner'",
"resolved": "\"banner\" | \"link\" | \"popup\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Alert Type"
},
"attribute": "type",
"reflect": true,
"defaultValue": "'popup'"
},
"icon": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Alert Icon class from salla icons library - ex: sicon-user"
},
"attribute": "icon",
"reflect": true
},
"message": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Alert Message"
},
"attribute": "message",
"reflect": true
},
"actionUrl": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Button url - used when type is link"
},
"attribute": "action-url",
"reflect": true
},
"actionLabel": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Button label - used when type is link and popup"
},
"attribute": "action-label",
"reflect": true
}
};
}
static get states() {
return {
"storeId": {},
"template": {},
"loading": {},
"templateData": {},
"defaultMessage": {},
"defaultActionLabel": {},
"storeFeatures": {},
"storeDetails": {},
"storePrice": {},
"theDeveloper": {},
"templateInformation": {},
"buyTheTemplate": {},
"isRtl": {}
};
}
static get elementRef() { return "host"; }
}
//# sourceMappingURL=salla-bottom-alert.js.map