@@ -44,11 +44,56 @@ const navLinks = [
4444
4545 <a
4646 href =" https://cloud.livedot.dev"
47- class =" font-headline rounded-md bg-primary px-5 py-2 text-sm font-semibold tracking-[-0.03em] text-on-primary-container transition-transform hover:bg-primary-container active:scale-95"
47+ class =" hidden font-headline rounded-md bg-primary px-5 py-2 text-sm font-semibold tracking-[-0.03em] text-on-primary-container transition-transform hover:bg-primary-container active:scale-95 md:inline-flex "
4848 >
4949 Cloud
5050 </a >
51+
52+ <button
53+ type =" button"
54+ data-mobile-menu-toggle
55+ aria-expanded =" false"
56+ aria-controls =" mobile-nav"
57+ class =" inline-flex h-11 w-11 items-center justify-center rounded-md border border-white/10 text-on-surface-variant transition-colors hover:border-white/20 hover:text-white md:hidden"
58+ >
59+ <span class =" sr-only" >Toggle navigation menu</span >
60+ <svg class =" h-5 w-5" viewBox =" 0 0 24 24" fill =" none" stroke =" currentColor" stroke-width =" 1.8" stroke-linecap =" round" >
61+ <path d =" M4 7h16" />
62+ <path d =" M4 12h16" />
63+ <path d =" M4 17h16" />
64+ </svg >
65+ </button >
5166 </nav >
67+
68+ <div
69+ id =" mobile-nav"
70+ data-mobile-menu
71+ class =" hidden border-t border-white/5 bg-surface/95 px-6 pb-6 pt-4 backdrop-blur-md md:hidden"
72+ >
73+ <div class =" flex flex-col gap-3 font-headline tracking-tight" >
74+ { navLinks .map ((link ) => (
75+ <a
76+ href = { link .href }
77+ data-mobile-menu-link
78+ aria-current = { pathname === link .href ? " page" : undefined }
79+ class :list = { [
80+ " rounded-lg border border-white/8 px-4 py-3 text-on-surface-variant transition-colors hover:border-white/15 hover:text-white" ,
81+ pathname === link .href ? " border-primary/40 bg-primary/8 text-primary" : " " ,
82+ ]}
83+ >
84+ { link .label }
85+ </a >
86+ ))}
87+
88+ <a
89+ href =" https://cloud.livedot.dev"
90+ data-mobile-menu-link
91+ class =" mt-2 inline-flex items-center justify-center rounded-lg bg-primary px-4 py-3 text-sm font-semibold tracking-[-0.03em] text-on-primary-container transition-transform hover:bg-primary-container active:scale-95"
92+ >
93+ Cloud
94+ </a >
95+ </div >
96+ </div >
5297</header >
5398
5499<script >
@@ -111,4 +156,40 @@ const navLinks = [
111156 } else {
112157 initSectionNav();
113158 }
159+
160+ const initMobileMenu = () => {
161+ const toggle = document.querySelector("[data-mobile-menu-toggle]");
162+ const menu = document.querySelector("[data-mobile-menu]");
163+ const menuLinks = Array.from(document.querySelectorAll("[data-mobile-menu-link]"));
164+
165+ if (!(toggle instanceof HTMLButtonElement) || !(menu instanceof HTMLElement)) {
166+ return;
167+ }
168+
169+ const setOpen = (open) => {
170+ toggle.setAttribute("aria-expanded", open ? "true" : "false");
171+ menu.classList.toggle("hidden", !open);
172+ };
173+
174+ toggle.addEventListener("click", () => {
175+ const isOpen = toggle.getAttribute("aria-expanded") === "true";
176+ setOpen(!isOpen);
177+ });
178+
179+ menuLinks.forEach((link) => {
180+ link.addEventListener("click", () => setOpen(false));
181+ });
182+
183+ window.addEventListener("resize", () => {
184+ if (window.innerWidth >= 768) {
185+ setOpen(false);
186+ }
187+ });
188+ };
189+
190+ if (document.readyState === "loading") {
191+ document.addEventListener("DOMContentLoaded", initMobileMenu, { once: true });
192+ } else {
193+ initMobileMenu();
194+ }
114195</script >
0 commit comments