Merge pull request #7 from vadimkorr/feature/#5_Add-stylish-arrows
Feature/#5 Add stylish arrows
This commit is contained in:
19
src/Arrow/Arrow.stories.js
Normal file
19
src/Arrow/Arrow.stories.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import Arrow from './Arrow.svelte';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Arrow',
|
||||||
|
component: Arrow,
|
||||||
|
argTypes: {
|
||||||
|
onClick: { action: 'onClick' }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Template = ({ onClick, ...args }) => ({
|
||||||
|
Component: Arrow,
|
||||||
|
props: args,
|
||||||
|
on: {
|
||||||
|
click: onClick,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const Primary = Template.bind({});
|
||||||
50
src/Arrow/Arrow.svelte
Normal file
50
src/Arrow/Arrow.svelte
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Indicates direction of the arrow ('next', 'prev')
|
||||||
|
*/
|
||||||
|
export let direction = 'next'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="circle"
|
||||||
|
on:click
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
class="arrow"
|
||||||
|
class:next={direction === 'next'}
|
||||||
|
class:prev={direction === 'prev'}
|
||||||
|
></i>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--size: 2px
|
||||||
|
}
|
||||||
|
.circle {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: rgba(93, 93, 93, 0.5); /* #5d5d5d */
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: opacity 100ms ease;
|
||||||
|
}
|
||||||
|
.circle:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
.arrow {
|
||||||
|
border: solid #1e1e1e;
|
||||||
|
border-width: 0 var(--size) var(--size) 0;
|
||||||
|
padding: var(--size);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.next {
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
left: calc(var(--size) / -2);
|
||||||
|
}
|
||||||
|
.prev {
|
||||||
|
transform: rotate(135deg);
|
||||||
|
right: calc(var(--size) / -2);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
<script>
|
<script>
|
||||||
import { tweened } from 'svelte/motion';
|
import { tweened } from 'svelte/motion';
|
||||||
import { cubicInOut } from 'svelte/easing';
|
import { cubicInOut } from 'svelte/easing';
|
||||||
|
|
||||||
const size = tweened(10, {
|
const sizePx = 5
|
||||||
duration: 100,
|
const sizeCurrentPx = 8
|
||||||
easing: cubicInOut
|
|
||||||
});
|
const size = tweened(sizePx, {
|
||||||
|
duration: 250,
|
||||||
|
easing: cubicInOut
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if dot is active
|
* Indicates if dot is active
|
||||||
@@ -13,7 +16,7 @@
|
|||||||
export let active = false
|
export let active = false
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
size.set(active ? 13 : 10)
|
size.set(active ? sizeCurrentPx : sizePx)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -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({});
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
getIsNotCompletePage
|
getIsNotCompletePage
|
||||||
} from '../utils/size'
|
} from '../utils/size'
|
||||||
import Dots from '../Dots/Dots.svelte'
|
import Dots from '../Dots/Dots.svelte'
|
||||||
|
import Arrow from '../Arrow/Arrow.svelte'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable Next/Prev arrows
|
* Enable Next/Prev arrows
|
||||||
@@ -139,12 +140,11 @@
|
|||||||
<div class="main-container">
|
<div class="main-container">
|
||||||
<div class="carousel-container">
|
<div class="carousel-container">
|
||||||
{#if arrows}
|
{#if arrows}
|
||||||
<div class="side-container">
|
<slot name="prev" {showPrevPage}>
|
||||||
<span
|
<div class="side-container">
|
||||||
class="clickable"
|
<Arrow direction="prev" on:click={showPrevPage} />
|
||||||
on:click={showPrevPage}
|
</div>
|
||||||
><</span>
|
</slot>
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
class="content-container"
|
class="content-container"
|
||||||
@@ -161,12 +161,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if arrows}
|
{#if arrows}
|
||||||
<div class="side-container">
|
<slot name="next" {showNextPage}>
|
||||||
<span
|
<div class="side-container">
|
||||||
class="clickable"
|
<Arrow direction="next" on:click={showNextPage} />
|
||||||
on:click={showNextPage}
|
</div>
|
||||||
>></span>
|
</slot>
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if dots}
|
{#if dots}
|
||||||
@@ -209,7 +208,6 @@
|
|||||||
transition-property: transform;
|
transition-property: transform;
|
||||||
}
|
}
|
||||||
.side-container {
|
.side-container {
|
||||||
background-color: cornflowerblue;
|
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -217,7 +215,4 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
.clickable {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
133
src/ImageCarousel/ImageCarouselViewCustomArrows.svelte
Normal file
133
src/ImageCarousel/ImageCarouselViewCustomArrows.svelte
Normal 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><<<</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div slot="next" class="arrow-container">
|
||||||
|
<div class="arrow" on:click={showNextPage}>
|
||||||
|
<span>>>></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>
|
||||||
Reference in New Issue
Block a user