diff --git a/docs/design-system.md b/docs/design-system.md index 5b36de7..0105202 100644 --- a/docs/design-system.md +++ b/docs/design-system.md @@ -78,7 +78,7 @@ Pages swap in place: the old page fades out and the new one in (React's ``, so every shell stays static. Search lives on the Players page. +Header, page and footer sit on the sheet. The header is one sticky bar: wordmark, sections, search (`/`), Discord, Steam sign-in; footer: one line, community logos. Phones: wordmark, search, account, menu. Account and current section sit in ``, so every shell stays static. Search lives on the Players page. ## Screenshot tests `npm run test:ui` (part of `just check`) screenshots `/dev/ui` wide, on a phone, with the menu open and with the dialog open, and fails on any pixel change. After an intended visual change: diff --git a/web/e2e/navigation.e2e.ts b/web/e2e/navigation.e2e.ts index 362d495..0bd10a3 100644 --- a/web/e2e/navigation.e2e.ts +++ b/web/e2e/navigation.e2e.ts @@ -60,3 +60,28 @@ test("styles switch in place, and a run opens in a dialog without leaving the pa await page.evaluate(() => (window as { stillHere?: boolean }).stillHere), ).toBe(true); }); + +test("the shared header stays seamless at the top and becomes fixed with blur on every route", async ({ + page, +}) => { + let footer = ""; + for (const route of ["/", "/maps", "/players"]) { + await page.goto(route); + const header = page.getByRole("banner"); + await expect(header).toHaveCount(1); + await expect(header).toHaveAttribute("data-scrolled", "false"); + await expect(header).toHaveCSS("background-color", "rgba(0, 0, 0, 0)"); + const mark = header.getByRole("link", { name: "SourceJump", exact: true }); + await expect(mark).toHaveText("SOURCEJUMP"); + expect( + await mark.evaluate((e) => getComputedStyle(e).fontFamily), + ).toContain("Play"); + const text = await page.getByRole("contentinfo").innerText(); + if (footer) expect(text).toBe(footer); + footer = text; + await page.evaluate(() => scrollTo(0, 400)); + await expect(header).toHaveAttribute("data-scrolled", "true"); + await expect(header).toHaveCSS("backdrop-filter", "blur(18px)"); + expect((await header.boundingBox())!.y).toBe(0); + } +}); diff --git a/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png index a395a37..0bc7c3c 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png differ diff --git a/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png index f88f6c4..29e4a7c 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png differ diff --git a/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png index 5e728d7..9c07edd 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png differ diff --git a/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png index 17c8df7..4de424b 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png differ diff --git a/web/src/app/globals.css b/web/src/app/globals.css index f71680b..4125984 100644 --- a/web/src/app/globals.css +++ b/web/src/app/globals.css @@ -7,6 +7,7 @@ /* Taps show the site's own pressed and hover states, not the browser's grey flash, and act without the double-tap zoom delay. */ html { + --site-header-height: 80px; -webkit-tap-highlight-color: transparent; } a, @@ -49,3 +50,14 @@ background: var(--color-accent-soft); } } + +@media (max-width: 900px) { + html { + --site-header-height: 68px; + } +} +@media (max-width: 600px) { + html { + --site-header-height: 64px; + } +} diff --git a/web/src/features/site/HeaderSearch.tsx b/web/src/features/site/HeaderSearch.tsx index 647cf75..336ab4d 100644 --- a/web/src/features/site/HeaderSearch.tsx +++ b/web/src/features/site/HeaderSearch.tsx @@ -172,9 +172,14 @@ export function HeaderSearch() { setActive(-1); } - function go(href: string) { + function leave() { close(); + setExpanded(false); input.current?.blur(); + } + + function go(href: string) { + leave(); router.push(href); } @@ -338,7 +343,7 @@ export function HeaderSearch() { id={optionId(index)} href={targets[index]!} active={active === index} - onPick={close} + onPick={leave} picture={ (null); + useEffect(() => { + const element = header.current!; + const scroll = () => { + element.dataset.scrolled = String(scrollY > 16); + }; + function dismiss(event: PointerEvent) { + const menu = element.querySelector("details[open]"); + if (menu && event.target instanceof Node && !menu.contains(event.target)) + menu.open = false; + } + function escape(event: KeyboardEvent) { + if (event.key !== "Escape") return; + const menu = element.querySelector("details[open]"); + if (menu) { + menu.open = false; + menu.querySelector("summary")?.focus(); + } + } + scroll(); + window.addEventListener("scroll", scroll, { passive: true }); + document.addEventListener("pointerdown", dismiss); + document.addEventListener("keydown", escape); + return () => { + window.removeEventListener("scroll", scroll); + document.removeEventListener("pointerdown", dismiss); + document.removeEventListener("keydown", escape); + }; + }, []); + return ( +
{ + if (event.target instanceof Element && event.target.closest("a")) { + const menu = + header.current?.querySelector("details[open]"); + if (menu) menu.open = false; + } + }} + > + {children} +
+ ); +} diff --git a/web/src/features/site/SiteHeader.module.css b/web/src/features/site/SiteHeader.module.css new file mode 100644 index 0000000..c843bfa --- /dev/null +++ b/web/src/features/site/SiteHeader.module.css @@ -0,0 +1,257 @@ +.header { + position: sticky; + z-index: 30; + top: 0; + height: var(--site-header-height); + flex-shrink: 0; + color: #edf3fc; + transition: background-color 250ms; +} +.header[data-scrolled="true"] { + background: #080c12d9; + backdrop-filter: blur(18px); +} +.shell { + display: flex; + width: calc(100% - 112px); + max-width: 1440px; + height: 100%; + margin-inline: auto; + align-items: center; + gap: 40px; +} +.wordmark { + display: inline-flex; + flex-shrink: 0; + align-items: center; + font-size: 24px; + font-weight: 700; + line-height: 1; + letter-spacing: -0.025em; +} +.wordmark > span { + color: #77b9ff; +} +.nav { + display: flex; + align-items: center; + gap: 28px; +} +.nav a { + padding-block: 12px; + color: #bac8d9; + font-size: 14px; + transition: color 180ms; +} +.nav a:hover { + color: #fff; +} +.nav a[aria-current="page"] { + color: #94c7ff; +} +.right { + display: flex; + margin-left: auto; + align-items: center; + gap: 20px; +} +.search { + display: flex; + align-items: center; +} +.search [role="search"] { + background: transparent; + border-radius: 10px; +} +.search input { + padding-right: 36px; + border: 0; + background: #9bb8e20d; + border-radius: 10px; + box-shadow: inset 0 0 0 1px #ffffff06; + transition: + background-color 180ms, + box-shadow 180ms; +} +.search input:hover { + background: #9bb8e214; +} +.search input:focus-visible { + background: #162332b3; + box-shadow: inset 0 0 0 1px #8cc4ff80; +} +.discord { + color: #bac8d9; + font-size: 13px; +} +.discord:hover { + color: #fff; +} +.account { + display: flex; + align-items: center; + min-width: 36px; +} +.account > a { + min-height: 40px; + padding-inline: 14px; + border: 0; + border-radius: 10px; + background: #9bb8e20d; + font-size: 13px; +} +.account > a:hover { + background: #9bb8e21a; +} +.mobileMenu { + display: none; +} +@media (min-width: 1280px) { + .search [role="search"] > div:first-child { + width: 240px; + } +} +@media (max-width: 1350px) { + .discord { + display: none; + } + .shell { + gap: 28px; + } + .nav { + gap: 22px; + } +} +@media (max-width: 1150px) { + .shell { + width: calc(100% - 80px); + gap: 24px; + } + .nav { + gap: 20px; + } + .nav a { + font-size: 13px; + } +} +@media (max-width: 900px) { + .shell { + width: calc(100% - 48px); + gap: 20px; + } + .wordmark { + font-size: 22px; + } + .nav { + display: none; + } + .mobileMenu { + display: block; + } + .mobileMenu summary { + display: flex; + min-height: 44px; + align-items: center; + gap: 8px; + cursor: pointer; + list-style: none; + font-size: 13px; + } + .mobileMenu summary::-webkit-details-marker { + display: none; + } + .mobileMenu summary svg { + width: 20px; + height: 20px; + transition: transform 200ms; + } + .mobileMenu[open] summary svg { + transform: rotate(45deg); + } + .mobileLinks { + position: absolute; + top: 100%; + right: 16px; + left: 16px; + display: flex; + max-height: calc(100svh - var(--site-header-height) - 24px); + flex-direction: column; + overflow-y: auto; + padding: 16px 24px; + border-radius: 18px; + background: #101b2af5; + backdrop-filter: blur(24px); + } + .mobileLinks a { + display: flex; + min-height: 48px; + flex-shrink: 0; + align-items: center; + font-size: 16px; + } + .mobileLinks a[aria-current="page"] { + color: #94c7ff; + } +} +@media (max-width: 600px) { + .shell { + width: calc(100% - 36px); + gap: 14px; + } + .wordmark { + font-size: 20px; + } + .right { + gap: 12px; + } + .search [role="search"] { + background: transparent; + } + .search input { + font-size: 16px; + } + .account > a { + min-height: 36px; + width: 36px; + gap: 0; + justify-content: center; + padding-inline: 0; + } + .account > a > span { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; + } + .mobileMenu summary { + gap: 4px; + font-size: 12px; + } +} +@media (max-width: 359px) { + .shell { + gap: 12px; + } + .wordmark { + font-size: 18px; + } + .mobileMenu summary { + font-size: 0; + gap: 0; + } + .mobileMenu summary svg { + width: 22px; + height: 22px; + } +} + +@media (max-width: 1279px) { + .search [role="search"] { + height: var(--site-header-height); + background: #080c12f5; + border-radius: 0; + backdrop-filter: blur(18px); + } +} diff --git a/web/src/features/site/SiteHeader.tsx b/web/src/features/site/SiteHeader.tsx index 11effb1..95e7051 100644 --- a/web/src/features/site/SiteHeader.tsx +++ b/web/src/features/site/SiteHeader.tsx @@ -1,47 +1,60 @@ -// The top of every page: one bar across the window, staying in view while the page scrolls. The -// wordmark and the sections, then the search for players and maps and the account corner. On a phone: the menu, -// the wordmark, the search button and the account corner. import { Suspense } from "react"; import { Play } from "next/font/google"; +import { Plus } from "lucide-react"; import { Link } from "@/ui/Link"; import { AccountArea } from "./AccountArea"; import { HeaderSearch } from "./HeaderSearch"; +import { HeaderShell } from "./HeaderShell"; import { SiteNav, SiteNavLinks } from "./SiteNav"; +import { communityLinks } from "./navigation"; +import styles from "./SiteHeader.module.css"; const wordmark = Play({ weight: "700", subsets: ["latin"] }); +const discord = communityLinks.find((link) => link.brand === "discord")!.href; export function SiteHeader() { return ( -
-
+ +
- SourceJump + SOURCEJUMP }> -
- {/* Uses the address to close its list on a page change, so it streams in like the section links. */} - }> - - - - {/* Depends on the session cookie, so it streams in per request while the shell stays static. */} - - - +
+
+ }> + + +
+ + Discord + +
+ + + +
+
+ + Menu + + }> + + +
-
+ ); } diff --git a/web/src/features/site/SiteNav.tsx b/web/src/features/site/SiteNav.tsx index 7991ae1..24e8504 100644 --- a/web/src/features/site/SiteNav.tsx +++ b/web/src/features/site/SiteNav.tsx @@ -1,180 +1,53 @@ "use client"; -// Header navigation: section links on wide screens; on narrow ones, a menu that opens as a panel under the header, -// each section with what's in it, and the ruleset and community at its foot. Marks the current section. -import { - Activity, - type LucideIcon, - Map as MapIcon, - Menu as MenuIcon, - ScrollText, - Server, - Trophy, - Users, - X, -} from "lucide-react"; -import type { CSSProperties } from "react"; -import { Link } from "@/ui/Link"; + import { usePathname } from "next/navigation"; -import { BrandIcon } from "@/ui/BrandIcon"; -import { classNames } from "@/ui/classNames"; -import { Menu } from "@/ui/Menu"; -import { communityLinks, isCurrent, sections } from "./navigation"; +import { Link } from "@/ui/Link"; +import { communityLinks, isCurrent } from "./navigation"; +import styles from "./SiteHeader.module.css"; -const icons: Record<(typeof sections)[number]["href"], LucideIcon> = { - "/leaderboards": Trophy, - "/maps": MapIcon, - "/players": Users, - "/activity": Activity, - "/servers": Server, -}; +const navigation = [ + { href: "/activity?show=records", label: "Records" }, + { href: "/leaderboards", label: "Rankings" }, + { href: "/maps", label: "Maps" }, + { href: "/players", label: "Players" }, + { href: "/servers", label: "Servers" }, +]; +const discord = communityLinks.find((link) => link.brand === "discord")!.href; -/** - * On pages with a dynamic address, such as a profile, the path is only known per request. SiteHeader shows - * `SiteNavLinks` without a current section while it streams in, so every page's shell stays static. - */ -export function SiteNav() { - return ; +export function SiteNav({ mobile = false }: { mobile?: boolean }) { + return ; } - -export function SiteNavLinks({ pathname }: { pathname: string | null }) { +export function SiteNavLinks({ + pathname, + mobile = false, +}: { + pathname: string | null; + mobile?: boolean; +}) { return ( - <> - - {/* Ordered before the wordmark, so on a phone the menu button sits on its left. It turns into a close mark - while the menu is open. */} -
- - - - + -
- + {label} + + ))} + {mobile && ( + <> + Ruleset + + Discord + + + )} + ); }