Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/components/Hamburger.astro

This file was deleted.

16 changes: 12 additions & 4 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
---
import Hamburger from "./Hamburger.astro";
import Menu from "./Menu.astro";
import Navigation from "./Navigation.astro";
import ThemeIcon from "./ThemeIcon.astro";
---

<header>
<nav>
<Hamburger />
<ThemeIcon />
<nav aria-label="Main menu">
<div>
<Menu />
<ThemeIcon />
</div>
<Navigation />
</nav>
</header>

<style>
div {
display: flex;
}
</style>
6 changes: 6 additions & 0 deletions src/components/Menu.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
---

<button aria-expanded="false" aria-controls="main-menu" class="menu">
Menu
</button>
2 changes: 1 addition & 1 deletion src/components/Navigation.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
---
<div class="nav-links">
<div id="main-menu" class="nav-links">
<a href="/">Home</a>
<a href="/about/">About</a>
<a href="/blog/">Blog</a>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ThemeIcon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---

<button id="themeToggle">
<button id="themeToggle" aria-hidden="true" aria-label="Toggle theme">
<svg width="30px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
class="sun"
Expand Down
7 changes: 5 additions & 2 deletions src/scripts/menu.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
document.querySelector('.hamburger').addEventListener('click', () => {
document.querySelector('.nav-links').classList.toggle('expanded');
const menu = document.querySelector('.menu')

menu.addEventListener('click', () => {
const isExpanded = menu.getAttribute('aria-expanded') === 'true';
menu.setAttribute('aria-expanded', !isExpanded);
});
39 changes: 24 additions & 15 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,18 @@ h1 {

/* nav styles */

.hamburger {
padding-right: 20px;
cursor: pointer;
.menu {
background-color: #0d0950;
border: none;
color: #fff;
font-size: 1.2rem;
font-weight: bold;
padding: 5px 10px;
}

.hamburger .line {
display: block;
width: 40px;
height: 5px;
margin-bottom: 10px;
background-color: #ff9776;
}

.nav-links {
width: 100%;
top: 5rem;
left: 48px;
background-color: #ff9776;
display: none;
margin: 0;
}
Expand All @@ -52,14 +46,15 @@ h1 {
font-size: 1.2rem;
font-weight: bold;
text-transform: uppercase;
color: #0d0950;
}

.nav-links a:hover,
.nav-links a:focus {
background-color: #ff9776;
}

.expanded {
:has(.menu[aria-expanded="true"]) .nav-links {
display: unset;
}

Expand All @@ -77,7 +72,7 @@ h1 {
padding: 15px 20px;
}

.hamburger {
.menu {
display: none;
}
}
Expand All @@ -87,6 +82,20 @@ html.dark {
color: #fff;
}

.dark .menu {
background-color: #fff;
color: #000;
}

.dark .nav-links a:hover,
.dark .nav-links a:focus {
color: #0d0950;
}

.dark .nav-links a {
color: #fff;
}

.dark a {
color: #ff9776;
}