@salla.sa/twilight-components
Version:
Salla Web Component
123 lines (122 loc) • 6.71 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 => {
console.log(e);
this.hasError = true;
this.placeholder_description = e.response?.data?.error?.message || e.response?.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: 'ee92769c8a6ef18fa3817c39dbf26a6a4bff23a8', 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: '3d969a0a2c77b8f873dcb934ed2421537cb964e4', slot: 'icon', class: "s-product-size-guide-header-icon", innerHTML: PencilRuler }), h("div", { key: 'e018072d407a6c44f8481c08efc59a991a0eb3fd', slot: "loading" }, h("div", { key: '0667c648322893ad770faf98cebe245917ff63f4', class: "s-product-size-guide-skeleton" }, h("salla-skeleton", { key: '758a611fa61eda549a6decc541c11da1115a2f2f', height: '15px', width: '25%' }), h("div", { key: '8ab9e86a59b4cbb9a03458599a7fef9bd8243573', class: "s-product-size-guide-skeleton-header" }, h("salla-skeleton", { key: '01c47a9a1776c53ce84034bb0c0decf8485fcd6a', height: '40px' }), h("salla-skeleton", { key: '65aee0267fc69e08993fe57df2722dd5b90900ae', height: '40px' }), h("salla-skeleton", { key: '250836e73e41353588a08c15ae619730617a96d3', height: '40px' }), h("salla-skeleton", { key: 'f69fe0eac766ecb7441ea41b43e679921211e8c1', height: '40px' })), h("div", { key: '5e9d83171dba98fb4beb8ab149ae7f075f528c26', class: "s-product-size-guide-skeleton-content" }, h("salla-skeleton", { key: '259f2f0fe3e0e4ed568119ca3967541785b4875d', height: '15px', width: '25%' }), h("salla-skeleton", { key: '0f66a4bc8e1a426f19787775e39fdc526e5635ab', height: '10px', width: '75%' }), h("salla-skeleton", { key: 'ae62c34708c5f4b6ece5eb3caf13b867b2c1e17c', height: '10px', width: '50%' }), h("salla-skeleton", { key: 'c3a03c44c2452d4dd37eaf6d3927e2ae8ef885fd', height: '10px', width: '75%' }), h("salla-skeleton", { key: 'fb42a6a8dd803f8cef6e5990a5f2e17e6e87bbfc', height: '10px', width: '100%' }), h("salla-skeleton", { key: 'b972cba0a06ae46f09fa4c8a352a780e9b620445', height: '10px', width: '25%' }), h("salla-skeleton", { key: 'ac3d5c03485c0d64dc3d868c8f1588565167b60e', height: '10px', width: '60%' }), h("salla-skeleton", { key: 'ec3a83f4eb22bc42d6df5f37bb04b9da54edf309', height: '10px', width: '45%' }), h("salla-skeleton", { key: '62e8d10fae559f7abe3ed3088c03e4fa5e2230b4', height: '10px', width: '30%' })))), h("slot", { key: '59ab1d26dde5103727840c81c4e855638403bf13', 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: 'efd65db973af6678c45c97b5021702dc0585f621', 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"; }
}