fix: simplify navigation and mobile menu
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Link, NavLink, useLocation } from 'react-router-dom'
|
import { Link, NavLink } from 'react-router-dom'
|
||||||
import { PRIMARY_NAV, GLOBAL_RESIDENT } from '@/data/nav'
|
import { PRIMARY_NAV, GLOBAL_RESIDENT } from '@/data/nav'
|
||||||
import './layout.css'
|
import './layout.css'
|
||||||
|
|
||||||
export default function Navbar() {
|
export default function Navbar() {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const location = useLocation()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="site-header">
|
<header className="site-header">
|
||||||
@@ -18,7 +17,7 @@ export default function Navbar() {
|
|||||||
</span>
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<nav className={`nav-menu ${open ? 'open' : ''}`} aria-label="主导航(冻结6项)">
|
<nav className="nav-menu" aria-label="主导航">
|
||||||
{PRIMARY_NAV.map(item => (
|
{PRIMARY_NAV.map(item => (
|
||||||
<NavLink
|
<NavLink
|
||||||
key={item.key}
|
key={item.key}
|
||||||
@@ -31,7 +30,7 @@ export default function Navbar() {
|
|||||||
))}
|
))}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div className={`nav-resident ${open ? 'open' : ''}`}>
|
<div className="nav-resident">
|
||||||
{GLOBAL_RESIDENT.map(item => (
|
{GLOBAL_RESIDENT.map(item => (
|
||||||
<Link
|
<Link
|
||||||
key={item.key}
|
key={item.key}
|
||||||
@@ -55,12 +54,34 @@ export default function Navbar() {
|
|||||||
<span />
|
<span />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/* 当前路径提示,便于验收无死链 */}
|
{open && (
|
||||||
<div className="nav-current-path" aria-hidden>
|
<div className="mobile-nav-panel" id="mobile-navigation">
|
||||||
<div className="container">
|
<nav className="mobile-nav-links" aria-label="移动端主导航">
|
||||||
<span>当前:{location.pathname}</span>
|
{PRIMARY_NAV.map(item => (
|
||||||
|
<NavLink
|
||||||
|
key={item.key}
|
||||||
|
to={item.path}
|
||||||
|
className={({ isActive }) => (isActive ? 'nav-link active' : 'nav-link')}
|
||||||
|
onClick={() => setOpen(false)}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</NavLink>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
<div className="mobile-nav-actions">
|
||||||
|
{GLOBAL_RESIDENT.map(item => (
|
||||||
|
<Link
|
||||||
|
key={item.key}
|
||||||
|
to={item.path}
|
||||||
|
className={item.key === 'contact-cta' ? 'btn btn-primary' : 'btn btn-ghost'}
|
||||||
|
onClick={() => setOpen(false)}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,13 +48,7 @@
|
|||||||
}
|
}
|
||||||
.hamburger span { width: 22px; height: 2px; background: var(--primary); border-radius: 2px; display: block; }
|
.hamburger span { width: 22px; height: 2px; background: var(--primary); border-radius: 2px; display: block; }
|
||||||
|
|
||||||
.nav-current-path {
|
.mobile-nav-panel { display: none; }
|
||||||
background: #f8fafc;
|
|
||||||
border-top: 1px solid #f1f5f9;
|
|
||||||
font-size: 11px;
|
|
||||||
color: #94a3b8;
|
|
||||||
padding: 4px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.site-footer {
|
.site-footer {
|
||||||
background: #0f172a;
|
background: #0f172a;
|
||||||
@@ -88,19 +82,26 @@
|
|||||||
.nav-menu, .nav-resident {
|
.nav-menu, .nav-resident {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.nav-menu.open, .nav-resident.open {
|
.mobile-nav-panel {
|
||||||
display: flex;
|
display: flex;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0; right: 0;
|
top: 64px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
max-height: calc(100vh - 64px);
|
||||||
|
overflow-y: auto;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-bottom: 1px solid #e2e8f0;
|
border-bottom: 1px solid #e2e8f0;
|
||||||
padding: 12px 16px;
|
box-shadow: 0 14px 28px rgba(15, 23, 42, 0.14);
|
||||||
|
padding: 12px 16px calc(20px + env(safe-area-inset-bottom));
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
|
gap: 12px;
|
||||||
}
|
}
|
||||||
.nav-menu.open { top: 64px; }
|
.mobile-nav-links { display: grid; gap: 4px; }
|
||||||
.nav-resident.open { top: 260px; }
|
.mobile-nav-links .nav-link { padding: 12px; }
|
||||||
.nav-link { padding: 12px; }
|
.mobile-nav-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 8px; border-top: 1px solid #e2e8f0; }
|
||||||
|
.mobile-nav-actions .btn { width: 100%; min-height: 44px; }
|
||||||
.hamburger { display: flex; }
|
.hamburger { display: flex; }
|
||||||
.footer-grid { grid-template-columns: 1fr; }
|
.footer-grid { grid-template-columns: 1fr; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user