| 1 | import Link from "next/link"; |
| 2 | import type { Locale } from "@/lib/i18n/config"; |
| 3 | import { getChrome } from "@/lib/i18n/dictionaries"; |
| 4 | import { FOUNDER_SWITCH_VALUES } from "@/lib/founder-switches"; |
| 5 | import { navLinks, signInLink, REPO_URL } from "@/lib/i18n/links"; |
| 6 | import { formatStars, readRepoStatsSnapshot } from "@/lib/github"; |
| 7 | import { PROJECT_COPY } from "@/lib/content/project"; |
| 8 | import { fill, pickText } from "@/lib/i18n/dictionaries"; |
| 9 | import { Icon } from "./icon"; |
| 10 | import { LocaleSwitcher } from "./locale-switcher"; |
| 11 | import { MobileMenu } from "./mobile-menu"; |
| 12 | import { NavLinks } from "./nav-links"; |
| 13 | import { ThemeToggle } from "./theme-toggle"; |
| 14 | import { ArrowLabel } from "./arrow-label"; |
| 15 | |
| 16 | /** |
| 17 | * Masthead + primary nav. Like the GPUI titlebar it carries few visible |
| 18 | * controls: the mark and the wordmark, the page links, quiet icon controls |
| 19 | * with accessible names and the one primary action, Install. |
| 20 | */ |
| 21 | export function Nav({ locale = "en" }: { locale?: Locale }) { |
| 22 | const chrome = getChrome(locale); |
| 23 | const links = navLinks(locale, chrome); |
| 24 | const signIn = FOUNDER_SWITCH_VALUES.accountSignInOffered ? signInLink(locale, chrome) : null; |
| 25 | const stats = readRepoStatsSnapshot(); |
| 26 | const stars = stats.stars === null ? null : formatStars(stats.stars); |
| 27 | const asOf = stats.fetchedAt |
| 28 | ? fill(chrome.numbersAsOf, { |
| 29 | date: new Intl.DateTimeFormat(chrome.dateLocale, { dateStyle: "medium", timeZone: "UTC" }).format(new Date(stats.fetchedAt)), |
| 30 | }) |
| 31 | : undefined; |
| 32 | const githubAria = stars === null |
| 33 | ? "GitHub" |
| 34 | : [`GitHub, ${stars} ${pickText(PROJECT_COPY.statStars, locale)}`, asOf].filter(Boolean).join(", "); |
| 35 | const homeHref = `/${locale}`; |
| 36 | |
| 37 | return ( |
| 38 | <header className="site-nav paper-nav"> |
| 39 | <div className="site-nav-inner paper-nav-inner"> |
| 40 | <Link href={homeHref} className="site-wordmark paper-wordmark" aria-label={chrome.navHomeAria}> |
| 41 | <div className="paper-wordmark-text"> |
| 42 | <span className="brand-mark" aria-hidden="true" /> |
| 43 | {/* The mark and the wordmark are one ink, drawn through CSS masks so |
| 44 | both appearances re-ink them; the link carries the name. */} |
| 45 | <span className="paper-wordmark-logo" aria-hidden="true" /> |
| 46 | </div> |
| 47 | </Link> |
| 48 | |
| 49 | <NavLinks links={links} primaryAria={chrome.navPrimaryAria} /> |
| 50 | |
| 51 | <div className="site-nav-actions"> |
| 52 | <ThemeToggle |
| 53 | key={locale} |
| 54 | lightLabel={chrome.themeLight} |
| 55 | darkLabel={chrome.themeDark} |
| 56 | ariaTemplate={chrome.themeAria} |
| 57 | /> |
| 58 | <LocaleSwitcher current={locale} /> |
| 59 | <Link |
| 60 | href={REPO_URL} |
| 61 | className="nav-icon-button site-github-link !w-auto gap-1.5 px-2.5" |
| 62 | aria-label={githubAria} |
| 63 | title={asOf ?? "GitHub"} |
| 64 | data-funnel="star_exit" |
| 65 | > |
| 66 | <Icon name="github" className="nav-icon" /> |
| 67 | {stars !== null && <span className="tabular text-sm">{stars}</span>} |
| 68 | </Link> |
| 69 | {signIn ? ( |
| 70 | <Link href={signIn.href} className="nav-link site-signin-link hidden lg:inline-flex px-2"> |
| 71 | {signIn.label} |
| 72 | </Link> |
| 73 | ) : null} |
| 74 | <Link |
| 75 | href={`/${locale}/install`} |
| 76 | className="paper-install-cta hidden lg:inline-flex" |
| 77 | > |
| 78 | <ArrowLabel text={chrome.installCta} /> |
| 79 | </Link> |
| 80 | <MobileMenu |
| 81 | installHref={`/${locale}/install`} |
| 82 | installLabel={chrome.installCta} |
| 83 | links={links} |
| 84 | github={{ href: REPO_URL, label: "GitHub", count: stars, aria: githubAria }} |
| 85 | signIn={signIn} |
| 86 | openLabel={chrome.menuOpen} |
| 87 | closeLabel={chrome.menuClose} |
| 88 | navAria={chrome.navPrimaryAria} |
| 89 | /> |
| 90 | </div> |
| 91 | </div> |
| 92 | </header> |
| 93 | ); |
| 94 | } |
| 95 |