Spaces:
Running
Running
Download apps/web/components/Nav.tsx from 2026worldcup/predictor: direct link, hf CLI and curl.
- Browser
- Download file 3.37 kB
-
https://huggingface.co/spaces/2026worldcup/predictor/resolve/main/apps/web/components/Nav.tsx
- Command line
-
hf download hf://spaces/2026worldcup/predictor/apps/web/components/Nav.tsx
-
curl -L -o Nav.tsx https://huggingface.co/spaces/2026worldcup/predictor/resolve/main/apps/web/components/Nav.tsx
3.37 kB
| "use client"; | |
| import Link from "next/link"; | |
| import { usePathname } from "next/navigation"; | |
| import { useState, useEffect, useRef } from "react"; | |
| const PRIMARY = [ | |
| { href: "/", label: "总览", icon: "🏠" }, | |
| { href: "/standings", label: "积分榜", icon: "📋" }, | |
| { href: "/watch", label: "观赛指南", icon: "📺" }, | |
| { href: "/predict", label: "比分预测", icon: "🎯" }, | |
| { href: "/value", label: "竞彩价值", icon: "💰" }, | |
| ]; | |
| const MORE = [ | |
| { href: "/simulator", label: "赛事模拟", icon: "🏆" }, | |
| { href: "/calibration", label: "模型校准", icon: "📊" }, | |
| ]; | |
| export default function Nav() { | |
| const path = usePathname(); | |
| const [open, setOpen] = useState(false); | |
| const ref = useRef<HTMLDivElement>(null); | |
| useEffect(() => setOpen(false), [path]); | |
| useEffect(() => { | |
| const h = (e: MouseEvent) => { | |
| if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); | |
| }; | |
| document.addEventListener("click", h); | |
| return () => document.removeEventListener("click", h); | |
| }, []); | |
| const cls = (active: boolean) => | |
| `whitespace-nowrap rounded-lg px-3 py-1.5 text-sm transition ${ | |
| active ? "bg-gold/15 text-gold" : "text-white/60 hover:bg-white/5 hover:text-white" | |
| }`; | |
| const isActive = (href: string) => (href === "/" ? path === "/" : path.startsWith(href)); | |
| const moreActive = MORE.some((l) => isActive(l.href)); | |
| return ( | |
| <header className="sticky top-0 z-50 border-b border-white/10 bg-ink/70 backdrop-blur-xl"> | |
| <div className="mx-auto flex max-w-7xl items-center gap-1 px-3 py-3 sm:px-4"> | |
| <Link href="/" className="mr-2 flex items-center gap-2 font-bold tracking-tight sm:mr-4"> | |
| <span className="text-2xl">⚽</span> | |
| <span className="hidden md:inline"> | |
| World Cup <span className="text-gold">2026</span> | |
| </span> | |
| </Link> | |
| {/* primary links: scroll horizontally on small screens */} | |
| <nav className="flex flex-1 items-center gap-0.5 overflow-x-auto"> | |
| {PRIMARY.map((l) => ( | |
| <Link key={l.href} href={l.href} className={cls(isActive(l.href))}> | |
| <span className="mr-1">{l.icon}</span> | |
| {l.label} | |
| </Link> | |
| ))} | |
| </nav> | |
| {/* 更多 dropdown — OUTSIDE the overflow nav so it isn't clipped */} | |
| <div className="relative shrink-0" ref={ref}> | |
| <button | |
| onClick={(e) => { | |
| e.stopPropagation(); | |
| setOpen((v) => !v); | |
| }} | |
| className={cls(moreActive) + " flex items-center"} | |
| > | |
| 更多 <span className="ml-0.5 text-[10px]">▾</span> | |
| </button> | |
| {open && ( | |
| <div className="absolute right-0 z-50 mt-1 w-40 overflow-hidden rounded-xl border border-white/10 bg-ink-card shadow-xl"> | |
| {MORE.map((l) => ( | |
| <Link | |
| key={l.href} | |
| href={l.href} | |
| className={`block px-4 py-2.5 text-sm ${ | |
| isActive(l.href) ? "bg-gold/15 text-gold" : "text-white/70 hover:bg-white/5" | |
| }`} | |
| > | |
| <span className="mr-2">{l.icon}</span> | |
| {l.label} | |
| </Link> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| </header> | |
| ); | |
| } | |