"use client"; import { useEffect, useState } from "react"; import { Link, usePathname } from "@/i18n/navigation"; import { useTranslations } from "next-intl"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { Menu, X } from "lucide-react"; import { cn } from "@/lib/utils"; import { LocaleSwitcher } from "./locale-switcher"; const NAV_ITEMS = [ { href: "/", key: "home" }, { href: "/about", key: "about" }, ] as const; /** * 站点头部导航。 * * DESIGN.md:粘性白色导航条,高度约 64px,底部分割线 1px hairline-soft。 * 桌面端横向展示链接与 CTA;移动端(<1024px)折叠为抽屉菜单。 */ export function SiteHeader() { const t = useTranslations("Nav"); const pathname = usePathname(); const [menuOpen, setMenuOpen] = useState(false); const shouldReduceMotion = useReducedMotion(); // 菜单打开时锁定页面滚动(与外部系统 document.body 同步) useEffect(() => { if (!menuOpen) { return; } const original = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.body.style.overflow = original; }; }, [menuOpen]); const isActive = (href: string) => href === "/" ? pathname === "/" : pathname.startsWith(href); return (
{/* 品牌标识 */} 个人博客 {/* 桌面端导航 */}
{/* GitHub 入口(桌面端) */} GitHub {/* 移动端菜单开关 */}
{/* 移动端抽屉 */} {menuOpen ? (
    {NAV_ITEMS.map((item) => (
  • setMenuOpen(false)} aria-current={isActive(item.href) ? "page" : undefined} className={cn( // 触控目标 ≥ 44px "flex min-h-11 items-center rounded-md px-sm text-body-md transition-colors duration-150", isActive(item.href) ? "font-medium text-ink" : "text-steel active:bg-surface", )} > {t(item.key)}
  • ))}
) : null}
); }