feat: navbar responsive avec menu hamburger mobile

- Création composant MobileMenu.jsx avec React
- Menu slide-in depuis la droite
- Animation hamburger vers X
- Overlay semi-transparent
- Navigation desktop/mobile adaptative
- Design minimal et élégant
This commit is contained in:
2025-12-08 21:34:32 +00:00
parent 4d1ed1e515
commit 9a64abff76
2 changed files with 107 additions and 1 deletions

View File

@@ -0,0 +1,100 @@
import { useState } from 'react';
export default function MobileMenu({ currentPath }) {
const [isOpen, setIsOpen] = useState(false);
const links = [
{ href: '/', label: 'Home' },
{ href: '/about', label: 'About' },
{ href: '/contact', label: 'Contact' },
];
return (
<>
{/* Hamburger Button */}
<button
onClick={() => setIsOpen(!isOpen)}
className="md:hidden flex flex-col gap-1.5 p-2 hover:bg-gray-100 rounded transition-colors"
aria-label="Toggle menu"
>
<span
className={`block w-6 h-0.5 bg-gray-900 transition-transform ${isOpen ? 'rotate-45 translate-y-2' : ''
}`}
/>
<span
className={`block w-6 h-0.5 bg-gray-900 transition-opacity ${isOpen ? 'opacity-0' : ''
}`}
/>
<span
className={`block w-6 h-0.5 bg-gray-900 transition-transform ${isOpen ? '-rotate-45 -translate-y-2' : ''
}`}
/>
</button>
{/* Mobile Menu Overlay */}
{isOpen && (
<div
className="fixed inset-0 bg-black/20 z-40 md:hidden"
onClick={() => setIsOpen(false)}
/>
)}
{/* Mobile Menu Panel */}
<div
className={`fixed top-0 right-0 h-full w-64 bg-white shadow-xl z-50 transform transition-transform duration-300 md:hidden ${isOpen ? 'translate-x-0' : 'translate-x-full'
}`}
>
<div className="flex flex-col h-full">
{/* Header */}
<div className="flex items-center justify-between p-6 border-b border-gray-200">
<span className="text-lg font-semibold text-gray-900">Menu</span>
<button
onClick={() => setIsOpen(false)}
className="p-2 hover:bg-gray-100 rounded transition-colors"
aria-label="Close menu"
>
<svg
className="w-6 h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
{/* Navigation Links */}
<nav className="flex-1 p-6">
<ul className="space-y-4">
{links.map((link) => (
<li key={link.href}>
<a
href={link.href}
className={`block py-3 px-4 rounded-lg text-base font-medium transition-colors ${currentPath === link.href
? 'bg-gray-900 text-white'
: 'text-gray-700 hover:bg-gray-100'
}`}
onClick={() => setIsOpen(false)}
>
{link.label}
</a>
</li>
))}
</ul>
</nav>
{/* Footer */}
<div className="p-6 border-t border-gray-200">
<p className="text-xs text-gray-500">Astro Starter Kit</p>
</div>
</div>
</div>
</>
);
}

View File

@@ -1,4 +1,6 @@
--- ---
import MobileMenu from "./MobileMenu.jsx";
const currentPath = Astro.url.pathname; const currentPath = Astro.url.pathname;
--- ---
@@ -12,7 +14,8 @@ const currentPath = Astro.url.pathname;
Starter Kit Starter Kit
</a> </a>
<div class="flex gap-8"> {/* Desktop Navigation */}
<div class="hidden md:flex gap-8">
<a <a
href="/" href="/"
class:list={[ class:list={[
@@ -47,6 +50,9 @@ const currentPath = Astro.url.pathname;
Contact Contact
</a> </a>
</div> </div>
{/* Mobile Menu */}
<MobileMenu currentPath={currentPath} client:load />
</div> </div>
</div> </div>
</nav> </nav>