|
12 | 12 | import Search from '$lib/features/awesome-privacy/components/search.svelte'; |
13 | 13 | import { cn } from '$lib/utils/cn'; |
14 | 14 |
|
15 | | - const drawerId = 'navbar-drawer'; |
16 | | -
|
17 | | - let { search }: { search: LayoutData['search'] } = $props(); |
| 15 | + const DRAWER_ID = 'navbar-drawer'; |
18 | 16 |
|
19 | 17 | let drawer: HTMLInputElement | undefined; |
20 | 18 |
|
| 19 | + function isPath(base: string) { |
| 20 | + const pathname = page.url.pathname; |
| 21 | +
|
| 22 | + return pathname === base || pathname.startsWith(base + '/'); |
| 23 | + } |
| 24 | +
|
21 | 25 | function toggleDrawer() { |
22 | | - const drawer = document.getElementById(drawerId) as HTMLInputElement; |
| 26 | + const drawer = document.getElementById(DRAWER_ID) as HTMLInputElement; |
| 27 | +
|
23 | 28 | if (drawer) { |
24 | 29 | drawer.checked = !drawer.checked; |
25 | 30 | } |
26 | 31 | } |
| 32 | +
|
| 33 | + let { search }: { search: LayoutData['search'] } = $props(); |
27 | 34 | </script> |
28 | 35 |
|
29 | 36 | <nav class="w-full bg-base-100 shadow-sm"> |
|
37 | 44 |
|
38 | 45 | <div class="ml-auto flex items-center gap-2"> |
39 | 46 | <!-- awesome-privacy search trigger (desktop) --> |
40 | | - <div |
41 | | - class={cn('hidden', page.url.pathname.startsWith(resolve('/awesome-privacy')) && 'block')} |
42 | | - > |
| 47 | + <div class={cn('hidden', isPath(resolve('/awesome-privacy')) && 'block')}> |
43 | 48 | <Search {search} /> |
44 | 49 | </div> |
45 | 50 |
|
|
48 | 53 |
|
49 | 54 | <!-- mobile drawer --> |
50 | 55 | <div class="drawer drawer-end ml-auto w-fit md:hidden"> |
51 | | - <input bind:this={drawer} id={drawerId} type="checkbox" class="drawer-toggle" /> |
| 56 | + <input bind:this={drawer} id={DRAWER_ID} type="checkbox" class="drawer-toggle" /> |
52 | 57 | <div class="drawer-content"> |
53 | 58 | <label |
54 | | - for={drawerId} |
| 59 | + for={DRAWER_ID} |
55 | 60 | class="drawer-button btn btn-square text-base-content/50 btn-ghost" |
56 | 61 | > |
57 | 62 | <Icons.menu class="text-lg" /> |
58 | 63 | </label> |
59 | 64 | </div> |
60 | 65 | <div class="drawer-side"> |
61 | | - <label for={drawerId} aria-label="close drawer" class="drawer-overlay"></label> |
| 66 | + <label for={DRAWER_ID} aria-label="close drawer" class="drawer-overlay"></label> |
62 | 67 |
|
63 | 68 | <div class="flex min-h-full w-80 flex-col bg-base-200 *:w-full"> |
64 | 69 | <div class="w-full bg-base-100 pt-2 pb-1"> |
|
0 commit comments