Add custom arrows example

This commit is contained in:
Vadim
2021-01-22 17:37:02 +03:00
parent 7075e8de00
commit d671b9ff55
3 changed files with 143 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import ImageCarouselView from './ImageCarouselView.svelte'; import ImageCarouselView from './ImageCarouselView.svelte';
import ImageCarouselViewCustomDots from './ImageCarouselViewCustomDots.svelte'; import ImageCarouselViewCustomDots from './ImageCarouselViewCustomDots.svelte';
import ImageCarouselViewCustomArrows from './ImageCarouselViewCustomArrows.svelte';
export default { export default {
title: 'ImageCarousel', title: 'ImageCarousel',
@@ -10,13 +11,17 @@ const Template = ({ ...args }) => ({
Component: ImageCarouselView, Component: ImageCarouselView,
props: args props: args
}); });
export const Primary = Template.bind({});
const TemplateCustomDots = ({ ...args }) => ({ const TemplateCustomDots = ({ ...args }) => ({
Component: ImageCarouselViewCustomDots, Component: ImageCarouselViewCustomDots,
props: args props: args
}); });
export const Primary = Template.bind({});
export const WithCustomDots = TemplateCustomDots.bind({}); export const WithCustomDots = TemplateCustomDots.bind({});
const TemplateCustomArrows = ({ ...args }) => ({
Component: ImageCarouselViewCustomArrows,
props: args
});
export const WithCustomArrows = TemplateCustomArrows.bind({});

View File

@@ -140,7 +140,7 @@
<div class="main-container"> <div class="main-container">
<div class="carousel-container"> <div class="carousel-container">
{#if arrows} {#if arrows}
<slot name="prev"> <slot name="prev" {showPrevPage}>
<div class="side-container"> <div class="side-container">
<Arrow direction="prev" on:click={showPrevPage} /> <Arrow direction="prev" on:click={showPrevPage} />
</div> </div>
@@ -161,7 +161,7 @@
</div> </div>
</div> </div>
{#if arrows} {#if arrows}
<slot name="next"> <slot name="next" {showNextPage}>
<div class="side-container"> <div class="side-container">
<Arrow direction="next" on:click={showNextPage} /> <Arrow direction="next" on:click={showNextPage} />
</div> </div>

View File

@@ -0,0 +1,133 @@
<script>
import ImageCarousel from './ImageCarousel.svelte'
/**
* Enable Next/Previos arrows
*/
export let arrows = true;
/**
* Infinite looping
*/
export let infinite = true;
/**
* Number of slides to show at a time
*/
export let slidesToShow = 1;
/**
* Page to start on
*/
export let initialPage = 1
/**
* Transition speed (ms)
*/
export let speed = 500
/**
* Enables auto play of slides
*/
export let autoplay = false
/**
* Auto play change interval
*/
export let autoplaySpeed = 3000
/**
* Auto play change direction ('next', 'prev')
*/
export let autoplayDirection = 'next'
/**
* Current page indicator dots
*/
export let dots = true
function onPageChange(event, showPage) {
showPage(event.target.value)
}
const colors = [
'#e5f9f0',
'#ccf3e2',
'#b2edd3',
'#99e7c5',
'#7fe1b7',
'#66dba8',
'#4cd59a',
'#32cf8b',
'#19c97d',
'#00c36f'
]
</script>
<div class="main-container">
<ImageCarousel
{arrows}
{infinite}
{slidesToShow}
{initialPage}
{speed}
{autoplay}
{autoplaySpeed}
{autoplayDirection}
{dots}
let:showPrevPage
let:showNextPage
>
{#each colors as color (color)}
<div
class="color-container"
style="background-color: {color};"
>
<p>{color}</p>
</div>
{/each}
<div slot="prev" class="arrow-container">
<div class="arrow" on:click={showPrevPage}>
<span>&lt;&lt;&lt;</span>
</div>
</div>
<div slot="next" class="arrow-container">
<div class="arrow" on:click={showNextPage}>
<span>&gt;&gt;&gt;</span>
</div>
</div>
</ImageCarousel>
</div>
<style>
.main-container {
display: flex;
width: 100%;
}
.color-container {
height: 100px;
display: flex;
align-items: center;
justify-content: center;
}
.color-container > p {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-style: italic;
font-size: 18px;
}
.arrow-container {
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
}
.arrow {
background-color: darkgray;
border-radius: 5px;
padding: 5px;
font-weight: bold;
cursor: pointer;
user-select: none;
}
</style>