refactor(web): page skeleton as Tailwind utilities
ci / web (pull_request) Successful in 30s
ci / rust (pull_request) Successful in 1m28s
ci / image (pull_request) Skipped

Decks, page bars, sections, heads, status slots and group notes move
out of components.css into Deck, PageBar, Section, Rows and friends.
The theme gains the geometry tokens and the container widths.

Refs #280

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-11-11 17:16:47 +00:00
co-authored by Claude Opus 5.5
parent 5528ac8aa8
commit db22e4a1d2
14 changed files with 370 additions and 330 deletions
+177 -17
View File
@@ -5,11 +5,14 @@
import {
type ComponentProps,
createContext,
type HTMLAttributes,
type KeyboardEvent,
type MouseEvent,
type ReactNode,
type Ref,
useCallback,
useContext,
useState,
} from "react";
import { Icon, type IconName, useArmed } from "./icons";
@@ -156,7 +159,7 @@ export function Disclosure({
return (
<button
type="button"
className="control control-quiet disclose"
className="control control-quiet disclose ml-auto"
aria-expanded={open}
onClick={onToggle}
>
@@ -212,16 +215,34 @@ export interface Status {
* A status slot. The slot is always laid out — an empty one keeps its line —
* so a message arriving or leaving never pushes the content below it.
*/
export function StatusSlot({ status, className }: { status: Status | null; className: string }) {
const SLOT = {
// a page bar's one line, ellipsised: a message never pushes the page down
head: "flex-1 min-w-0 m-0 overflow-hidden whitespace-nowrap text-ellipsis",
// a section's line: reserved, and wraps only when the sentence must
deck: "flex items-center flex-wrap gap-y-2 gap-x-3 min-h-chip-h mb-3",
} as const;
export function StatusSlot({
status,
variant,
}: {
status: Status | null;
variant: keyof typeof SLOT;
}) {
return (
<p
className={className}
className={cx(
"readout text-xs text-ink-muted data-[tone=fault]:text-signal-fault",
SLOT[variant],
)}
role="status"
data-empty={String(status === null)}
data-tone={status?.tone}
data-action={flag(status?.action !== undefined)}
>
{status?.busy && <span className="lamp" data-state="probing" aria-hidden="true" />}
{status?.busy && (
<span className="lamp inline-block mr-2" data-state="probing" aria-hidden="true" />
)}
{status?.text ?? ""}
{status?.action && <Control text={status.action.label} quiet onClick={status.action.run} />}
</p>
@@ -500,6 +521,107 @@ export function EmptyRow({
);
}
/* ---- page skeleton ------------------------------------------------------- */
/**
* A page: the one centred column, and a container, so a row answers to the
* page's width rather than the window's. The gutter belongs to the content;
* a child marked `data-bleed` (the detail hero) reaches both edges.
*/
export function Deck({
label,
detail = false,
hidden,
id,
ref,
onKeyDown,
children,
}: {
label: string;
/** A detail page opens on its hero, so the page drops its top padding. */
detail?: boolean;
hidden?: boolean;
id?: string;
ref?: Ref<HTMLElement>;
onKeyDown?: (event: KeyboardEvent<HTMLElement>) => void;
children: ReactNode;
}) {
return (
<main
className={cx(
"@container w-full max-w-deck mx-auto pb-12 flex-1 *:not-data-bleed:mx-gutter",
detail ? "pt-0" : "pt-4",
)}
aria-label={label}
hidden={hidden}
id={id}
ref={ref}
onKeyDown={onKeyDown}
>
{children}
</main>
);
}
/** A page's line: title, count, a one-line status slot, the page's controls. */
export function PageBar({
title,
count,
status,
children,
}: {
title: string;
/** Absent leaves the count's slot out entirely. */
count?: string;
status: Status | null;
children?: ReactNode;
}) {
return (
<header className="flex items-center gap-3 min-h-control-h mb-4">
<h2 className="page-title capitalize">{title}</h2>
{count !== undefined && <span className="deck-count readout flex-none">{count}</span>}
<StatusSlot status={status} variant="head" />
{children}
</header>
);
}
/** Whether a section sits inside another: its head is then a quieter group label. */
const Nested = createContext(false);
const InnerSection = createContext(false);
/** A section of a page; `spacing` replaces the default gap after it. */
export function Section({
spacing = "mb-8",
hidden,
labelledBy,
ref,
className,
children,
}: {
spacing?: string;
hidden?: boolean;
labelledBy?: string;
ref?: Ref<HTMLElement>;
/** A marker other rules still key on, such as `subs-lane`. */
className?: string;
children: ReactNode;
}) {
const outer = useContext(Nested);
return (
<section
className={cx(spacing, className)}
hidden={hidden}
aria-labelledby={labelledBy}
ref={ref}
>
<InnerSection.Provider value={outer}>
<Nested.Provider value={true}>{children}</Nested.Provider>
</InnerSection.Provider>
</section>
);
}
/** A section head: the engraved label, a count, then whatever acts on it. */
export function DeckHead({
label,
@@ -516,8 +638,15 @@ export function DeckHead({
count?: string | number | null;
children?: ReactNode;
}) {
// nested heads inside a section are group labels, one step quieter
const nested = useContext(InnerSection);
return (
<header className="deck-head">
<header
className={cx(
"flex items-center gap-3 pb-1 border-b border-b-line",
nested ? "min-h-chip-h pt-3" : "min-h-control-h",
)}
>
<Heading className={labelClass} id={labelId}>
{label}
</Heading>
@@ -527,21 +656,52 @@ export function DeckHead({
);
}
/** A list of rows, or of poster cards. */
export function Rows({
grid = false,
className,
hidden,
children,
}: {
grid?: boolean;
/** A marker other rules still key on, such as `seasons`. */
className?: string;
hidden?: boolean;
children?: ReactNode;
}) {
return (
<ul
className={cx("m-0 list-none", grid ? "grid-rows px-0 pb-0" : "p-0", className)}
aria-hidden={hidden}
>
{children}
</ul>
);
}
/** A group's one plain sentence, which opens to the long form on a tap. */
export function GroupNote({ short, more }: { short: string; more: string }) {
export function GroupNote({ short, more }: { short: string; more?: string }) {
const [open, setOpen] = useState(false);
return (
<div className="group-note" data-explain-group="">
<p>{short}</p>
<IconControl
glyph="info"
label="more about this list"
aria-expanded={open}
onClick={() => setOpen(!open)}
/>
<p className="group-note-more" hidden={!open}>
{more}
</p>
<div
className="flex flex-wrap items-center gap-y-1 gap-x-2 pt-2 text-sm text-ink-muted"
data-explain-group={more === undefined ? undefined : ""}
>
<p className="m-0">{short}</p>
{more !== undefined && (
<>
<IconControl
glyph="info"
label="more about this list"
aria-expanded={open}
onClick={() => setOpen(!open)}
className="size-chip-h min-w-chip-h min-h-chip-h border-transparent bg-none bg-transparent [box-shadow:none] text-ink-faint aria-expanded:border-accent aria-expanded:text-accent-bright"
/>
<p className="m-0 basis-full max-w-measure text-xs" hidden={!open}>
{more}
</p>
</>
)}
</div>
);
}