Add arrow component

This commit is contained in:
Vadim
2021-01-22 17:22:25 +03:00
parent 1313f75e4c
commit 7075e8de00
4 changed files with 90 additions and 23 deletions

View 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
View 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>

View File

@@ -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>

View File

@@ -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">
<span <div class="side-container">
class="clickable" <Arrow direction="prev" on:click={showPrevPage} />
on:click={showPrevPage} </div>
>&lt;</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">
<span <div class="side-container">
class="clickable" <Arrow direction="next" on:click={showNextPage} />
on:click={showNextPage} </div>
>&gt;</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>