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)}