AI Resource Pro / website · airesourcepro.com / src / components / site-header.tsx
| 1 | "use client"; |
| 2 | |
| 3 | import { useState } from "react"; |
| 4 | import Link from "next/link"; |
| 5 | import { usePathname } from "next/navigation"; |
| 6 | import { Menu, X, Map as MapIcon } from "lucide-react"; |
| 7 | import { Logo } from "@/components/logo"; |
| 8 | import { ThemeToggle } from "@/components/theme/theme-toggle"; |
| 9 | import { UserMenu } from "@/components/user-menu"; |
| 10 | import { TRACKS } from "@/lib/tracks"; |
| 11 | import { useUser } from "@/lib/use-user"; |
| 12 | import { cn } from "@/lib/utils"; |
| 13 | |
| 14 | // "My roadmap" gets a quiet outlined pill so it's easy to find without shouting |
| 15 | function RoadmapPill({ active, onClick }: { active: boolean; onClick?: () => void }) { |
| 16 | return ( |
| 17 | <Link |
| 18 | href="/roadmap" |
| 19 | onClick={onClick} |
| 20 | className={cn( |
| 21 | "inline-flex min-h-[44px] w-fit flex-none items-center gap-2 whitespace-nowrap rounded-full border px-3.5 py-1.5 font-mono text-[12px] font-medium uppercase tracking-[0.07em] transition-colors", |
| 22 | active |
| 23 | ? "border-primary text-foreground" |
| 24 | : "border-primary/35 text-[var(--accent-text)] hover:border-primary hover:text-foreground" |
| 25 | )} |
| 26 | > |
| 27 | <MapIcon className="size-3.5" strokeWidth={2} aria-hidden="true" /> |
| 28 | My roadmap |
| 29 | </Link> |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | const NAV_LINKS = [ |
| 34 | { href: "/getting-started", label: "Start here" }, |
| 35 | { href: "/tutorials", label: "Tutorials" }, |
| 36 | { href: "/videos", label: "Videos" }, |
| 37 | ]; |
| 38 | |
| 39 | export function SiteHeader() { |
| 40 | const pathname = usePathname(); |
| 41 | const [open, setOpen] = useState(false); |
| 42 | const { user } = useUser(); |
| 43 | |
| 44 | const linkClass = (href: string) => |
| 45 | cn( |
| 46 | "whitespace-nowrap font-mono text-[12.5px] font-medium uppercase tracking-[0.07em] transition-colors hover:text-foreground", |
| 47 | pathname === href || pathname.startsWith(`${href}/`) ? "text-foreground" : "text-[var(--ash)]" |
| 48 | ); |
| 49 | |
| 50 | return ( |
| 51 | <header className="fixed inset-x-0 top-0 z-30 bg-gradient-to-b from-background via-background/85 to-transparent"> |
| 52 | <div className="mx-auto flex max-w-[1416px] items-center gap-2 px-4 py-4 md:gap-3 md:px-8 md:py-[22px] lg:gap-7 xl:gap-9 xl:px-12"> |
| 53 | <Logo className="min-h-[44px] flex-none whitespace-nowrap max-md:gap-2 max-md:text-[17px] max-md:[&>svg]:h-[26px] max-md:[&>svg]:w-[26px]" /> |
| 54 | <nav aria-label="Main" className="ml-auto hidden items-center gap-6 lg:flex xl:gap-[30px]"> |
| 55 | {NAV_LINKS.map((l) => ( |
| 56 | <Link key={l.href} href={l.href} className={linkClass(l.href)}> |
| 57 | {l.label} |
| 58 | </Link> |
| 59 | ))} |
| 60 | <RoadmapPill active={pathname.startsWith("/roadmap")} /> |
| 61 | </nav> |
| 62 | <div className="ml-auto flex flex-none items-center gap-2 md:gap-4 lg:ml-0 xl:gap-6"> |
| 63 | {pathname !== "/" && <ThemeToggle className="max-sm:hidden" />} |
| 64 | <UserMenu /> |
| 65 | <button |
| 66 | className="grid size-[44px] shrink-0 place-items-center rounded-md text-[var(--ash)] hover:text-foreground lg:hidden" |
| 67 | onClick={() => setOpen(!open)} |
| 68 | aria-label={open ? "Close menu" : "Open menu"} |
| 69 | aria-expanded={open} |
| 70 | aria-controls="airp-mobile-nav" |
| 71 | > |
| 72 | {open ? <X className="h-5 w-5" /> : <Menu className="h-5 w-5" />} |
| 73 | </button> |
| 74 | </div> |
| 75 | </div> |
| 76 | {open && ( |
| 77 | <nav id="airp-mobile-nav" aria-label="Mobile" className="max-h-[calc(100dvh-76px)] overflow-y-auto border-t border-border bg-background px-4 pb-6 pt-4 lg:hidden"> |
| 78 | <div className="flex flex-col gap-1"> |
| 79 | <RoadmapPill active={pathname.startsWith("/roadmap")} onClick={() => setOpen(false)} /> |
| 80 | {/* The header bar drops the theme toggle on phones, and the sign-in pill on the narrowest ones */} |
| 81 | {!user && ( |
| 82 | <Link href="/login" className={cn(linkClass("/login"), "flex min-h-[44px] items-center min-[420px]:hidden")} onClick={() => setOpen(false)}> |
| 83 | Sign in |
| 84 | </Link> |
| 85 | )} |
| 86 | {[...NAV_LINKS, ...TRACKS.map((t) => ({ href: `/${t.slug}`, label: t.name }))].map((l) => ( |
| 87 | <Link key={l.href} href={l.href} className={cn(linkClass(l.href), "flex min-h-[44px] items-center")} onClick={() => setOpen(false)}> |
| 88 | {l.label} |
| 89 | </Link> |
| 90 | ))} |
| 91 | {pathname !== "/" && ( |
| 92 | <div className="flex items-center gap-3 sm:hidden"> |
| 93 | <ThemeToggle /> |
| 94 | <span className="font-mono text-[12.5px] uppercase tracking-[0.07em] text-[var(--ash)]">Theme</span> |
| 95 | </div> |
| 96 | )} |
| 97 | </div> |
| 98 | </nav> |
| 99 | )} |
| 100 | </header> |
| 101 | ); |
| 102 | } |