From f51421b5bf68e3553a7f1dbfca5e2d05f0c4d8e0 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 24 Jul 2021 15:14:45 +0300 Subject: [PATCH 1/3] #47 : Add swiping prop --- src/components/Carousel/Carousel.svelte | 5 +++++ src/components/Carousel/stories/CarouselView.svelte | 9 ++++++++- .../Carousel/stories/CarouselViewCustomArrows.svelte | 8 +++++++- .../Carousel/stories/CarouselViewCustomDots.svelte | 8 +++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/Carousel/Carousel.svelte b/src/components/Carousel/Carousel.svelte index 0589c37..e5f09ec 100644 --- a/src/components/Carousel/Carousel.svelte +++ b/src/components/Carousel/Carousel.svelte @@ -90,6 +90,11 @@ */ export let dots = true + /** + * Enable swiping + */ + export let swiping = true + export async function goTo(pageIndex, options) { const animated = get(options, 'animated', true) if (typeof pageIndex !== 'number') { diff --git a/src/components/Carousel/stories/CarouselView.svelte b/src/components/Carousel/stories/CarouselView.svelte index 02743d5..6c47864 100644 --- a/src/components/Carousel/stories/CarouselView.svelte +++ b/src/components/Carousel/stories/CarouselView.svelte @@ -56,6 +56,11 @@ */ export let dots = true + /** + * Enable swiping + */ + export let swiping = true + const colors = [ { color: '#e5f9f0', text: '0' }, { color: '#ccf3e2', text: '1' }, @@ -89,6 +94,7 @@ {pauseOnFocus} {autoplayProgressVisible} {dots} + {swiping} on:pageChange={ event => console.log(`Current page index: ${event.detail}`) } @@ -115,6 +121,7 @@ {pauseOnFocus} {autoplayProgressVisible} {dots} + {swiping} > {#each colors2 as { color, text } (color)}
\ No newline at end of file + diff --git a/src/components/Carousel/stories/CarouselViewCustomArrows.svelte b/src/components/Carousel/stories/CarouselViewCustomArrows.svelte index 70e1f61..cd7a489 100644 --- a/src/components/Carousel/stories/CarouselViewCustomArrows.svelte +++ b/src/components/Carousel/stories/CarouselViewCustomArrows.svelte @@ -56,6 +56,11 @@ */ export let dots = true + /** + * Enable swiping + */ + export let swiping = true + const colors = [ '#e5f9f0', '#ccf3e2', @@ -83,6 +88,7 @@ {pauseOnFocus} {autoplayProgressVisible} {dots} + {swiping} let:showPrevPage let:showNextPage > @@ -138,4 +144,4 @@ cursor: pointer; -webkit-tap-highlight-color: transparent; } - \ No newline at end of file + diff --git a/src/components/Carousel/stories/CarouselViewCustomDots.svelte b/src/components/Carousel/stories/CarouselViewCustomDots.svelte index 8e0cc72..de97c0d 100644 --- a/src/components/Carousel/stories/CarouselViewCustomDots.svelte +++ b/src/components/Carousel/stories/CarouselViewCustomDots.svelte @@ -56,6 +56,11 @@ */ export let dots = true + /** + * Enable swiping + */ + export let swiping = true + function onPageChange(event, showPage) { showPage(Number(event.target.value)) } @@ -87,6 +92,7 @@ {pauseOnFocus} {autoplayProgressVisible} {dots} + {swiping} let:currentPageIndex let:pagesCount let:showPage @@ -148,4 +154,4 @@ width: 100px; border-radius: 5px; } - \ No newline at end of file + From 1dbccd20a9f267e3d5849d588b09ab773ee4c4bb Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 24 Jul 2021 15:17:45 +0300 Subject: [PATCH 2/3] #47 : Extend docs --- README.md | 1 + src/docs/Carousel.svx | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index f199c0c..2dc47d1 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Import component | `autoplayProgressVisible` | `boolean` | `false` | Show autoplay duration progress indicator | | `dots` | `boolean` | `true` | Current page indicator dots | | `timingFunction` | `string` | `'ease-in-out'` | CSS animation timing function | +| `swiping` | `boolean` | `true` | Enable swiping | ## Events diff --git a/src/docs/Carousel.svx b/src/docs/Carousel.svx index a7b28c4..d9ad74e 100644 --- a/src/docs/Carousel.svx +++ b/src/docs/Carousel.svx @@ -273,6 +273,7 @@ Import component | `autoplayProgressVisible` | `boolean` | `false` | Show autoplay duration progress indicator | | `dots` | `boolean` | `true` | Current page indicator dots | | `timingFunction` | `string` | `'ease-in-out'` | CSS animation timing function | +| `swiping` | `boolean` | `true` | Enable swiping | From 35495d6f9169c4c19aef9518807d4a318b0fe09e Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 24 Jul 2021 15:21:30 +0300 Subject: [PATCH 3/3] #47 : Prevent swiping if swiping is false --- src/components/Carousel/Carousel.svelte | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Carousel/Carousel.svelte b/src/components/Carousel/Carousel.svelte index e5f09ec..43c35af 100644 --- a/src/components/Carousel/Carousel.svelte +++ b/src/components/Carousel/Carousel.svelte @@ -286,15 +286,19 @@ // gestures function handleSwipeStart() { + if (!swiping) return _duration = 0 } async function handleThreshold(event) { + if (!swiping) return await directionFnDescription[event.detail.direction]() } function handleSwipeMove(event) { + if (!swiping) return offset += event.detail.dx } function handleSwipeEnd() { + if (!swiping) return showPage(currentPageIndex) } function handleFocused(event) {