Use a component for carousel dots

- Show 5 dots by default
- First and last one from current index are smaller
- Other ones are hidden
This commit is contained in:
2020-03-25 12:19:48 +01:00
parent 093c87d156
commit 498f3c0c17
3 changed files with 48 additions and 11 deletions

View File

@@ -0,0 +1,21 @@
<script>
import { createEventDispatcher } from 'svelte'
const dispatch = createEventDispatcher()
// Props
export let photos
export let currentIndex
</script>
<ol class="carousel__dots">
{#each photos as dot, index}
<li
class:active={index === currentIndex}
class:small={index < currentIndex - 2 || index > currentIndex + 2}
class:hidden={index < currentIndex - 3 || index > currentIndex + 3}
on:click={() => dispatch('goToIndex', { index })}
>
<button aria-label="Go to photo #{index + 1}"></button>
</li>
{/each}
</ol>