@salla.sa/twilight-components
Version:
Salla Web Component
125 lines (124 loc) • 6.99 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { h } from "@stencil/core";
import PencilRuler from "../../assets/svg/pencil-ruler.svg";
/**
* @slot header - The upper section of the component.Empty by default.
* @slot footer - The bottom section of the component.Empty by default.
*/
export class SallaProductSizeGuide {
constructor() {
this.hasError = false;
salla.event.on('size-guide::open', (product_id) => this.open(product_id));
salla.lang.onLoaded(() => {
this.placeholder_title = salla.lang.get('pages.products.size_guide_placeholder');
this.placeholder_description = salla.lang.get('pages.products.size_guide_placeholder_info');
this.modal_title = salla.lang.get('pages.products.size_guides');
});
}
/**
* Show the size-guide modal window
*/
async open(product_id) {
this.modal.setTitle(this.modal_title);
this.modal.open();
return await salla.api.withoutNotifier(() => salla.product.getSizeGuides(product_id))
.then((response) => {
this.guides = response.data;
})
.catch(e => {
var _a, _b, _c, _d;
console.log(e);
this.hasError = true;
this.placeholder_description = ((_c = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) || ((_d = e.response) === null || _d === void 0 ? void 0 : _d.data);
})
.finally(() => this.modal.stopLoading());
}
/**
*
* Hide the size-guide modal window
*/
async close() {
return this.modal.close();
}
showPlaceholder() {
return h("salla-placeholder", { alignment: "center", iconSize: "xl" }, h("div", { slot: "title" }, this.placeholder_title), h("div", { slot: "description" }, this.placeholder_description));
}
render() {
return (h("salla-modal", { key: '1d068fa2f066803af16ffaa112e26ce100b89688', class: "s-product-size-guide-wrapper", id: 'salla-product-size-guide-modal', isLoading: true, "has-skeleton": true, width: "md", ref: modal => this.modal = modal }, h("span", { key: '364fbc029b05351b13e689703eddb7b93428b2a1', slot: 'icon', class: "s-product-size-guide-header-icon", innerHTML: PencilRuler }), h("div", { key: '18a48cffb065119c126d034a61ebce882ff57601', slot: "loading" }, h("div", { key: '183e7b9882257f2b2fbe97c477955882f2544fee', class: "s-product-size-guide-skeleton" }, h("salla-skeleton", { key: '5d8db1b8ceb894d935364b02b11480b1f5204904', height: '15px', width: '25%' }), h("div", { key: '36fa82f8dcfb507391e8ae596ea7f689d5b2f2e5', class: "s-product-size-guide-skeleton-header" }, h("salla-skeleton", { key: '478c1efbcf3b85dfc7a95837b6ac3eed50bbf050', height: '40px' }), h("salla-skeleton", { key: 'e5de9d2745bc7b7a891e03e499feb57ea0e59633', height: '40px' }), h("salla-skeleton", { key: 'eff6539ba1d9b692322b2e9e9f1e4e90c6685bf1', height: '40px' }), h("salla-skeleton", { key: '84a9cd41423f9fa405c0a6da192a2af78eae3f9e', height: '40px' })), h("div", { key: '391ad1a9fb9879a9c6985562427dc76d64a7184a', class: "s-product-size-guide-skeleton-content" }, h("salla-skeleton", { key: '2880ffe6d56a34cb6758331a26b943f41d6d0732', height: '15px', width: '25%' }), h("salla-skeleton", { key: '045f0b4b90e2b0cdf76f8824afa3b3edd8883acf', height: '10px', width: '75%' }), h("salla-skeleton", { key: '68b2200b765fac6e01f8fea0f6df938b8b5da1c7', height: '10px', width: '50%' }), h("salla-skeleton", { key: '9abed0c186180114e0412f98cab8003ee6e8305e', height: '10px', width: '75%' }), h("salla-skeleton", { key: '162ad766e7d777a28a04377a532d04bbdab1233f', height: '10px', width: '100%' }), h("salla-skeleton", { key: '6ee20556d6998ed44979040a4959fe5e3ea5016d', height: '10px', width: '25%' }), h("salla-skeleton", { key: 'fb1c535bd3461a10855c070a09502a3e3a0c8c3b', height: '10px', width: '60%' }), h("salla-skeleton", { key: '3cc8a3830bc3efcd41c004f401043dc24395ffdc', height: '10px', width: '45%' }), h("salla-skeleton", { key: '186d3f1ac166c5cc030b8dcb43668d05e2575f24', height: '10px', width: '30%' })))), h("slot", { key: '7bc87c465003c57b129009c5381039d91676055b', name: "header" }), !this.hasError && !!this.guides ?
[
h("salla-tabs", null, this.guides.map((guide) => h("salla-tab-header", { slot: "header", name: guide.name }, h("span", null, guide.name))), this.guides.map((guide) => h("salla-tab-content", { slot: "content", name: guide.name }, h("div", { innerHTML: guide.description }))))
]
: this.showPlaceholder(), h("slot", { key: 'bd73fec471ce8a641ca0cba79a359354b82743b1', name: "footer" })));
}
static get is() { return "salla-product-size-guide"; }
static get originalStyleUrls() {
return {
"$": ["salla-product-size-guide.scss"]
};
}
static get styleUrls() {
return {
"$": ["salla-product-size-guide.css"]
};
}
static get states() {
return {
"guides": {},
"productId": {},
"placeholder_title": {},
"placeholder_description": {},
"modal_title": {},
"hasError": {}
};
}
static get methods() {
return {
"open": {
"complexType": {
"signature": "(product_id: number) => Promise<any>",
"parameters": [{
"name": "product_id",
"type": "number",
"docs": ""
}],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<any>"
},
"docs": {
"text": "Show the size-guide modal window",
"tags": []
}
},
"close": {
"complexType": {
"signature": "() => Promise<HTMLElement>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
},
"HTMLElement": {
"location": "global",
"id": "global::HTMLElement"
}
},
"return": "Promise<HTMLElement>"
},
"docs": {
"text": "\nHide the size-guide modal window",
"tags": []
}
}
};
}
static get elementRef() { return "host"; }
}
//# sourceMappingURL=salla-product-size-guide.js.map