From f4ea213f438021baad44d8dfd0b75ae5466f7194 Mon Sep 17 00:00:00 2001 From: Tiwalade Ladele Date: Sat, 5 Sep 2026 17:44:28 +0100 Subject: [PATCH] feat: implement mobile responsive navigation menu with hamburger toggle --- src/App.css | 82 ++++++++++++++++++++++++++++++++++++--- src/components/Navbar.jsx | 31 +++++++++++++-- 2 files changed, 105 insertions(+), 8 deletions(-) diff --git a/src/App.css b/src/App.css index 73a237a..c94f445 100644 --- a/src/App.css +++ b/src/App.css @@ -199,6 +199,51 @@ html[data-theme="dark"] .welcome p { flex-shrink: 0; } +.navbar-toggle { + display: none; + background: transparent; + border: none; + cursor: pointer; + padding: 0.4rem; + flex-direction: column; + justify-content: space-between; + width: 2rem; + height: 1.75rem; + z-index: 11; + border-radius: 4px; +} + +.navbar-toggle:focus-visible { + outline: 2px solid #8e8dd3; + outline-offset: 2px; +} + +.hamburger-line { + display: block; + width: 100%; + height: 2px; + background-color: #213547; + border-radius: 2px; + transition: transform 0.3s ease, opacity 0.3s ease, background-color 0.3s ease; + transform-origin: center; +} + +html[data-theme="dark"] .hamburger-line { + background-color: #7da2c3; +} + +.navbar-toggle.open .hamburger-line:nth-child(1) { + transform: translateY(7px) rotate(45deg); +} + +.navbar-toggle.open .hamburger-line:nth-child(2) { + opacity: 0; +} + +.navbar-toggle.open .hamburger-line:nth-child(3) { + transform: translateY(-7px) rotate(-45deg); +} + .navbar-links { display: flex; gap: 1.75rem; @@ -253,17 +298,44 @@ html[data-theme="dark"] .navbar-link { @media (max-width: 600px) { .navbar { - padding: 0.75rem 1rem; + padding: 0.75rem 1.25rem; } .navbar-content { - flex-direction: column; - align-items: flex-start; - gap: 0.6rem; + flex-direction: row; + align-items: center; + justify-content: space-between; + gap: 0; + } + + .navbar-toggle { + display: flex; } .navbar-links { - gap: 1.1rem; + width: 100%; + flex-direction: column; + gap: 1rem; + max-height: 0; + opacity: 0; + overflow: hidden; + pointer-events: none; + transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease; + padding-top: 0; + } + + .navbar-links.is-active { + max-height: 250px; + opacity: 1; + pointer-events: auto; + padding-top: 1rem; + } + + .navbar-link { + display: block; + width: 100%; + padding: 0.4rem 0; + font-size: 1rem; } } diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index f5ff7a7..ce6a134 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -1,16 +1,39 @@ +import { useState } from "react"; import { NavLink } from "react-router-dom"; function Navbar() { + const [isMenuOpen, setIsMenuOpen] = useState(false); + + const toggleMenu = () => { + setIsMenuOpen((prev) => !prev); + }; + + const closeMenu = () => { + setIsMenuOpen(false); + }; + return (
- + React Open Source -