Change Switcher labels and close it when clicking outside
This commit is contained in:
@@ -1,7 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
// Components
|
||||||
import Icon from '$components/atoms/Icon.svelte'
|
import Icon from '$components/atoms/Icon.svelte'
|
||||||
|
|
||||||
let isOpen: boolean = false
|
let switcherEl: HTMLElement
|
||||||
|
let isOpen = false
|
||||||
|
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
// Links
|
// Links
|
||||||
const links = [
|
const links = [
|
||||||
@@ -9,19 +15,19 @@
|
|||||||
icon: "globe",
|
icon: "globe",
|
||||||
iconLabel: "Globe icon",
|
iconLabel: "Globe icon",
|
||||||
url: "/locations",
|
url: "/locations",
|
||||||
text: "Discover locations"
|
text: "Explore Locations"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "photos",
|
icon: "photos",
|
||||||
iconLabel: "Photos icon",
|
iconLabel: "Photos icon",
|
||||||
url: "/photos",
|
url: "/photos",
|
||||||
text: "Browse all photos"
|
text: "Photo Grid"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "bag",
|
icon: "bag",
|
||||||
iconLabel: "Bag icon",
|
iconLabel: "Bag icon",
|
||||||
url: "/shop",
|
url: "/shop",
|
||||||
text: "Shop the prints"
|
text: "Shop Posters"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -32,9 +38,22 @@
|
|||||||
const toggleSwitcher = () => {
|
const toggleSwitcher = () => {
|
||||||
isOpen = !isOpen
|
isOpen = !isOpen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect outside click
|
||||||
|
*/
|
||||||
|
const windowClick = ({ target }) => {
|
||||||
|
if (!switcherEl.contains(target)) {
|
||||||
|
// Close switcher
|
||||||
|
isOpen = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<aside class="switcher" class:is-open={isOpen}>
|
<svelte:window on:click={windowClick} />
|
||||||
|
|
||||||
|
<aside class="switcher" class:is-open={isOpen} bind:this={switcherEl}>
|
||||||
<nav class="switcher__links">
|
<nav class="switcher__links">
|
||||||
<ul>
|
<ul>
|
||||||
{#each links as { icon, iconLabel, url, text }}
|
{#each links as { icon, iconLabel, url, text }}
|
||||||
@@ -52,9 +71,9 @@
|
|||||||
on:click={toggleSwitcher}
|
on:click={toggleSwitcher}
|
||||||
>
|
>
|
||||||
<span>
|
<span>
|
||||||
|
{#each Array(3) as _}
|
||||||
<i />
|
<i />
|
||||||
<i />
|
{/each}
|
||||||
<i />
|
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</aside>
|
</aside>
|
||||||
@@ -74,7 +74,6 @@
|
|||||||
span {
|
span {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
transition: transform 0.8s var(--ease-quart);
|
|
||||||
}
|
}
|
||||||
// Dot
|
// Dot
|
||||||
i {
|
i {
|
||||||
@@ -113,9 +112,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__button {
|
&__button {
|
||||||
span {
|
|
||||||
transform: rotate3d(70deg, 120deg, 180deg) translateZ(0);
|
|
||||||
}
|
|
||||||
i {
|
i {
|
||||||
&:nth-child(1) { transform: translate3d(-7px, 8px, 0); }
|
&:nth-child(1) { transform: translate3d(-7px, 8px, 0); }
|
||||||
&:nth-child(2) { transform: translate3d(7px, -2px, 0); }
|
&:nth-child(2) { transform: translate3d(7px, -2px, 0); }
|
||||||
|
|||||||
Reference in New Issue
Block a user