@salla.sa/twilight-components
Version:
Salla Web Component
79 lines (74 loc) • 4.55 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { r as registerInstance, h } from './index-114c614f.js';
import { a as arrowLeft } from './arrow-left-3ba30fe6.js';
import { H as Helper } from './Helper-895025d9.js';
import './anime.es-6b92d9cd.js';
const IconQuoteOpen = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>quote-open</title>
<path d="M8 12v-5.333c0-0.737-0.596-1.333-1.333-1.333-3.676 0-6.667 2.991-6.667 6.667v8c0 3.676 2.991 6.667 6.667 6.667h1.333c3.676 0 6.667-2.991 6.667-6.667v-1.333c0-3.676-2.991-6.667-6.667-6.667zM12 20c0 2.205-1.795 4-4 4h-1.333c-2.205 0-4-1.795-4-4v-8c0-1.739 1.115-3.221 2.667-3.772v5.105c0 0.737 0.596 1.333 1.333 1.333h1.333c2.205 0 4 1.795 4 4zM25.333 12v-5.333c0-0.737-0.596-1.333-1.333-1.333-3.676 0-6.667 2.991-6.667 6.667v8c0 3.676 2.991 6.667 6.667 6.667h1.333c3.676 0 6.667-2.991 6.667-6.667v-1.333c0-3.676-2.991-6.667-6.667-6.667zM29.333 20c0 2.205-1.795 4-4 4h-1.333c-2.205 0-4-1.795-4-4v-8c0-1.739 1.115-3.221 2.667-3.772v5.105c0 0.737 0.596 1.333 1.333 1.333h1.333c2.205 0 4 1.795 4 4z"></path>
</svg>
`;
const sallaReviewsCss = "";
const SallaReviews = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.displayAllURL = null;
this.displayAllLink = undefined;
this.source = undefined;
this.sourceValue = undefined;
this.limit = 5;
this.type = "store";
this.sort = "latest";
this.hideCustomerInfo = false;
this.reviews = [];
this.isRTL = undefined;
this.showReviews = false;
this.testimonialText = salla.lang.get('blocks.home.testimonials');
this.displayAllLinkText = salla.lang.get('blocks.home.display_all');
this.source = this.source;
salla.onReady(() => {
this.displayAllURL = salla.url.get('testimonials');
this.isRTL = salla.config.get('theme.is_rtl', true);
});
salla.lang.onLoaded(() => {
this.testimonialText = salla.lang.get('blocks.home.testimonials');
this.displayAllLinkText = salla.lang.get('blocks.home.display_all');
});
}
fetchReviews() {
if (this.source === 'json') {
return Promise.resolve(JSON.parse(this.sourceValue));
}
const isJsonEncoded = ['products', 'categories'].includes(this.source);
const params = {
limit: this.limit,
source: this.source,
items: isJsonEncoded ? JSON.parse(this.sourceValue) : this.sourceValue,
sort: this.sort,
type: this.type,
hide_customer_info: this.hideCustomerInfo ? 1 : 0
};
return salla.api.request('reviews', { params }, 'get');
}
componentWillLoad() {
return (new Promise(resolve => salla.onReady(resolve)))
.then(() => this.fetchReviews())
.then((resp) => resp.data || [])
.then(reviews => {
if (reviews.length) {
this.reviews = reviews;
this.showReviews = true;
Helper.generateReviewSchema(this.reviews);
}
});
}
render() {
return (h("div", { class: "s-reviews-container" }, h("div", { class: "s-reviews-header-wrapper" }, h("h1", { class: "s-reviews-header" }, this.testimonialText), !!this.displayAllLink ? (h("a", { href: this.displayAllURL, class: "s-reviews-display-all" }, this.displayAllLinkText, h("span", { class: "s-reviews-display-all-icon", innerHTML: arrowLeft }))) : null), h("salla-slider", { centered: true, "slides-per-view": 1, type: "testimonials", class: "s-reviews-testimonials-slider", "controls-outer": true, "auto-play": true, id: `testimonials-${this.source}-slider` }, h("div", { slot: "items" }, this.reviews.map((item, index) => (h("div", { key: index, class: "s-reviews-swiper-slide" }, h("div", { class: "s-reviews-testimonial" }, h("div", { class: "s-reviews-testimonial__inner" }, h("div", { class: "s-reviews-testimonial__avatar" }, h("img", { src: 'images/s-empty.png', "data-src": item.avatar, alt: item.name ? item.name : 'testimonial-' + index, class: "lazy" })), h("div", { class: "s-reviews-testimonial__text" }, h("p", { innerHTML: item.content }), h("div", { class: "s-reviews-testimonial__name_wrapper" }, h("div", { class: "s-reviews-testimonial__info" }, item.name && h("h2", null, `${item.name}`)), h("div", { class: "s-reviews-testimonial__rating" }, h("salla-rating-stars", { size: "small", value: item.stars })))), h("span", { class: "s-reviews-testimonial__icon", innerHTML: IconQuoteOpen }))))))))));
}
};
SallaReviews.style = sallaReviewsCss;
export { SallaReviews as salla_reviews };
//# sourceMappingURL=salla-reviews.entry.js.map