/** * * Testimonial component * * */ import { SkhemataBase, html, property, CSSResult } from '@skhemata/skhemata-base'; // Import custom style elements // Import element dependencies import { stringToHtml } from '@skhemata/skhemata-base/dist/directives/stringToHtml.js'; // Import Icon import { faUser, faQuoteLeft } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@riovir/wc-fontawesome'; import { SkhemataTestimonialStyle } from './style/SkhemataTestimonialStyle'; /** * Use the customElement decorator to define your class as * a custom element. Registers as an HTML tag. */ export class SkhemataTestimonial extends SkhemataBase { // Component specific properties @property({ type: Number, attribute: 'interval' }) carouselInterval = 5000; @property({ type: Number, attribute: 'active-testimonial' }) activeTestimonial = 0; static get scopedElements() { return { 'fa-icon': FontAwesomeIcon, }; } static get styles() { return [...super.styles, SkhemataTestimonialStyle]; } async firstUpdated() { await super.firstUpdated(); if (this.configData?.length && this.carouselInterval > 0) { setInterval(() => { this.activeTestimonial = (this.activeTestimonial + 1) % this.configData.length; this.makeActive(`#slide-${this.activeTestimonial}`); }, this.carouselInterval); } } /** * Click function for carousel dots * */ handleCarouselDotClick = (event: any) => { event.preventDefault(); const elementId = event.target.value; this.makeActive(elementId); }; /** * Make a testimonial active */ makeActive = (elementId: any) => { this.activeTestimonial = parseInt( elementId.substring(elementId.length - 1, elementId.length), 10 ); if (this.shadowRoot) { const selectedElement = this.shadowRoot.querySelector(elementId); const carouselElement = this.shadowRoot.querySelector( '.testimonials-carousel' ); if (carouselElement !== null) { carouselElement.scroll( carouselElement.clientWidth * this.activeTestimonial, 0 ); } // Add/remove class from slide elements const carouselItems = this.shadowRoot.querySelectorAll('.testimonial-item'); for (let index = 0; index < carouselItems.length; index += 1) { if (carouselItems[index].classList.contains('is-active')) { carouselItems[index].classList.remove('is-active'); } } selectedElement.classList.add('is-active'); // Add/remove class from dot navigation const carouselDots = this.shadowRoot.querySelectorAll('.carousel-dots li'); for (let index = 0; index < carouselDots.length; index += 1) { // Remove is-active from all elements if (index === this.activeTestimonial) { carouselDots[index].classList.add('is-active'); } else if (carouselDots[index].classList.contains('is-active')) { carouselDots[index].classList.remove('is-active'); } } // selectedElement.parentNode.classList.add('is-active'); } }; /** * Template for carousel items * */ carouselItem = (testimonials: any = []) => html` `; /** * Template for carousel dots * */ carouselDots = (data: any = []) => html`