Skip to content

Commit ccbc03c

Browse files
Merge pull request #86 from abakus-ntnu/feature/mobile-nav
Refine mobile navigation layout and behavior
2 parents 1ab858e + 0d0f365 commit ccbc03c

File tree

5 files changed

+112
-137
lines changed

5 files changed

+112
-137
lines changed

src/components/Header/Header.astro

Lines changed: 101 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,117 @@
11
---
22
import Logo from "../Branding/Logo.astro";
3-
import Navbar from "./Navbar/Navbar.astro";
43
import ThemeSwitcher from "./ThemeSwitcher.astro";
5-
64
import MobileNavbar from "./MobileNavbar/MobileNavbar";
5+
import { Menu, X, Scroll, Users, Image, Drama } from "lucide-astro";
6+
import { SOCIALS } from "@/lib/constants";
77
8-
import { AlignJustify as Hamburger } from "lucide-astro";
9-
10-
const ITEMS = {
11-
"/opptak": "Opptak",
12-
"/om_oss": "Om oss",
13-
"/galleri": "Bildegalleri",
14-
"/revyer": "Tidligere revyer",
15-
};
8+
const PAGES = [
9+
{ href: "/opptak", title: "Opptak", Icon: Scroll },
10+
{ href: "/om_oss", title: "Om oss", Icon: Users },
11+
{ href: "/galleri", title: "Bildegalleri", Icon: Image },
12+
{ href: "/revyer", title: "Tidligere revyer", Icon: Drama },
13+
];
1614
---
1715

18-
<header class="w-full">
19-
<div
20-
class="container mx-auto flex h-32 items-center justify-between px-6 py-3"
21-
>
16+
<header id="header" class="z-50 w-full">
17+
<div class="mx-auto flex h-32 items-center justify-between px-6 py-3">
2218
<a href="/" data-astro-prefetch="load">
2319
<Logo />
2420
</a>
2521

26-
<div class="md:text-red flex gap-6">
27-
<div class="hidden md:flex">
28-
<Navbar items={ITEMS} />
29-
</div>
22+
<nav class="hidden items-center justify-center gap-4 md:flex lg:gap-6">
23+
{
24+
PAGES.map(({ href, title }) => (
25+
<a
26+
class="text-lg text-foreground transition-colors hover:text-accent"
27+
href={href}
28+
data-astro-prefetch="load"
29+
>
30+
{title}
31+
</a>
32+
))
33+
}
34+
<ThemeSwitcher mobile="false" />
35+
</nav>
3036

31-
<ThemeSwitcher />
37+
<div class="flex items-center gap-1 md:hidden">
38+
<ThemeSwitcher mobile="true" />
39+
<button
40+
id="menuButton"
41+
class="relative h-8 w-8 p-1"
42+
aria-label="Toggle Menu"
43+
>
44+
<Menu class="icon-menu transition-all" />
45+
<X
46+
class="icon-close absolute inset-1 rotate-90 opacity-0 transition-all"
47+
/>
48+
</button>
49+
</div>
50+
</div>
3251

33-
<div class="flex md:hidden">
34-
<MobileNavbar client:load items={ITEMS}>
35-
<span class="text-foreground transition-colors hover:text-accent">
36-
<Hamburger />
37-
</span>
38-
</MobileNavbar>
39-
</div>
52+
<div
53+
id="mobileMenu"
54+
class="pointer-events-none absolute inset-x-0 top-full flex h-[calc(100vh-4rem)] flex-col gap-6 bg-background px-6 text-foreground opacity-0 md:hidden"
55+
>
56+
<div class="flex flex-col gap-4">
57+
<span class="text-[1.5rem] font-semibold">Sider</span>
58+
{
59+
PAGES.map(({ href, title, Icon }) => (
60+
<a
61+
class="flex gap-3 text-lg text-foreground transition-colors hover:text-accent"
62+
href={href}
63+
data-astro-prefetch="load"
64+
>
65+
<Icon />
66+
{title}
67+
</a>
68+
))
69+
}
70+
</div>
71+
<div class="flex flex-col gap-4">
72+
<span class="text-[1.5rem] font-semibold">Kontakt oss</span>
73+
{
74+
SOCIALS.map(({ name, href, external, Icon }) => (
75+
<a
76+
class="flex gap-3 text-lg text-foreground transition-colors hover:text-accent"
77+
href={href}
78+
target={external ? "_blank" : "_self"}
79+
data-astro-prefetch="load"
80+
>
81+
<Icon />
82+
{name}
83+
</a>
84+
))
85+
}
4086
</div>
4187
</div>
88+
<script is:inline>
89+
const header = document.getElementById("header");
90+
const menuButton = document.getElementById("menuButton");
91+
const menuIcon = menuButton.querySelector(".icon-menu");
92+
const closeIcon = menuButton.querySelector(".icon-close");
93+
94+
let menuOpen = false;
95+
96+
menuButton.addEventListener("click", () => {
97+
menuOpen = !menuOpen;
98+
99+
menuIcon.classList.toggle("rotate-90", menuOpen);
100+
menuIcon.classList.toggle("opacity-0", menuOpen);
101+
closeIcon.classList.toggle("rotate-0", menuOpen);
102+
closeIcon.classList.toggle("opacity-100", menuOpen);
103+
104+
if (menuOpen) {
105+
header.classList.add("fixed", "top-0", "left-0", "bg-background");
106+
mobileMenu.classList.add("opacity-100");
107+
mobileMenu.classList.remove("pointer-events-none");
108+
document.body.style.overflow = "hidden";
109+
} else {
110+
header.classList.remove("fixed", "top-0", "left-0", "bg-background");
111+
mobileMenu.classList.remove("opacity-100");
112+
mobileMenu.classList.add("pointer-events-none");
113+
document.body.style.overflow = "";
114+
}
115+
});
116+
</script>
42117
</header>

src/components/Header/MobileNavbar/MobileNavbar.tsx

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/components/Header/Navbar/NavLink.astro

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/components/Header/Navbar/Navbar.astro

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/components/Header/ThemeSwitcher.astro

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import { Sun, MoonStar } from "lucide-astro";
33
---
44

5-
<button
6-
id="themeSwitcher"
7-
class="text-foreground transition-colors hover:text-accent"
8-
>
5+
<button class="text-foreground transition-colors hover:text-accent">
96
<span class="hidden hover:text-yellow-500 dark:block">
107
<Sun />
118
</span>
@@ -15,12 +12,15 @@ import { Sun, MoonStar } from "lucide-astro";
1512
</button>
1613

1714
<script is:inline>
18-
function switchTheme() {
19-
let nowPresent = window.document.documentElement.classList.toggle("dark");
20-
localStorage.setItem("darkTheme", nowPresent);
15+
{
16+
document.currentScript.previousElementSibling.addEventListener(
17+
"click",
18+
() => {
19+
localStorage.setItem(
20+
"darkTheme",
21+
document.documentElement.classList.toggle("dark"),
22+
);
23+
},
24+
);
2125
}
22-
23-
window.document
24-
.getElementById("themeSwitcher")
25-
.addEventListener("click", switchTheme);
2626
</script>

0 commit comments

Comments
 (0)