|
3 | 3 | import { Button } from '$lib/components/ui/button';
|
4 | 4 | import { MenuIcon, XIcon } from 'lucide-svelte';
|
5 | 5 | import ThemeToggler from './ThemeToggler.svelte';
|
| 6 | +
|
6 | 7 | interface link {
|
7 | 8 | label: string;
|
8 | 9 | url: string;
|
9 | 10 | highlight?: boolean;
|
10 | 11 | }
|
| 12 | +
|
11 | 13 | let links: link[] = [
|
12 | 14 | { label: 'Unread', url: '/' },
|
13 | 15 | { label: 'Bookmark', url: '/bookmarks' },
|
|
30 | 32 | links = links;
|
31 | 33 | }
|
32 | 34 | 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 | + } |
33 | 41 | </script>
|
34 | 42 |
|
35 | 43 | <nav class="block w-full sm:mt-3 mb-6">
|
36 | 44 | <div class="flex flex-col items-center w-full sm:max-w-[500px] sm:mx-auto bg-background">
|
37 | 45 | <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" |
39 | 47 | >
|
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> |
41 | 51 | <div class="hidden sm:block">
|
42 | 52 | {#each links as l}
|
43 | 53 | <Button
|
|
64 | 74 | </Button>
|
65 | 75 | </div>
|
66 | 76 |
|
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> |
83 | 93 | </div>
|
84 | 94 | </div>
|
85 | 95 | </nav>
|
0 commit comments