Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions web/e2e/mobile-header.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// The recovered mobile menu keeps rich section rows and native keyboard/dismissal behavior.
import { expect, test } from "@playwright/test";

for (const width of [320, 390, 768, 900]) {
test(`mobile sections at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 740 });
await page.goto("/dev/ui");
const trigger = page.getByRole("button", { name: "Sections", exact: true });
const menu = page.getByRole("menu");
await trigger.click();
await expect(menu).toBeVisible();
await expect(
menu.getByText("Every map, with its tier and world record"),
).toBeVisible();
await expect(menu.getByRole("menuitem")).toHaveCount(11);
await expect(
menu.getByRole("menuitem", { name: "Discord", exact: true }),
).toHaveAttribute("href", "https://discord.gg/RYP5G4tuwX");
const headerBox = (await page.getByRole("banner").boundingBox())!;
expect((await menu.boundingBox())!.y).toBe(headerBox.y + headerBox.height);
expect(
await menu.evaluate(
(element) => element.scrollWidth <= element.clientWidth,
),
).toBe(true);
await page.keyboard.press("End");
await expect(
menu.getByRole("menuitem", { name: "Instagram", exact: true }),
).toBeFocused();
await page.keyboard.press("Escape");
await expect(menu).toBeHidden();
await expect(trigger).toBeFocused();
await trigger.click();
await menu.getByRole("menuitem", { name: "Ruleset", exact: true }).click();
await expect(page).toHaveURL(/\/ruleset$/);
await expect(menu).toBeHidden();
await trigger.click();
await page.mouse.click(width - 5, 730);
await expect(menu).toBeHidden();
});
}

test("desktop keeps the current header", async ({ page }) => {
await page.goto("/dev/ui");
await expect(
page.getByRole("button", { name: "Sections", exact: true }),
).toBeHidden();
await expect(
page
.getByRole("navigation", { name: "Main", exact: true })
.getByRole("link", { name: "Records", exact: true }),
).toBeVisible();
});
144 changes: 144 additions & 0 deletions web/src/features/site/MobileSiteNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
"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 { BrandIcon } from "@/ui/BrandIcon";
import { classNames } from "@/ui/classNames";
import { Menu } from "@/ui/Menu";
import { communityLinks, isCurrent, sections } from "./navigation";

const icons: Record<(typeof sections)[number]["href"], LucideIcon> = {
"/leaderboards": Trophy,
"/maps": MapIcon,
"/players": Users,
"/activity": Activity,
"/servers": Server,
};

import styles from "./SiteHeader.module.css";

// Recovered from the navigation before the desktop header redesign.
export function MobileSiteNav({ pathname }: { pathname: string | null }) {
return (
<div className={styles.mobileMenu}>
<Menu
label="Sections"
sheet
trigger={
<>
<MenuIcon
aria-hidden
className="size-5 group-aria-expanded:hidden"
/>
<X
aria-hidden
className="hidden size-5 group-aria-expanded:block"
/>
</>
}
triggerClassName="group flex size-10 items-center justify-center rounded-md text-text-muted hover:bg-surface-raised hover:text-text aria-expanded:bg-surface-raised aria-expanded:text-text"
>
<ul role="none" className="flex flex-col p-2">
{sections.map(({ href, label, summary }, index) => {
const current = isCurrent(href, pathname);
const Icon = icons[href];
return (
<li
key={href}
role="none"
className="motion-enter"
style={
{
"--motion-delay": `${index * 25}ms`,
} as CSSProperties
}
>
{/* The current section's mark is the desktop underline turned on its side. */}
<Link
href={href}
role="menuitem"
tabIndex={-1}
aria-current={current ? "page" : undefined}
// Hover tints the row with the text color, as the other menus do, lighter than the icon's tile,
// and lifts the tile a shade: a row in the tile's own color swallowed the tile.
className={classNames(
"group focus-visible:bg-text/6 relative flex items-center gap-3 rounded-md px-3 py-2.5 transition-colors duration-(--duration-fast) outline-none",
current
? "bg-accent-soft before:bg-accent before:absolute before:inset-y-3 before:left-0 before:w-0.5 before:rounded-full"
: "hover:bg-text/6",
)}
>
<span
className={classNames(
"flex size-10 shrink-0 items-center justify-center rounded-md transition-colors duration-(--duration-fast)",
current
? "bg-surface-raised text-accent"
: "bg-surface-raised text-text-muted group-hover:bg-surface-overlay group-hover:text-text group-focus-visible:bg-surface-overlay group-focus-visible:text-text",
)}
>
<Icon aria-hidden className="size-5" />
</span>
<span className="flex min-w-0 flex-col">
<span
className={classNames(
"font-bold",
current ? "text-accent" : "text-text",
)}
>
{label}
</span>
<span className="text-text-muted truncate text-sm">
{summary}
</span>
</span>
</Link>
</li>
);
})}
</ul>
<div
role="none"
className="border-border flex items-center justify-between gap-4 border-t px-5 py-3"
>
<Link
href="/ruleset"
role="menuitem"
tabIndex={-1}
className="text-accent inline-flex items-center gap-1.5 text-sm outline-none focus-visible:underline"
>
<ScrollText aria-hidden className="size-4" />
Ruleset
</Link>
<span role="none" className="flex items-center gap-1">
{communityLinks.map(({ label, brand, href }) => (
<a
key={label}
href={href}
role="menuitem"
tabIndex={-1}
rel="noreferrer"
target="_blank"
aria-label={label}
className="focus-visible:bg-surface-raised flex size-9 items-center justify-center rounded-full outline-none"
>
<BrandIcon brand={brand} round className="size-7" />
</a>
))}
</span>
</div>
</Menu>
</div>
);
}
61 changes: 5 additions & 56 deletions web/src/features/site/SiteHeader.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,52 +135,13 @@
.nav {
display: none;
}
.mobileMenu [role="menu"] {
top: var(--site-header-height);
}
.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;
order: -1;
margin-left: -8px;
}
}
@media (max-width: 600px) {
Expand Down Expand Up @@ -215,10 +176,6 @@
clip-path: inset(50%);
white-space: nowrap;
}
.mobileMenu summary {
gap: 4px;
font-size: 12px;
}
}
@media (max-width: 359px) {
.shell {
Expand All @@ -227,14 +184,6 @@
.wordmark {
font-size: 18px;
}
.mobileMenu summary {
font-size: 0;
gap: 0;
}
.mobileMenu summary svg {
width: 22px;
height: 22px;
}
}

@media (max-width: 1279px) {
Expand Down
12 changes: 3 additions & 9 deletions web/src/features/site/SiteHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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";
Expand Down Expand Up @@ -36,14 +35,9 @@ export function SiteHeader() {
</Suspense>
</div>
</div>
<details data-site-menu className={styles.mobileMenu}>
<summary aria-label="Open navigation">
Menu <Plus aria-hidden />
</summary>
<Suspense fallback={<SiteNavLinks pathname={null} mobile />}>
<SiteNav mobile />
</Suspense>
</details>
<Suspense fallback={null}>
<SiteNav mobile />
</Suspense>
</div>
</HeaderShell>
);
Expand Down
8 changes: 3 additions & 5 deletions web/src/features/site/SiteNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { usePathname } from "next/navigation";
import { Link } from "@/ui/Link";
import { isCurrent } from "./navigation";
import { MobileSiteNav } from "./MobileSiteNav";
import styles from "./SiteHeader.module.css";

const navigation = [
Expand All @@ -23,11 +24,9 @@ export function SiteNavLinks({
pathname: string | null;
mobile?: boolean;
}) {
if (mobile) return <MobileSiteNav pathname={pathname} />;
return (
<nav
aria-label={mobile ? "Mobile" : "Main"}
className={mobile ? styles.mobileLinks : styles.nav}
>
<nav aria-label="Main" className={styles.nav}>
{navigation.map(({ href, label }) => (
<Link
key={href}
Expand All @@ -39,7 +38,6 @@ export function SiteNavLinks({
{label}
</Link>
))}
{mobile && <Link href="/ruleset">Ruleset</Link>}
</nav>
);
}