@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: '7f3163771a6fe805ee75842c83c792b6a7dd0a2b', 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: '6358583b137c5aa191d0b0b5a3f91a8934340271', slot: 'icon', class: "s-product-size-guide-header-icon", innerHTML: PencilRuler }), h("div", { key: 'de9f920cd4c75f8089c7f3c426965e4551ffc77b', slot: "loading" }, h("div", { key: '67cb37e30e211233c10b14ad4d91bc5c5b24da6d', class: "s-product-size-guide-skeleton" }, h("salla-skeleton", { key: '28cca753f94de6eaee5dce72929d0df79ee5fa04', height: '15px', width: '25%' }), h("div", { key: 'a5281ef076771baaca25938ee50d16ab2d720753', class: "s-product-size-guide-skeleton-header" }, h("salla-skeleton", { key: 'a1d4a72b246a6a47c7b7d4bdbbb9404f00cda07f', height: '40px' }), h("salla-skeleton", { key: '1928477107338585e9ede41e2770b2269af3931c', height: '40px' }), h("salla-skeleton", { key: 'f8066e7ea05f580eec61529cfe24f3610b009ac6', height: '40px' }), h("salla-skeleton", { key: '3fdc216da7789b27061a2a9ef7f0abe96677d7c1', height: '40px' })), h("div", { key: '957b3b2951821bfd8bf6d382777a9f680c4e36ed', class: "s-product-size-guide-skeleton-content" }, h("salla-skeleton", { key: '49f609d34eae8f4c0256a559bd12396bdbd4b996', height: '15px', width: '25%' }), h("salla-skeleton", { key: '2c20035b717f0b35212b066f39030bfbd17a597b', height: '10px', width: '75%' }), h("salla-skeleton", { key: '2e003fe9f76575c9b60b0aa86d650091213d8bb7', height: '10px', width: '50%' }), h("salla-skeleton", { key: 'ae28bd7c1770938e2a02b23a960bad255d59329e', height: '10px', width: '75%' }), h("salla-skeleton", { key: '3737f5b2d81b852e4c2b269bd61e73740341e32a', height: '10px', width: '100%' }), h("salla-skeleton", { key: 'e7e82f9ba968478ab38b1e9db94a98f2162b4e73', height: '10px', width: '25%' }), h("salla-skeleton", { key: 'd97efa180720f9ac39fa9bdb17f73cc27fb4a3f0', height: '10px', width: '60%' }), h("salla-skeleton", { key: 'ff3934e9aa7f58cbec9b42c772f7ee30e7cd69ea', height: '10px', width: '45%' }), h("salla-skeleton", { key: '5bc02f885b39fd6585a40f38299610e181414c43', height: '10px', width: '30%' })))), h("slot", { key: 'b8d469ede8c64d77c57888b08b749e5642da90b1', 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: '04df3ec4386e0beff2d18cc9df73dc427e9cf507', 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"; }
}