Code cleanup

This commit is contained in:
Vadim
2021-01-22 20:57:08 +03:00
parent 5154887d93
commit 139695edb8
12 changed files with 28 additions and 122 deletions

View File

@@ -1,7 +1,7 @@
import Arrow from './Arrow.svelte'; import Arrow from './Arrow.svelte';
export default { export default {
title: 'Arrow', title: 'Default Components/Arrow',
component: Arrow, component: Arrow,
argTypes: { argTypes: {
onClick: { action: 'onClick' } onClick: { action: 'onClick' }

View File

@@ -1,8 +1,9 @@
<script> <script>
import { NEXT, PREV } from '../direction'
/** /**
* Indicates direction of the arrow ('next', 'prev') * Indicates direction of the arrow ('next', 'prev')
*/ */
export let direction = 'next' export let direction = NEXT
</script> </script>
<div <div
@@ -11,8 +12,8 @@
> >
<i <i
class="arrow" class="arrow"
class:next={direction === 'next'} class:next={direction === NEXT}
class:prev={direction === 'prev'} class:prev={direction === PREV}
></i> ></i>
</div> </div>

View File

@@ -11,6 +11,7 @@
} from '../utils/size' } from '../utils/size'
import Dots from '../Dots/Dots.svelte' import Dots from '../Dots/Dots.svelte'
import Arrow from '../Arrow/Arrow.svelte' import Arrow from '../Arrow/Arrow.svelte'
import { NEXT, PREV } from '../direction'
/** /**
* Enable Next/Prev arrows * Enable Next/Prev arrows
@@ -50,7 +51,7 @@
/** /**
* Auto play change direction ('next', 'prev') * Auto play change direction ('next', 'prev')
*/ */
export let autoplayDirection = 'next' export let autoplayDirection = NEXT
/** /**
* Current page indicator dots * Current page indicator dots
@@ -61,16 +62,16 @@
let pagesCount = 0 let pagesCount = 0
let pageWidth = 0 let pageWidth = 0
let offset let offset
let contentContainerElement let pageWindow
let innerContentContainerElement let pagesElement
const unsubscribe = store.subscribe(value => { const unsubscribe = store.subscribe(value => {
currentPageIndex = value.currentPageIndex currentPageIndex = value.currentPageIndex
}) })
function applySlideSizes() { function applySlideSizes() {
const children = innerContentContainerElement ? innerContentContainerElement.children : [] const children = pagesElement ? pagesElement.children : []
pageWidth = contentContainerElement.clientWidth pageWidth = pageWindow.clientWidth
const slidesCount = children.length const slidesCount = children.length
pagesCount = getPagesCount({ slidesCount, slidesToShow }) pagesCount = getPagesCount({ slidesCount, slidesToShow })
@@ -87,8 +88,8 @@
function applyAutoplay() { function applyAutoplay() {
const autoplayDirectionFnDescription = { const autoplayDirectionFnDescription = {
'next': showNextPage, [NEXT]: showNextPage,
'prev': showPrevPage [PREV]: showPrevPage
} }
let interval let interval
if (autoplay) { if (autoplay) {
@@ -146,28 +147,28 @@
<div class="carousel-container"> <div class="carousel-container">
{#if arrows} {#if arrows}
<slot name="prev" {showPrevPage}> <slot name="prev" {showPrevPage}>
<div class="side-container"> <div class="arrow-container">
<Arrow direction="prev" on:click={showPrevPage} /> <Arrow direction="prev" on:click={showPrevPage} />
</div> </div>
</slot> </slot>
{/if} {/if}
<div <div
class="content-container" class="content-container"
bind:this={contentContainerElement} bind:this={pageWindow}
> >
<div <div
style=" style="
transform: translateX({offset}px); transform: translateX({offset}px);
transition-duration: {speed}ms; transition-duration: {speed}ms;
" "
bind:this={innerContentContainerElement} bind:this={pagesElement}
> >
<slot></slot> <slot></slot>
</div> </div>
</div> </div>
{#if arrows} {#if arrows}
<slot name="next" {showNextPage}> <slot name="next" {showNextPage}>
<div class="side-container"> <div class="arrow-container">
<Arrow direction="next" on:click={showNextPage} /> <Arrow direction="next" on:click={showNextPage} />
</div> </div>
</slot> </slot>
@@ -212,7 +213,7 @@
transition-timing-function: ease-in-out; transition-timing-function: ease-in-out;
transition-property: transform; transition-property: transform;
} }
.side-container { .arrow-container {
height: 100%; height: 100%;
padding: 5px; padding: 5px;
box-sizing: border-box; box-sizing: border-box;

View File

@@ -1,5 +1,6 @@
<script> <script>
import Carousel from './Carousel.svelte' import Carousel from './Carousel.svelte'
import { NEXT } from '../direction'
/** /**
* Enable Next/Previos arrows * Enable Next/Previos arrows
@@ -39,7 +40,7 @@
/** /**
* Auto play change direction ('next', 'prev') * Auto play change direction ('next', 'prev')
*/ */
export let autoplayDirection = 'next' export let autoplayDirection = NEXT
/** /**
* Current page indicator dots * Current page indicator dots

View File

@@ -1,5 +1,6 @@
<script> <script>
import Carousel from './Carousel.svelte' import Carousel from './Carousel.svelte'
import { NEXT } from '../direction'
/** /**
* Enable Next/Previos arrows * Enable Next/Previos arrows
@@ -39,7 +40,7 @@
/** /**
* Auto play change direction ('next', 'prev') * Auto play change direction ('next', 'prev')
*/ */
export let autoplayDirection = 'next' export let autoplayDirection = NEXT
/** /**
* Current page indicator dots * Current page indicator dots

View File

@@ -1,5 +1,6 @@
<script> <script>
import Carousel from './Carousel.svelte' import Carousel from './Carousel.svelte'
import { NEXT } from '../direction'
/** /**
* Enable Next/Previos arrows * Enable Next/Previos arrows
@@ -39,7 +40,7 @@
/** /**
* Auto play change direction ('next', 'prev') * Auto play change direction ('next', 'prev')
*/ */
export let autoplayDirection = 'next' export let autoplayDirection = NEXT
/** /**
* Current page indicator dots * Current page indicator dots

View File

@@ -1,7 +1,7 @@
import DotView from './DotView.svelte'; import DotView from './DotView.svelte';
export default { export default {
title: 'Dot', title: 'Default Components/Dot',
component: DotView component: DotView
}; };

View File

@@ -1,7 +1,7 @@
import DotsView from './DotsView.svelte'; import DotsView from './DotsView.svelte';
export default { export default {
title: 'Dots', title: 'Default Components/Dots',
component: DotsView component: DotsView
}; };

2
src/direction.js Normal file
View File

@@ -0,0 +1,2 @@
export const PREV = 'prev'
export const NEXT = 'next'

View File

@@ -1,29 +0,0 @@
import Button from './Button.svelte';
export default {
title: 'Example/Button',
component: Button,
argTypes: {
label: { control: 'text' },
primary: { control: 'boolean' },
backgroundColor: { control: 'color' },
size: {
control: { type: 'select', options: ['small', 'medium', 'large'] },
},
onClick: { action: 'onClick' },
},
};
const Template = ({ onClick, ...args }) => ({
Component: Button,
props: args,
on: {
click: onClick,
},
});
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};

View File

@@ -1,42 +0,0 @@
<script>
import './button.css';
import { createEventDispatcher } from 'svelte';
/**
* Is this the principal call to action on the page?
*/
export let primary = false;
/**
* What background color to use
*/
export let backgroundColor;
/**
* How large should the button be?
*/
export let size = 'medium';
/**
* Button contents
*/
export let label = '';
let mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
let style = backgroundColor ? `background-color: ${backgroundColor}` : '';
const dispatch = createEventDispatcher();
/**
* Optional click handler
*/
function onClick(event) {
dispatch('click', event);
}
</script>
<button
type="button"
class={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
{style}
on:click={onClick}>
{label}
</button>

View File

@@ -1,30 +0,0 @@
.storybook-button {
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-weight: 700;
border: 0;
border-radius: 3em;
cursor: pointer;
display: inline-block;
line-height: 1;
}
.storybook-button--primary {
color: white;
background-color: #1ea7fd;
}
.storybook-button--secondary {
color: #333;
background-color: transparent;
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
}
.storybook-button--small {
font-size: 12px;
padding: 10px 16px;
}
.storybook-button--medium {
font-size: 14px;
padding: 11px 20px;
}
.storybook-button--large {
font-size: 16px;
padding: 12px 24px;
}