This repository was archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNav.svelte
110 lines (102 loc) · 2.77 KB
/
Nav.svelte
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<script>
// @ts-check
import { page } from '$app/stores';
import { fly, fade } from 'svelte/transition';
import { cubicInOut } from 'svelte/easing';
const slugRegex = /^(?:\d{3}-)([a-z-]+)(?:\.svx)$/;
const inConfig = {
x: 50,
duration: 300,
easing: cubicInOut,
};
const outConfig = {
x: 200,
duration: 300,
easing: cubicInOut,
};
/** @type {{
* title: string;
* description: string;
* filename: string;
* }[]} */
export let pages = [];
let expanded = false;
/** @param { string } filename */
function slug(filename) {
return filename.match(slugRegex)[1];
}
function toggleExpand() {
expanded = !expanded;
}
</script>
{#if expanded}
<div
class="modal-blocker"
on:click={() => {
expanded = false;
}}
transition:fade={{
duration: 300,
}}
/>
{/if}
<button class:expanded on:click={toggleExpand}>
MENU
{#if expanded}
<nav class:expanded in:fly={inConfig} out:fly={outConfig}>
<ul>
{#each pages as { title, filename } (filename)}
<li
class:active={$page.path === `/learn/${slug(filename)}`}
>
<a href="/learn/{slug(filename)}">
<span>
{title}
</span>
</a>
</li>
{/each}
<li>
<a href="https://discord.gg/j7NhbT2DSY">
<span>Unofficial Discord Server</span>
</a>
</li>
</ul>
</nav>
{/if}
</button>
<style>
.modal-blocker {
@apply fixed inset-0 bg-gray-900 opacity-20 z-40;
}
button {
@apply relative;
@apply pt-2 pb-1 px-4 bg-gray-700 text-gray-50;
@apply hover:bg-gray-600;
@apply rounded-none shadow;
@apply hover:shadow-md transition-all;
@apply outline-none;
@apply z-50;
}
button.expanded {
@apply bg-orange-600 text-orange-100;
}
nav {
@apply absolute top-10 right-0 block;
@apply text-right;
@apply rounded-none z-50 shadow-md;
@apply bg-gray-700;
}
nav li a {
@apply block pt-2 pb-1 pl-8 pr-4;
@apply bg-gradient-to-r from-gray-700 to-gray-700 text-gray-300;
@apply hover:text-gray-200;
@apply hover:to-gray-600;
@apply transition-colors;
@apply whitespace-nowrap;
}
nav li.active a {
@apply text-gray-100;
@apply bg-gradient-to-r from-gray-700 via-gray-600 to-gray-600;
}
</style>