Skip to content

Commit 04d9a10

Browse files
committed
feat(github): add mobile navigation toggle and update navbar for responsiveness
1 parent 030d3ff commit 04d9a10

1 file changed

Lines changed: 100 additions & 2 deletions

File tree

src/components/Navbar.astro

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const navLinks = [
6363
</span>
6464
<a
6565
href="/login?callbackUrl=%2Fentrar"
66-
class="inline-flex items-center gap-2 h-8 px-3 text-[12px] font-medium rounded-full bg-white/5 text-ink-100 hover:bg-white/10 transition-colors"
66+
class="hidden md:inline-flex items-center gap-2 h-8 px-3 text-[12px] font-medium rounded-full bg-white/5 text-ink-100 hover:bg-white/10 transition-colors"
6767
>
6868
<svg
6969
xmlns="http://www.w3.org/2000/svg"
@@ -84,7 +84,7 @@ const navLinks = [
8484
</a>
8585
<a
8686
href="/contact"
87-
class="inline-flex items-center gap-2 h-8 px-3 text-[12px] font-medium rounded-full bg-cyan text-ink-950 hover:brightness-110 transition-all"
87+
class="hidden md:inline-flex items-center gap-2 h-8 px-3 text-[12px] font-medium rounded-full bg-cyan text-ink-950 hover:brightness-110 transition-all"
8888
>
8989
<svg
9090
xmlns="http://www.w3.org/2000/svg"
@@ -101,6 +101,104 @@ const navLinks = [
101101
</svg>
102102
Contáctame
103103
</a>
104+
105+
<!-- Mobile menu button -->
106+
<button
107+
id="navbar-toggle"
108+
type="button"
109+
aria-expanded="false"
110+
aria-controls="navbar-mobile-panel"
111+
aria-label="Abrir menú"
112+
class="md:hidden inline-flex items-center justify-center w-9 h-9 rounded-full bg-white/5 text-ink-100 hover:bg-white/10 transition-colors"
113+
>
114+
<svg
115+
id="navbar-toggle-icon-open"
116+
xmlns="http://www.w3.org/2000/svg"
117+
width="18"
118+
height="18"
119+
viewBox="0 0 24 24"
120+
fill="none"
121+
stroke="currentColor"
122+
stroke-width="2"
123+
stroke-linecap="round"
124+
stroke-linejoin="round"
125+
>
126+
<path d="M4 6h16M4 12h16M4 18h16"></path>
127+
</svg>
128+
<svg
129+
id="navbar-toggle-icon-close"
130+
xmlns="http://www.w3.org/2000/svg"
131+
width="18"
132+
height="18"
133+
viewBox="0 0 24 24"
134+
fill="none"
135+
stroke="currentColor"
136+
stroke-width="2"
137+
stroke-linecap="round"
138+
stroke-linejoin="round"
139+
class="hidden"
140+
>
141+
<path d="M18 6 6 18M6 6l12 12"></path>
142+
</svg>
143+
</button>
104144
</div>
105145
</div>
146+
147+
<!-- Mobile nav panel -->
148+
<div
149+
id="navbar-mobile-panel"
150+
class="hidden md:hidden glass-strong rounded-3xl mt-2 p-3 flex flex-col gap-1"
151+
>
152+
{
153+
navLinks.map((link) => {
154+
const isActive = currentPath.startsWith(link.href);
155+
return (
156+
<a
157+
href={link.href}
158+
class={`px-4 py-2.5 rounded-full text-[13px] font-mono transition-colors hover:bg-white/5 ${isActive ? "text-cyan" : "text-ink-100"}`}
159+
>
160+
{link.label}
161+
</a>
162+
);
163+
})
164+
}
165+
<div class="h-px bg-white/10 my-1"></div>
166+
<a
167+
href="/login?callbackUrl=%2Fentrar"
168+
class="px-4 py-2.5 rounded-full text-[13px] font-mono text-ink-100 hover:bg-white/5 transition-colors"
169+
>
170+
Login
171+
</a>
172+
<a
173+
href="/contact"
174+
class="inline-flex items-center justify-center h-9 px-4 mt-1 text-[13px] font-medium rounded-full bg-cyan text-ink-950 hover:brightness-110 transition-all"
175+
>
176+
Contáctame
177+
</a>
178+
</div>
106179
</header>
180+
181+
<script>
182+
const toggle = document.getElementById("navbar-toggle");
183+
const panel = document.getElementById("navbar-mobile-panel");
184+
const iconOpen = document.getElementById("navbar-toggle-icon-open");
185+
const iconClose = document.getElementById("navbar-toggle-icon-close");
186+
187+
toggle?.addEventListener("click", () => {
188+
const isOpen = panel?.classList.toggle("hidden") === false;
189+
toggle.setAttribute("aria-expanded", String(isOpen));
190+
toggle.setAttribute("aria-label", isOpen ? "Cerrar menú" : "Abrir menú");
191+
iconOpen?.classList.toggle("hidden", isOpen);
192+
iconClose?.classList.toggle("hidden", !isOpen);
193+
});
194+
195+
panel?.querySelectorAll("a").forEach((link) => {
196+
link.addEventListener("click", () => {
197+
panel.classList.add("hidden");
198+
toggle?.setAttribute("aria-expanded", "false");
199+
toggle?.setAttribute("aria-label", "Abrir menú");
200+
iconOpen?.classList.remove("hidden");
201+
iconClose?.classList.add("hidden");
202+
});
203+
});
204+
</script>

0 commit comments

Comments
 (0)