Files
housesof/src/components/molecules/Switcher.svelte
Félix Péault 73c9e80a21 Use SVG icons from global symbols
Allow to change color and avoid code duplication
2021-11-10 22:57:50 +01:00

60 lines
1.4 KiB
Svelte

<script lang="ts">
import Icon from '$components/atoms/Icon.svelte'
let isOpen: boolean = false
// Links
const links = [
{
icon: "globe",
iconLabel: "Globe icon",
url: "/locations",
text: "Discover locations"
},
{
icon: "photos",
iconLabel: "Photos icon",
url: "/photos",
text: "Browse all photos"
},
{
icon: "bag",
iconLabel: "Bag icon",
url: "/shop",
text: "Shop the prints"
}
]
/**
* Toggle switcher open state
*/
const toggleSwitcher = () => {
isOpen = !isOpen
}
</script>
<aside class="switcher" class:is-open={isOpen}>
<nav class="switcher__links">
<ul>
{#each links as { icon, iconLabel, url, text }}
<li>
<a href={url} on:click={toggleSwitcher} sveltekit:prefetch>
<Icon class="icon" icon={icon} label={iconLabel} />
<span>{text}</span>
</a>
</li>
{/each}
</ul>
</nav>
<button class="switcher__button" title="{!isOpen ? 'Open' : 'Close'} menu"
on:click={toggleSwitcher}
>
<span>
<i />
<i />
<i />
</span>
</button>
</aside>