mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-22 16:10:40 +07:00
feat: personal engineering portfolio with routing, theme toggle, and responsive design
- React + TypeScript + Vite + React Router v6 - Dark/light/system theme toggle (fixed cycle from 'system' state) - Multi-page SPA: Home, About, Experience, Projects, Engineering, Contact - Responsive layout with mobile menu - Data-driven sections (profile, skills, experience, projects) - CSS Modules-compatible with CSS variables for theming - Accessibility: skip-link, ARIA labels, keyboard navigation
This commit is contained in:
1 parent
0273f555de
commit
7e42bd8017
38 files changed
+2921
-358
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Link, NavLink, useLocation } from 'react-router-dom'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
|
||||
const navItems = [
|
||||
{ label: 'Home', path: '/' },
|
||||
{ label: 'About', path: '/about' },
|
||||
{ label: 'Experience', path: '/experience' },
|
||||
{ label: 'Projects', path: '/projects' },
|
||||
{ label: 'Engineering', path: '/engineering' },
|
||||
{ label: 'Contact', path: '/contact' },
|
||||
]
|
||||
|
||||
export function Navigation() {
|
||||
const { cycleTheme, resolvedTheme } = useTheme()
|
||||
const [mobileOpen, setMobileOpen] = useState(false)
|
||||
const location = useLocation()
|
||||
|
||||
useEffect(() => {
|
||||
if (mobileOpen) {
|
||||
document.body.style.overflow = 'hidden'
|
||||
} else {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
return () => {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
}, [mobileOpen])
|
||||
|
||||
useEffect(() => {
|
||||
setMobileOpen(false)
|
||||
}, [location.pathname])
|
||||
|
||||
return (
|
||||
<>
|
||||
<nav className="nav" role="navigation" aria-label="Main navigation">
|
||||
<div className="nav-container">
|
||||
<Link to="/" className="nav-logo">
|
||||
Portfolio
|
||||
</Link>
|
||||
|
||||
<ul className="nav-menu">
|
||||
{navItems.map((item) => (
|
||||
<li key={item.path}>
|
||||
<NavLink
|
||||
to={item.path}
|
||||
className={({ isActive }) =>
|
||||
isActive ? 'nav-link active' : 'nav-link'
|
||||
}
|
||||
>
|
||||
{item.label}
|
||||
</NavLink>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<div className="nav-actions">
|
||||
<button
|
||||
className="theme-toggle"
|
||||
onClick={cycleTheme}
|
||||
aria-label={`Switch theme (currently ${resolvedTheme})`}
|
||||
title={`Theme: ${resolvedTheme}`}
|
||||
>
|
||||
{resolvedTheme === 'dark' ? (
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="12" cy="12" r="5" />
|
||||
<path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="mobile-menu-btn"
|
||||
onClick={() => setMobileOpen(!mobileOpen)}
|
||||
aria-label={mobileOpen ? 'Close menu' : 'Open menu'}
|
||||
aria-expanded={mobileOpen}
|
||||
>
|
||||
{mobileOpen ? (
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M18 6L6 18M6 6l12 12" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M3 12h18M3 6h18M3 18h18" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div className={`mobile-menu ${mobileOpen ? 'open' : ''}`} role="dialog" aria-label="Mobile navigation">
|
||||
<ul className="mobile-menu-list">
|
||||
{navItems.map((item) => (
|
||||
<li key={item.path}>
|
||||
<NavLink
|
||||
to={item.path}
|
||||
className={({ isActive }) =>
|
||||
isActive ? 'mobile-menu-link active' : 'mobile-menu-link'
|
||||
}
|
||||
onClick={() => setMobileOpen(false)}
|
||||
>
|
||||
{item.label}
|
||||
</NavLink>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user