From be3f860c52822b14907c71ade467d8ec5a08b275 Mon Sep 17 00:00:00 2001 From: Tomasz Dziezyk Date: Tue, 30 Jul 2024 11:45:09 +0200 Subject: [PATCH] KAW-7686 Udpate the carousel buttons styles --- blocks/carousel/carousel.css | 28 ++++++++++++++++++++++++++-- blocks/carousel/carousel.js | 20 +++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/blocks/carousel/carousel.css b/blocks/carousel/carousel.css index b2dbdcc..9525d88 100644 --- a/blocks/carousel/carousel.css +++ b/blocks/carousel/carousel.css @@ -22,5 +22,29 @@ } .carousel .transition-effect { - transition: transform 300ms ease-in-out; -} \ No newline at end of file + transition: transform 500ms ease; +} + +.carousel-nav { + padding: 0; + list-style: none; + display: flex; + gap: 12px; + justify-content: center; +} + +.carousel-nav-button { + background-color: #fff; + width: 10px; + height: 10px; + border-radius: 50%; + transition: 0.2s ease-in-out; + transition-property: color, background-color, border-color, box-shadow; + border: 1px solid rgb(29 29 27 / 40%); + padding: 0; +} + +.carousel-nav-button-active { + background-color: rgb(29 29 27 / 60%); + border-color: transparent; +} diff --git a/blocks/carousel/carousel.js b/blocks/carousel/carousel.js index 92c71e1..d502c57 100644 --- a/blocks/carousel/carousel.js +++ b/blocks/carousel/carousel.js @@ -1,3 +1,5 @@ +import { getTextLabel } from '../../scripts/scripts.js'; + const getCarouselPadding = (itemIndex) => `calc(-1 * (${itemIndex - 0.5} * var(--slide-width) + var(--slide-gap) * ${itemIndex - 1}))`; const recalcSlidePositions = (slides, activeSlideIndex, direction) => { @@ -54,6 +56,7 @@ const supportSwiping = (swipeEl, onSwipe) => { const handleSwipe = () => { const minSwipeDistance = 50; + if (touchEndX < touchStartX - minSwipeDistance) { // swipe left - next slide onSwipe('next'); @@ -97,9 +100,13 @@ export default async function decorate(block) { `); const carouselNav = document.createRange().createContextualFragment( - ``, + ``, ); block.append(slideWrapper); @@ -109,6 +116,13 @@ export default async function decorate(block) { let activeSlideIndex = 0; let prevActiveSlideIndex = 0; + const getActiveSlideIndex = () => activeSlideIndex; + + const setActiveSlideIndex = (value) => { + prevActiveSlideIndex = activeSlideIndex; + activeSlideIndex = value; + }; + recalcSlidePositions(slides, activeSlideIndex, null); [...block.querySelectorAll('.carousel-buttons button')].forEach((button, btnIndex) => {