From 78c39bf7f164e936dafca9b83906ea37523a84e0 Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 22 Jan 2021 11:13:54 +0300 Subject: [PATCH 1/3] Add dots --- src/Dots.svelte | 65 +++++++++++++++++++++++ src/ImageCarousel.svelte | 79 ++++++++++++++++++---------- src/stories/Dots.stories.js | 13 +++++ src/stories/DotsView.svelte | 24 +++++++++ src/stories/ImageCarousel.stories.js | 10 +--- src/stories/ImageCarouselView.svelte | 6 +++ 6 files changed, 162 insertions(+), 35 deletions(-) create mode 100644 src/Dots.svelte create mode 100644 src/stories/Dots.stories.js create mode 100644 src/stories/DotsView.svelte diff --git a/src/Dots.svelte b/src/Dots.svelte new file mode 100644 index 0000000..c3993a1 --- /dev/null +++ b/src/Dots.svelte @@ -0,0 +1,65 @@ + + +
+ {#each Array(pagesCount) as _, pageIndex} +
+
handleDotClick(pageIndex)} + >
+
+ {/each} +
+ + \ No newline at end of file diff --git a/src/ImageCarousel.svelte b/src/ImageCarousel.svelte index 46b45ec..ff3ddb6 100644 --- a/src/ImageCarousel.svelte +++ b/src/ImageCarousel.svelte @@ -10,6 +10,7 @@ getSlideSize, getIsNotCompletePage } from './utils/size' + import Dots from './Dots.svelte' /** * Enable Next/Prev arrows @@ -51,6 +52,11 @@ */ export let autoplayDirection = 'next' + /** + * Current page indicator dots + */ + export let dots = true + let pagesCount = 0 let contentContainerWidth = 0 let offset @@ -106,6 +112,10 @@ } }) + function handlePageChange(event) { + showPage(event.detail) + } + function applyOffset() { offset = -$store.currentItemIndex * contentContainerWidth } @@ -125,35 +135,44 @@
- {#if arrows} -
- < -
- {/if} -
-
- + - {#if arrows} -
- > -
+ {#if dots} + {/if}
@@ -161,6 +180,12 @@ .main-container { display: flex; width: 100%; + flex-direction: column; + align-items: center; + } + .carousel-container { + display: flex; + width: 100%; } .content-container { flex: 1; diff --git a/src/stories/Dots.stories.js b/src/stories/Dots.stories.js new file mode 100644 index 0000000..70434c1 --- /dev/null +++ b/src/stories/Dots.stories.js @@ -0,0 +1,13 @@ +import DotsView from './DotsView.svelte'; + +export default { + title: 'Dots', + component: DotsView +}; + +const Template = ({ ...args }) => ({ + Component: DotsView, + props: args +}); + +export const Primary = Template.bind({}); diff --git a/src/stories/DotsView.svelte b/src/stories/DotsView.svelte new file mode 100644 index 0000000..86f88e9 --- /dev/null +++ b/src/stories/DotsView.svelte @@ -0,0 +1,24 @@ + + + + diff --git a/src/stories/ImageCarousel.stories.js b/src/stories/ImageCarousel.stories.js index 25b1795..cfec282 100644 --- a/src/stories/ImageCarousel.stories.js +++ b/src/stories/ImageCarousel.stories.js @@ -2,18 +2,12 @@ import ImageCarouselView from './ImageCarouselView.svelte'; export default { title: 'ImageCarousel', - component: ImageCarouselView, - argTypes: { - arrows: { control: 'boolean' }, - }, + component: ImageCarouselView }; const Template = ({ ...args }) => ({ Component: ImageCarouselView, - props: args, + props: args }); export const Primary = Template.bind({}); -Primary.args = { - arrows: true -}; diff --git a/src/stories/ImageCarouselView.svelte b/src/stories/ImageCarouselView.svelte index a4de909..e8e0d2f 100644 --- a/src/stories/ImageCarouselView.svelte +++ b/src/stories/ImageCarouselView.svelte @@ -41,6 +41,11 @@ */ export let autoplayDirection = 'next' + /** + * Current page indicator dots + */ + export let dots = true + const colors = [ '#e5f9f0', '#ccf3e2', @@ -65,6 +70,7 @@ {autoplay} {autoplaySpeed} {autoplayDirection} + {dots} > {#each colors as color (color)}
Date: Fri, 22 Jan 2021 14:54:17 +0300 Subject: [PATCH 2/3] Add size animation to dots, move stories to component folder --- src/Dot/Dot.stories.js | 13 +++++ src/Dot/Dot.svelte | 54 +++++++++++++++++++ src/Dot/DotView.svelte | 17 ++++++ src/{stories => Dots}/Dots.stories.js | 0 src/{ => Dots}/Dots.svelte | 29 +++------- src/{stories => Dots}/DotsView.svelte | 2 +- .../ImageCarousel.stories.js | 0 src/{ => ImageCarousel}/ImageCarousel.svelte | 6 +-- .../ImageCarouselView.svelte | 2 +- 9 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 src/Dot/Dot.stories.js create mode 100644 src/Dot/Dot.svelte create mode 100644 src/Dot/DotView.svelte rename src/{stories => Dots}/Dots.stories.js (100%) rename src/{ => Dots}/Dots.svelte (61%) rename src/{stories => Dots}/DotsView.svelte (90%) rename src/{stories => ImageCarousel}/ImageCarousel.stories.js (100%) rename src/{ => ImageCarousel}/ImageCarousel.svelte (97%) rename src/{stories => ImageCarousel}/ImageCarouselView.svelte (96%) diff --git a/src/Dot/Dot.stories.js b/src/Dot/Dot.stories.js new file mode 100644 index 0000000..1b828d0 --- /dev/null +++ b/src/Dot/Dot.stories.js @@ -0,0 +1,13 @@ +import DotView from './DotView.svelte'; + +export default { + title: 'Dot', + component: DotView +}; + +const Template = ({ ...args }) => ({ + Component: DotView, + props: args +}); + +export const Primary = Template.bind({}); diff --git a/src/Dot/Dot.svelte b/src/Dot/Dot.svelte new file mode 100644 index 0000000..edb2f48 --- /dev/null +++ b/src/Dot/Dot.svelte @@ -0,0 +1,54 @@ + + +
+
+
+ + \ No newline at end of file diff --git a/src/Dot/DotView.svelte b/src/Dot/DotView.svelte new file mode 100644 index 0000000..100ea7a --- /dev/null +++ b/src/Dot/DotView.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/stories/Dots.stories.js b/src/Dots/Dots.stories.js similarity index 100% rename from src/stories/Dots.stories.js rename to src/Dots/Dots.stories.js diff --git a/src/Dots.svelte b/src/Dots/Dots.svelte similarity index 61% rename from src/Dots.svelte rename to src/Dots/Dots.svelte index c3993a1..394c75a 100644 --- a/src/Dots.svelte +++ b/src/Dots/Dots.svelte @@ -1,5 +1,7 @@
- {#each Array(pagesCount) as _, pageIndex} + {#each Array(pagesCount) as _, pageIndex (pageIndex)}
-
handleDotClick(pageIndex)} - >
+ >
{/each}
@@ -44,22 +45,4 @@ align-items: center; justify-content: center; } - .dot { - height: var(--dot-size); - width: var(--dot-size); - background-color: #aaa; - border-radius: 50%; - display: inline-block; - opacity: 0.5; - margin: 3px; - cursor: pointer; - } - .dot:hover { - opacity: 0.9; - } - .current { - height: calc(var(--dot-size) + 3px); - width: calc(var(--dot-size) + 3px); - opacity: 0.7; - } \ No newline at end of file diff --git a/src/stories/DotsView.svelte b/src/Dots/DotsView.svelte similarity index 90% rename from src/stories/DotsView.svelte rename to src/Dots/DotsView.svelte index 86f88e9..dd8cd7c 100644 --- a/src/stories/DotsView.svelte +++ b/src/Dots/DotsView.svelte @@ -1,5 +1,5 @@ + +
+ + {#each colors as color (color)} +
+

{color}

+
+ {/each} +
+
+ +
+
+
+
+ + \ No newline at end of file