mirror of
https://github.com/10h30/jpadventure.git
synced 2026-05-12 15:21:19 +09:00
Add Menu component and implement toggle functionality in the header
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
---
|
---
|
||||||
import Navigation from "./Navigation.astro";
|
import Navigation from "./Navigation.astro";
|
||||||
|
import Menu from "./Menu.astro";
|
||||||
---
|
---
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<nav>
|
<nav>
|
||||||
|
<Menu />
|
||||||
<Navigation />
|
<Navigation />
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<button aria-expanded='false' aria-controls='main-menu' class='menu'>
|
||||||
|
Menu
|
||||||
|
</button>
|
||||||
@@ -22,5 +22,8 @@ import "../styles/global.css";
|
|||||||
<li><a href='/posts/post-3/'>Post 3</a></li>
|
<li><a href='/posts/post-3/'>Post 3</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
<script>
|
||||||
|
import "../scripts/menu.js";
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -18,5 +18,8 @@ const pageTitle = "Thuan's Astro Page";
|
|||||||
<Header />
|
<Header />
|
||||||
<h1>{pageTitle}</h1>
|
<h1>{pageTitle}</h1>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
<script>
|
||||||
|
import "../scripts/menu.js";
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const menu = document.querySelector('.menu');
|
||||||
|
|
||||||
|
menu?.addEventListener('click', () => {
|
||||||
|
const isExpanded = menu.getAttribute('aria-expanded') === 'true';
|
||||||
|
menu.setAttribute('aria-expanded', `${!isExpanded}`);
|
||||||
|
});
|
||||||
@@ -21,6 +21,14 @@ h1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* nav styles */
|
/* nav styles */
|
||||||
|
.menu {
|
||||||
|
background-color: #0d0950;
|
||||||
|
border: none;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.nav-links {
|
.nav-links {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -44,6 +52,10 @@ h1 {
|
|||||||
background-color: #ff9776;
|
background-color: #ff9776;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:has(.menu[aria-expanded="true"]) .nav-links {
|
||||||
|
display: unset;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 636px) {
|
@media screen and (min-width: 636px) {
|
||||||
.nav-links {
|
.nav-links {
|
||||||
margin-left: 5em;
|
margin-left: 5em;
|
||||||
@@ -57,6 +69,10 @@ h1 {
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 15px 20px;
|
padding: 15px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menu {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
|
|||||||
Reference in New Issue
Block a user