@@ -58,20 +58,86 @@ import { SITE_TITLE } from "../consts";
5858 </div >
5959</header >
6060
61- <!-- Mobile Menu (Dropdown) -->
62- <div id =" mobile-menu" class =" md:hidden hidden px-4 pb-4" >
63- <nav class =" flex flex-col space-y-2" >
64- <a href =" /" class =" text-gray-700 hover:text-blue-600" >Home</a >
65- </nav >
61+ <!-- Mobile Menu Overlay -->
62+ <div id =" menu-overlay" class =" fixed inset-0 bg-black bg-opacity-0 z-40 hidden transition-opacity duration-300" ></div >
63+
64+ <!-- Mobile Menu (Slide from Right) -->
65+ <div id =" mobile-menu" class =" fixed top-0 right-0 h-full w-full sm:w-80 bg-white dark:bg-gray-900 shadow-xl z-50 transform translate-x-full transition-transform duration-300 ease-in-out" >
66+ <div class =" flex flex-col h-full" >
67+ <!-- Menu Header -->
68+ <div class =" flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700" >
69+ <h2 class =" text-xl font-bold text-gray-900 dark:text-white" >Menu</h2 >
70+ <button id =" menu-close" class =" text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400" >
71+ <svg xmlns =" http://www.w3.org/2000/svg" class =" h-6 w-6" fill =" none" viewBox =" 0 0 24 24" stroke =" currentColor" >
72+ <path stroke-linecap =" round" stroke-linejoin =" round" stroke-width =" 2" d =" M6 18L18 6M6 6l12 12" />
73+ </svg >
74+ </button >
75+ </div >
76+
77+ <!-- Menu Content -->
78+ <nav class =" flex-1 overflow-y-auto p-4" >
79+ <div class =" flex flex-col space-y-4" >
80+ <a href =" /" class =" text-lg text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 py-2 border-b border-gray-200 dark:border-gray-700" >Home</a >
81+ <a href =" /blog" class =" text-lg text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 py-2 border-b border-gray-200 dark:border-gray-700" >Blog</a >
82+ <a href =" /produk" class =" text-lg text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 py-2 border-b border-gray-200 dark:border-gray-700" >Produk</a >
83+ <a href =" /about" class =" text-lg text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 py-2 border-b border-gray-200 dark:border-gray-700" >About</a >
84+ </div >
85+ </nav >
86+ </div >
6687</div >
6788
6889<header >
6990 <script type =" module" >
7091 const menuToggle = document.getElementById("menu-toggle");
92+ const menuClose = document.getElementById("menu-close");
7193 const mobileMenu = document.getElementById("mobile-menu");
94+ const menuOverlay = document.getElementById("menu-overlay");
95+
96+ function openMenu() {
97+ // Show overlay
98+ menuOverlay.classList.remove("hidden");
99+ // Trigger reflow for animation
100+ menuOverlay.offsetHeight;
101+ menuOverlay.classList.remove("bg-opacity-0");
102+ menuOverlay.classList.add("bg-opacity-50");
103+
104+ // Slide menu in
105+ mobileMenu.classList.remove("translate-x-full");
106+
107+ // Prevent body scroll
108+ document.body.style.overflow = "hidden";
109+ }
110+
111+ function closeMenu() {
112+ // Slide menu out
113+ mobileMenu.classList.add("translate-x-full");
114+
115+ // Hide overlay
116+ menuOverlay.classList.remove("bg-opacity-50");
117+ menuOverlay.classList.add("bg-opacity-0");
118+
119+ // Wait for animation to complete before hiding
120+ setTimeout(() => {
121+ menuOverlay.classList.add("hidden");
122+ }, 300);
123+
124+ // Restore body scroll
125+ document.body.style.overflow = "";
126+ }
127+
128+ // Open menu
129+ menuToggle.addEventListener("click", openMenu);
130+
131+ // Close menu via close button
132+ menuClose.addEventListener("click", closeMenu);
133+
134+ // Close menu when clicking overlay
135+ menuOverlay.addEventListener("click", closeMenu);
72136
73- menuToggle.addEventListener("click", () => {
74- mobileMenu.classList.toggle("hidden");
137+ // Close menu when clicking menu links
138+ const menuLinks = mobileMenu.querySelectorAll("a");
139+ menuLinks.forEach(link => {
140+ link.addEventListener("click", closeMenu);
75141 });
76142 </script >
77143
0 commit comments