|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { |
| 4 | + ReactElement, |
| 5 | + ReactNode, |
| 6 | + useCallback, |
| 7 | + useEffect, |
| 8 | + useState, |
| 9 | +} from "react" |
| 10 | +import NextLink from "next/link" |
| 11 | +import { clsx } from "clsx" |
| 12 | +import { usePathname } from "next/navigation" |
| 13 | + |
| 14 | +import { HamburgerIcon, CrossIcon } from "@/icons" |
| 15 | + |
| 16 | +import { Badge } from "../../_components/badge" |
| 17 | + |
| 18 | +export interface NavbarProps { |
| 19 | + links: { href: string; children: React.ReactNode; "aria-disabled"?: true }[] |
| 20 | + year: number |
| 21 | +} |
| 22 | + |
| 23 | +export function Navbar({ links, year }: NavbarProps): ReactElement { |
| 24 | + const pathname = usePathname() |
| 25 | + const [mobileDrawerOpen, setMobileDrawerOpen] = useState(false) |
| 26 | + |
| 27 | + const handleDrawerClick = useCallback(() => { |
| 28 | + setMobileDrawerOpen(prev => !prev) |
| 29 | + }, []) |
| 30 | + |
| 31 | + useEffect(() => { |
| 32 | + setMobileDrawerOpen(false) |
| 33 | + }, [pathname]) |
| 34 | + |
| 35 | + return ( |
| 36 | + <> |
| 37 | + <div |
| 38 | + /* pink background "prelude" */ className={clsx( |
| 39 | + "top-0 h-[70px] w-full scale-y-105 bg-pri-base dark:bg-pri-darker", |
| 40 | + mobileDrawerOpen ? "static" : "absolute", |
| 41 | + )} |
| 42 | + /> |
| 43 | + <header |
| 44 | + // todo: not white, but ALWAYS contrasting color, either white or black depending on background |
| 45 | + className={clsx( |
| 46 | + "top-0 z-10 w-full border-b border-white/70 bg-white/20 font-mono text-white antialiased", |
| 47 | + mobileDrawerOpen ? "fixed" : "sticky", |
| 48 | + )} |
| 49 | + > |
| 50 | + <div |
| 51 | + /* navbar backdrop */ className="absolute inset-0 -z-10 backdrop-blur-[6.4px]" |
| 52 | + /> |
| 53 | + {/* todo: better backdrop */} |
| 54 | + <div className="container flex h-[70px] items-center justify-between gap-5"> |
| 55 | + <div className="flex items-center gap-2 text-xl/none uppercase"> |
| 56 | + <NextLink href="/"> |
| 57 | + <GraphQLLogo className="h-6" /> |
| 58 | + </NextLink> |
| 59 | + <span>/ GraphQLConf {year}</span> |
| 60 | + </div> |
| 61 | + |
| 62 | + {mobileDrawerOpen && ( |
| 63 | + <div |
| 64 | + onClick={handleDrawerClick} |
| 65 | + className="fixed inset-0 top-[71px] z-10 bg-neu-0/40 backdrop-blur-[6.4px]" |
| 66 | + /> |
| 67 | + )} |
| 68 | + |
| 69 | + <nav |
| 70 | + className={clsx( |
| 71 | + "inset-0 z-20 flex gap-7 typography-menu max-lg:fixed max-lg:mt-[71px] max-lg:flex-col max-md:min-w-[50%] sm:max-lg:p-4 lg:items-end", |
| 72 | + mobileDrawerOpen |
| 73 | + ? "translate-x-0 text-neu-900" |
| 74 | + : "text-white max-lg:translate-x-full", |
| 75 | + )} |
| 76 | + > |
| 77 | + <div className="flex w-full flex-col lg:mt-0 lg:block"> |
| 78 | + {links.map( |
| 79 | + ({ "aria-disabled": isDisabled, children, ...link }) => ( |
| 80 | + <NextLink |
| 81 | + aria-disabled={isDisabled} |
| 82 | + key={link.href} |
| 83 | + {...link} |
| 84 | + // if external link, open in new tab |
| 85 | + {...(link.href.startsWith("https") && { |
| 86 | + target: "_blank", |
| 87 | + rel: "noopener noreferrer", |
| 88 | + })} |
| 89 | + className={clsx( |
| 90 | + "p-5 underline-offset-4 hover:underline aria-disabled:pointer-events-none max-lg:text-base", |
| 91 | + pathname === link.href && "underline", |
| 92 | + )} |
| 93 | + > |
| 94 | + {children} |
| 95 | + {isDisabled && ( |
| 96 | + <sup className="ml-2"> |
| 97 | + <Badge className="text-white">Soon</Badge> |
| 98 | + </sup> |
| 99 | + )} |
| 100 | + </NextLink> |
| 101 | + ), |
| 102 | + )} |
| 103 | + </div> |
| 104 | + </nav> |
| 105 | + |
| 106 | + <button |
| 107 | + className="z-40 ml-auto size-6 text-white lg:hidden" |
| 108 | + onClick={handleDrawerClick} |
| 109 | + > |
| 110 | + {mobileDrawerOpen ? <CrossIcon /> : <HamburgerIcon />} |
| 111 | + </button> |
| 112 | + </div> |
| 113 | + </header> |
| 114 | + </> |
| 115 | + ) |
| 116 | +} |
| 117 | + |
| 118 | +function GraphQLLogo(props: React.SVGProps<SVGSVGElement>) { |
| 119 | + return ( |
| 120 | + <svg viewBox="0 0 100 100" fill="currentColor" {...props}> |
| 121 | + <path |
| 122 | + fill-rule="evenodd" |
| 123 | + clip-rule="evenodd" |
| 124 | + d="M50 6.90308L87.323 28.4515V71.5484L50 93.0968L12.677 71.5484V28.4515L50 6.90308ZM16.8647 30.8693V62.5251L44.2795 15.0414L16.8647 30.8693ZM50 13.5086L18.3975 68.2457H81.6025L50 13.5086ZM77.4148 72.4334H22.5852L50 88.2613L77.4148 72.4334ZM83.1353 62.5251L55.7205 15.0414L83.1353 30.8693V62.5251Z" |
| 125 | + /> |
| 126 | + <circle cx="50" cy="9.3209" r="8.82" /> |
| 127 | + <circle cx="85.2292" cy="29.6605" r="8.82" /> |
| 128 | + <circle cx="85.2292" cy="70.3396" r="8.82" /> |
| 129 | + <circle cx="50" cy="90.6791" r="8.82" /> |
| 130 | + <circle cx="14.7659" cy="70.3396" r="8.82" /> |
| 131 | + <circle cx="14.7659" cy="29.6605" r="8.82" /> |
| 132 | + </svg> |
| 133 | + ) |
| 134 | +} |
0 commit comments