Skip to content

Commit 574787c

Browse files
committed
feat: adiciona toggle da navegação mobile
1 parent bae36bb commit 574787c

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/components/layout/Header.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import MobileNav from "../navigation/MobileNav.astro";
55
import type { NavLink } from "../navigation/NavLink";
66
77
import List from "phosphor-astro/List.astro"
8+
import ToggleMobileNav from "../navigation/ToggleMobileNav.astro";
89
910
const navigationLinks: NavLink[] = [
1011
{
@@ -34,7 +35,7 @@ const navigationLinks: NavLink[] = [
3435
<!-- Navbar -->
3536
<DesktopNav links={navigationLinks} />
3637
<MobileNav links={navigationLinks} />
37-
<button class="block md:hidden" onclick="toggleNavigation()"><List class="w-8" /></button>
38+
<ToggleMobileNav />
3839
</Fragment>
3940
</Container>
4041
</header>

src/components/navigation/MobileNav.astro

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import type { NavigationProps } from "./NavLink";
44
const { links } = Astro.props as NavigationProps;
55
---
66

7-
<nav class="absolute top-16 left-0 w-screen py-4 overflow-hidden bg-accent-950 block md:hidden">
8-
<ul class="flex flex-col justify-center items-center h-full list-none gap-3">
7+
<nav
8+
id="mobile-navigation"
9+
class="absolute top-16 left-0 w-screen max-h-0 overflow-hidden bg-accent-950 block md:hidden transition-[max-height] duration-300"
10+
>
11+
<ul
12+
class="flex flex-col justify-center items-center h-full list-none gap-3 py-4"
13+
>
914
{
1015
links.map(({ url, label }) => (
1116
<li class="hover:text-accent-500">
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
import List from "phosphor-astro/List.astro";
3+
---
4+
5+
<button id="mobile-toggle-btn" class="block md:hidden"
6+
><List class="w-8" /></button
7+
>
8+
9+
<script>
10+
document.addEventListener("DOMContentLoaded", () => {
11+
const button = document.getElementById("mobile-toggle-btn")!;
12+
const navigation = document.getElementById("mobile-navigation")!;
13+
14+
button.addEventListener("click", () => {
15+
if (navigation.classList.contains("max-h-0")) {
16+
navigation.classList.replace("max-h-0", "max-h-[100px]");
17+
} else {
18+
navigation.classList.replace("max-h-[100px]", "max-h-0");
19+
}
20+
});
21+
});
22+
</script>

0 commit comments

Comments
 (0)