Skip to content

Commit 1b68d23

Browse files
authored
feat: add burger on small screen, with show / hide functionality. (#26)
* feat: add burger on small screen, with show / hide functionality. adjusted CSS * fix import
1 parent a8316d1 commit 1b68d23

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/components/Header.astro

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { Icon } from "astro-icon";
33
4-
const desktop = [
4+
const navItems = [
55
{
66
name: "Snippets",
77
href: "/snippets/",
@@ -16,10 +16,10 @@ const desktop = [
1616

1717
<header class="dark:bg-zinc-900 bg-white max-w-7xl m-auto transition-colors">
1818
<a href="/" class="text-lg sm:text-xl text-black dark:text-zinc-300 hover:dark:text-white transition-colors absolute m-8">Angular Snippets</a>
19-
<nav class="p-8 flex justify-end">
19+
<nav class="p-8 hidden sm:flex justify-end">
2020
<ul class="flex justify-end items-center m-0 space-x-1">
2121
{
22-
desktop.map((item) => (
22+
navItems.map((item) => (
2323
<li>
2424
<a href ={item.href} class="hover:bg-zinc-300 dark:hover:bg-zinc-700 dark:text-zinc-300 text-black p-2 transition-colors rounded-lg">
2525
{item.name}
@@ -36,5 +36,32 @@ const desktop = [
3636
<Icon name="akar-icons:sun" class="w-6 dark:text-white text-black transition-colors hidden dark:block" />
3737
</button>
3838
</nav>
39-
39+
<nav class="p-2 flex sm:hidden justify-end">
40+
<a aria-label="github" class="pointer mx-3 py-6" href="https://github.com/santoshyadavdev/angular-snipptes" target="_blank">
41+
<Icon name="simple-icons:github" class="w-6 dark:text-white text-black" />
42+
</a>
43+
<button aria-label="theme toggle" class="pointer theme-toggle">
44+
<Icon name="eva:moon-outline" class="w-6 dark:text-white text-black transition-colors dark:hidden" />
45+
<Icon name="akar-icons:sun" class="w-6 dark:text-white text-black transition-colors hidden dark:block" />
46+
</button>
47+
<button class="flex sm:hidden justify-end nav-toggle ml-3 mr-6 py-6" aria-label="menu button">
48+
<Icon name="ri:menu-4-line" class="w-6 h-6" />
49+
</button>
50+
</nav>
51+
52+
</header>
53+
54+
<header class="nav-menu hidden bg-white dark:bg-zinc-900">
55+
{
56+
(
57+
<nav class="m-8 flex flex-col inline-flex space-y-1 ">
58+
{navItems.map((navbar) => (
59+
<a href={navbar.href} class="hover:bg-zinc-300 dark:hover:bg-zinc-700 dark:text-zinc-300 text-black p-2 transition-colors rounded-lg">
60+
{navbar.name}
61+
</a>
62+
))}
63+
</nav>
64+
)
65+
}
66+
4067
</header>

src/scripts/main.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
const themeBtn = document.querySelector(".theme-toggle");
1+
const themeBtns = document.querySelectorAll(".theme-toggle");
22
const htmlClassList = document.documentElement.classList;
3-
themeBtn.addEventListener("click", function () {
3+
themeBtns.forEach( btn => btn.addEventListener("click", function () {
4+
45
if (htmlClassList.contains("dark")) {
56
localStorage.setItem("theme", "light");
67
htmlClassList.remove("dark");
78
} else {
89
localStorage.setItem("theme", "dark");
910
htmlClassList.add("dark");
1011
}
12+
}));
13+
14+
const navBtn = document.querySelector(".nav-toggle");
15+
const navMenu = document.querySelector(".nav-menu");
16+
navBtn.addEventListener("click", function () {
17+
navMenu.classList.toggle("hidden");
1118
});

0 commit comments

Comments
 (0)