header.tsx74 lines, 2.1 KB
| 1 | "use client"; |
| 2 | |
| 3 | import Link from "next/link"; |
| 4 | import { usePathname } from "next/navigation"; |
| 5 | import { cn } from "@/lib/utils"; |
| 6 | import { FolderGit2, GitPullRequest, Icon, ScanSearch } from "lucide-react"; |
| 7 | import { UserMenu } from "./user-menu"; |
| 8 | import { ThemeToggle } from "./theme-toggle"; |
| 9 | |
| 10 | interface User { |
| 11 | id: string; |
| 12 | name: string; |
| 13 | email: string; |
| 14 | image?: string | null | undefined; |
| 15 | } |
| 16 | |
| 17 | interface HeaderProps { |
| 18 | user: User; |
| 19 | } |
| 20 | |
| 21 | const navItems = [ |
| 22 | { |
| 23 | href: "/repos", |
| 24 | label: "Repositories", |
| 25 | icon: FolderGit2, |
| 26 | }, |
| 27 | { |
| 28 | href: "/reviews", |
| 29 | label: "Reviews", |
| 30 | icon: GitPullRequest, |
| 31 | }, |
| 32 | ]; |
| 33 | |
| 34 | export function Header({ user }: HeaderProps) { |
| 35 | const pathname = usePathname(); |
| 36 | |
| 37 | return ( |
| 38 | <header className="sticky top-0 z-50 w-full border-b border-border/60 bg-background/80 backdrop-blur-xl supports-backdrop-filter:bg-background/60"> |
| 39 | <div className="container mx-auto flex h-14 items-center justify-between px-4"> |
| 40 | <div className="flex items-center gap-8"> |
| 41 | <nav className="hidden md:flex items-center gap-1"> |
| 42 | {navItems.map((item) => { |
| 43 | const isActive = |
| 44 | pathname === item.href || pathname.startsWith(`${item.href}/`); |
| 45 | const Icon = item.icon; |
| 46 | |
| 47 | return ( |
| 48 | <Link |
| 49 | key={item.href} |
| 50 | href={item.href} |
| 51 | className={cn( |
| 52 | "flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium transition-colors", |
| 53 | isActive |
| 54 | ? "text-foreground bg-muted" |
| 55 | : "text-muted-foreground hover:text-foreground hover:bg-muted/50", |
| 56 | )} |
| 57 | > |
| 58 | <Icon className="size-4" /> |
| 59 | {item.label} |
| 60 | </Link> |
| 61 | ); |
| 62 | })} |
| 63 | </nav> |
| 64 | </div> |
| 65 | |
| 66 | <div className="flex items-center gap-2"> |
| 67 | <ThemeToggle /> |
| 68 | <div className="h-5 w-px bg-border mx-1 hidden sm:block" /> |
| 69 | <UserMenu user={user} /> |
| 70 | </div> |
| 71 | </div> |
| 72 | </header> |
| 73 | ); |
| 74 | } |