-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNavMenu.svelte
More file actions
59 lines (58 loc) · 1.66 KB
/
NavMenu.svelte
File metadata and controls
59 lines (58 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script>
import { quadOut } from "svelte/easing";
import navLinks from "../data/navLinks";
import { fade } from "svelte/transition";
let menuActive = $state(false);
function toggleMenu() {
menuActive = !menuActive;
}
</script>
<nav class="hidden md:block">
<ul class="flex gap-6 text-lg">
{#each navLinks as link}
<li>
<a
class="text-white font-bold"
href={`${import.meta.env.BASE_URL}${link.path}`}
>
{link.title}
</a>
</li>
{/each}
</ul>
</nav>
<button
class="md:hidden self-center text-white font-bold border-2 border-white rounded-lg px-2 py-1"
onclick={toggleMenu}
aria-label={menuActive ? "Close navigation menu" : "Open navigation menu"}
aria-controls="navMenu"
aria-expanded={menuActive}>Menu</button
>
{#if menuActive == true}
<div
id="navMenu"
class="fixed left-0 top-0 h-screen w-screen flex justify-center items-center bg-sky-500"
transition:fade={{ duration: 180, easing: quadOut }}
>
<button
class="fixed top-9.5 right-6 text-white font-bold border-2 border-white rounded-lg px-2 py-1"
onclick={toggleMenu}
aria-label={menuActive ? "Close navigation menu" : "Open navigation menu"}
aria-controls="navMenu"
aria-expanded={menuActive}>Close</button
>
<ul class="w-fit h-fit flex flex-col gap-4 items-center">
{#each navLinks as link}
<li>
<a
class="text-white text-3xl font-bold font-serif"
href={`${import.meta.env.BASE_URL}${link.path}`}
onclick={toggleMenu}
>
{link.title}
</a>
</li>
{/each}
</ul>
</div>
{/if}