Skip to content

Commit eba7d9d

Browse files
committed
refactor: better navbar
1 parent dee49ce commit eba7d9d

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

frontend/src/lib/components/Navbar.svelte

+28-18
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import { Button } from '$lib/components/ui/button';
44
import { MenuIcon, XIcon } from 'lucide-svelte';
55
import ThemeToggler from './ThemeToggler.svelte';
6+
67
interface link {
78
label: string;
89
url: string;
910
highlight?: boolean;
1011
}
12+
1113
let links: link[] = [
1214
{ label: 'Unread', url: '/' },
1315
{ label: 'Bookmark', url: '/bookmarks' },
@@ -30,14 +32,22 @@
3032
links = links;
3133
}
3234
let showMenu = false;
35+
$: disableBodyScoll(showMenu);
36+
37+
let bodyOverflowDefault = document.body.style.overflow;
38+
function disableBodyScoll(showMenu: boolean) {
39+
document.body.style.overflow = showMenu ? 'hidden' : bodyOverflowDefault;
40+
}
3341
</script>
3442

3543
<nav class="block w-full sm:mt-3 mb-6">
3644
<div class="flex flex-col items-center w-full sm:max-w-[500px] sm:mx-auto bg-background">
3745
<div
38-
class="flex justify-between sm:justify-around w-full px-4 sm:px-6 py-2 sm:py-4 sm:rounded-2xl shadow-md sm:border"
46+
class="flex justify-between sm:justify-around w-full px-4 sm:px-6 py-2 sm:py-4 sm:rounded-2xl shadow sm:border"
3947
>
40-
<img src="/icon-96.png" alt="icon" class="w-10" />
48+
<a href="/">
49+
<img src="/icon-96.png" alt="icon" class="w-10" />
50+
</a>
4151
<div class="hidden sm:block">
4252
{#each links as l}
4353
<Button
@@ -64,22 +74,22 @@
6474
</Button>
6575
</div>
6676

67-
<div class="sm:hidden relative w-full z-[9999]">
68-
{#if showMenu}
69-
<div class="flex flex-col w-full absolute top-0 bg-background shadow-md">
70-
{#each links as l}
71-
<Button
72-
variant="ghost"
73-
href={l.url}
74-
on:click={() => (showMenu = false)}
75-
class="w-full {l.highlight ? 'bg-accent text-accent-foreground' : ''}"
76-
>
77-
{l.label}
78-
</Button>
79-
{/each}
80-
<ThemeToggler className="w-full" />
81-
</div>
82-
{/if}
77+
<div
78+
class={`${showMenu ? 'opacity-100 visible' : 'opacity-0 invisible'} sm:hidden w-full h-screen z-50 fixed top-0 pt-14 pointer-events-none transition-all duration-300 origin-center overflow-y-auto`}
79+
>
80+
<div class="flex flex-col w-full h-full bg-background pointer-events-auto pt-6">
81+
{#each links as l}
82+
<Button
83+
variant="ghost"
84+
href={l.url}
85+
on:click={() => (showMenu = false)}
86+
class={`w-full text-lg h-14 ${l.highlight ? 'bg-accent text-accent-foreground' : ''}`}
87+
>
88+
{l.label}
89+
</Button>
90+
{/each}
91+
<ThemeToggler className="w-full h-14" />
92+
</div>
8393
</div>
8494
</div>
8595
</nav>

0 commit comments

Comments
 (0)