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
146 changes: 146 additions & 0 deletions dashboard/DESIGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Dashboard design system

One type ramp, one spacing scale, a handful of radii and semantic colors, so
every page reads as the same product. The values live in
[`src/app/tokens.css`](src/app/tokens.css) (CSS variables plus Tailwind's
`@theme`); code that cannot take a class (charts, QR codes, Mermaid, the
highlighter) reads the same values from [`src/lib/tokens.ts`](src/lib/tokens.ts).
`npm run lint` holds the rest of the code to them.

## Type

The root is the browser's 16px, so `1rem` is 16px. Seven sizes, each with a
fixed line height on the 4px grid:

| Class | Size / line height | Use |
|---|---|---|
| `text-xs` | 13 / 18 | captions, metadata, badges, table headers, timestamps |
| `text-sm` | 15 / 22 | body, controls, list rows, section titles (16 / 24 on a phone) |
| `text-base` | 16 / 24 | lead text; fields on a phone |
| `text-lg` | 18 / 26 | the title of a card that is the page's subject |
| `text-xl` | 20 / 28 | a dialog's or an empty state's title |
| `text-2xl` | 24 / 32 | the page title (`<PageHeader>` draws it) |
| `text-3xl` | 32 / 40 | a headline number on a stat tile |

Three weights: `font-normal` (400) for reading, `font-medium` (500) for
labels, buttons and names, `font-semibold` (600) for titles. Nothing bolder.

Semantic styles, size and weight only (add the color separately):

| Class | What it is |
|---|---|
| `text-page-title` | 24 / 32 semibold, tracking tight |
| `text-section-title` | 15 / 22 semibold (`<SectionHeading>`) |
| `text-body` | 15 / 22 normal |
| `text-caption` | 13 / 18 normal; pair with `text-fg-muted` |
| `text-data` | 13 / 18 mono, tabular numbers: ids, shas, durations in tables |
| `text-numeric` | tabular, lining figures for counts that line up |
| `text-display` | 32 / 40 semibold, tabular: a headline number |
| `text-code-inline` | 13px: inline code inside running text, keeping the line's height |

"Secondary" text is body size in `text-fg-muted`.

## Spacing

Tailwind's steps on a 4px grid. Padding, margin and gap use only:
`0, px, 0.5, 1, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24`
(0 to 96px). A value built from a token or the safe area
(`pb-[calc(var(--bottom-bar)+1rem)]`) is fine; `mt-[7px]` and `p-3.5` are not.

The page rhythm, the same on every page:

- the shell's gutter: 16px on a phone, 32px from `md:` (`<main>`);
- `<PageHeader>`, then **24px**, then the content (globals.css holds the
first block under the header to it, whatever margin it asks for);
- **40px** between titled sections (`<Section>`, `mt-10`);
- **12px** from a section's heading to its body;
- cards pad **16px** (`cardClass`, `p-4`); a list row pads `px-4 py-3`;
- **8px** between related controls (`gap-2`), **12px** between groups (`gap-3`).

## Lists, rails and groups

The places a page most often drifts:

- **A row's title** is `text-sm font-medium text-fg` (15px), its metadata
`text-xs text-fg-muted` (13px). A row title is never `text-base` or larger.
- **A group header** in a list ("Waiting on you 3") is `<SectionHeading>`:
`text-section-title` in sentence case with its count in `text-fg-muted`.
No uppercase overlines, no `tracking-wide` headers.
- **A number in a side rail or a summary row** is `text-lg font-semibold
text-numeric` (18px). `text-display` (32px) is only for the one headline
number of a stat tile.
- **Buttons in a row or a card** are `buttonClass(variant, "sm")` (32px);
the page's own actions beside its title are `"md"` (36px). One size per row.

## Radii

| Class | Size | Use |
|---|---|---|
| `rounded-sm` | 4px | badges, chips, keys, inline code |
| `rounded-md` | 6px | buttons, fields, menu items |
| `rounded-lg` | 8px | cards, panels, list boxes, menus, popovers, toasts |
| `rounded-xl` | 12px | dialogs and sheets |
| `rounded-full` | | pills, dots, avatars |

## Colors

Semantic names only; the palette (`zinc-400`, `amber-300`) is counted by the
lint and may only go down. Values are in `:root` so a light theme later
redefines `--ch-*` and nothing else changes.

| Role | Classes |
|---|---|
| Surfaces | `bg-canvas` (page), `bg-surface` (card), `bg-raised` (menu, dialog, sheet), `bg-inset` (a well inside a card), `bg-control` / `bg-control-hover` (secondary button, chip), `bg-hover` (row and ghost hover), `bg-inverse` / `bg-inverse-hover` (primary button), `bg-scrim` (behind a dialog) |
| Lines | `border-line` (cards, dividers), `border-line-strong` (fields), `border-line-emphasis` (hover, selected) |
| Text | `text-fg-strong` (titles), `text-fg` (body), `text-fg-secondary`, `text-fg-muted` (secondary, captions), `text-fg-subtle` (15px and up only), `text-fg-disabled` (disabled only), `text-fg-inverse` (on `bg-inverse`) |
| Status | `good`, `warn`, `bad`, `info`, plus `severe` (high severity) and `done` (merged, pull requests): `text-warn`, `text-warn-strong`, `bg-warn-solid` (dots, bars), `bg-warn-soft`, `border-warn-line` |
| Accent | CoderHelm blue: `text-accent`, `bg-accent-solid`, `bg-accent-soft`, `border-accent-line` |
| Charts | `SERIES` / `CHART` from `src/lib/tokens.ts`; `bg-chart-1`, `bg-chart-2` for legends |

A badge is `rounded-sm border border-<tone>-line bg-<tone>-soft px-1.5 text-xs text-<tone>`.

## Elevation

Only what floats casts a shadow: `shadow-popover` (menus, popovers,
toasts) and `shadow-dialog` (dialogs, sheets). Cards on the page have a
border and no shadow.

## Components

Use the shared pieces before writing classes: `<Page>`, `<PageHeader>`,
`<Section>`, `<SectionHeading>`, `cardClass` (components/page.tsx);
`buttonClass(variant, size)` and `inputClass` (components/ui.ts);
`<StatusPill>`, `<Tabs>`, `<Select>`, `<EmptyState>`, `<Callout>`,
`<StatTile>`, `<DataTable>`, `<List>`.

## The lint

`node scripts/ui-lint.mjs` (part of `npm run lint`) fails on:

- `type-ramp`: `text-[13px]`, `text-[0.8rem]`, `text-4xl` and up,
`font-bold`, `font-light`, `leading-[1.1]`, an `uppercase` label, a numeric
`fontSize` in code;
- `spacing-scale`: an arbitrary or off-scale padding, margin or gap;
- `raw-hex`: a hex color outside the two token files;
- `token-drift`: `src/lib/tokens.ts` disagreeing with `tokens.css`;
- `raw-color`: more palette color classes than the baseline.

The escape hatch is rare and says why, on the line or the line above:
`// ui-lint-allow raw-hex: <reason>` (in JSX,
`{/* ui-lint-allow spacing-scale: <reason> */}`), or for a whole file near
its top: `// ui-lint-allow-file raw-hex: other companies' logos keep their colors`.

## Moving a page onto the tokens

1. Replace palette colors with their roles: `text-zinc-400` is
`text-fg-muted`, `border-zinc-800` is `border-line`, `bg-zinc-900/50` is
`bg-surface`, `text-amber-300` is `text-warn`, `bg-red-500/10` is
`bg-bad-soft`, `border-emerald-500/30` is `border-good-line`.
2. Put every size on the ramp and every weight in the three; drop
`text-[..]`, `font-bold`, `tracking-wider`.
3. Put spacing on the scale; let `<PageHeader>`, `<Section>` and `cardClass`
set the rhythm instead of per-page margins.
4. Radii: buttons and fields `rounded-md`, cards `rounded-lg`, dialogs `rounded-xl`.
5. Pages under `src/app/` are listed in `TOKENS_LATER` in
`scripts/ui-lint.mjs` until they move; take a page off the list in the same
change that moves it, and run `npm run lint`.
4 changes: 2 additions & 2 deletions dashboard/e2e/data-sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,10 @@ test("small screens: the menu opens, navigates and closes with Escape", async ({
await expect(page.getByRole("dialog", { name: "Menu" })).toHaveCount(0);
await expect(page.getByRole("link", { name: /Data sources/ })).toBeVisible();

// Backdrop click closes too.
// The sheet fills the phone's screen, so its Close button closes it too.
await page.getByRole("button", { name: "Menu" }).click();
await expect(page.getByRole("dialog", { name: "Menu" })).toBeVisible();
await page.mouse.click(370, 400);
await page.getByTestId("menu-close").click();
await expect(page.getByRole("dialog", { name: "Menu" })).toHaveCount(0);
});

Expand Down
106 changes: 106 additions & 0 deletions dashboard/e2e/design-tokens.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { expect, test, type Page } from "@playwright/test";
import { mockWideApi } from "./wide-data";
import { SAMPLE_QUERY } from "./wide-data/addresses";

// The design system as the browser draws it (DESIGN.md). The shell and three
// key pages are opened on a wide screen and a phone, and every piece of text
// on them must sit on the type ramp in one of three weights, the page title
// must be the one title style, and the shell's paddings and corners must come
// from the spacing scale and the radii. The lint holds the source to the
// tokens; this holds what actually renders, including what a component
// computes or inherits.

/** px sizes on the ramp: text-xs to text-3xl (tokens.css). */
const RAMP = [13, 15, 16, 18, 20, 24, 32];
const WEIGHTS = ["400", "500", "600"];
/** 0 to 96px on the 4px grid, with the 1px and 2px and 6px and 10px half steps. */
const SPACING = [0, 1, 2, 4, 6, 8, 10, 12, 16, 20, 24, 32, 40, 48, 64, 80, 96];
/** rounded-sm, md, lg, xl; and full. */
const RADII = [0, 4, 6, 8, 12];

const PAGES = ["/inbox", "/settings/team", "/runs/detail"];

async function open(page: Page, path: string, width: number) {
await page.setViewportSize({ width, height: 900 });
await mockWideApi(page);
await page.goto(path + (SAMPLE_QUERY[path] || ""));
await expect(page.getByTestId("page-header").first()).toBeVisible();
}

/** Every visible element that holds text of its own, with what it draws. */
function textLooks(page: Page) {
return page.evaluate(() => {
const out: { size: number; weight: string; what: string }[] = [];
for (const el of Array.from(document.querySelectorAll("body *"))) {
// Code and diagrams set their own sizes (inline code is 0.9em of its line).
if (el.closest("code, pre, svg, kbd, [data-chart], .recharts-wrapper")) continue;
const own = Array.from(el.childNodes).some((n) => n.nodeType === 3 && n.textContent!.trim());
if (!own) continue;
const r = el.getBoundingClientRect();
if (!r.width || !r.height) continue;
const cs = getComputedStyle(el);
if (cs.visibility === "hidden" || cs.opacity === "0") continue;
out.push({ size: Math.round(parseFloat(cs.fontSize) * 100) / 100, weight: cs.fontWeight, what: `${el.tagName.toLowerCase()} "${el.textContent!.trim().slice(0, 40)}"` });
}
return out;
});
}

for (const width of [1440, 375]) {
for (const path of PAGES) {
test(`${path} at ${width}px: every text on the ramp, in three weights`, async ({ page }) => {
await open(page, path, width);
const looks = await textLooks(page);
expect(looks.length).toBeGreaterThan(10);
const offRamp = looks.filter((l) => !RAMP.includes(l.size)).map((l) => `${l.size}px ${l.what}`);
expect(offRamp, "text off the type ramp (DESIGN.md, Type)").toEqual([]);
const offWeight = looks.filter((l) => !WEIGHTS.includes(l.weight)).map((l) => `${l.weight} ${l.what}`);
expect(offWeight, "a weight other than 400, 500 or 600").toEqual([]);
});
}

test(`the page title is one style at ${width}px`, async ({ page }) => {
for (const path of PAGES) {
await open(page, path, width);
const title = page.getByTestId("page-header").locator("h1").first();
await expect(title).toHaveCSS("font-size", "24px");
await expect(title).toHaveCSS("line-height", "32px");
await expect(title).toHaveCSS("font-weight", "600");
// The first block under the header sits 24px below it, on every page.
const gap = await page.evaluate(() => {
const header = document.querySelector('[data-page] > [data-testid="page-header"]');
const next = header?.nextElementSibling;
return header && next ? Math.round(next.getBoundingClientRect().top - header.getBoundingClientRect().bottom) : null;
});
if (gap !== null) expect(gap, `${path}: header to content`).toBe(24);
}
});

test(`the shell's spacing and corners come from the tokens at ${width}px`, async ({ page }) => {
await open(page, "/inbox", width);
const bad = await page.evaluate(
({ spacing, radii }) => {
const out: string[] = [];
const shell = Array.from(document.querySelectorAll("aside, header, nav, [data-testid=page-header], [data-testid=phone-bar]"));
for (const root of shell) {
for (const el of [root, ...Array.from(root.querySelectorAll("*"))]) {
const r = el.getBoundingClientRect();
if (!r.width || !r.height || el.closest("svg")) continue;
const cs = getComputedStyle(el);
for (const p of ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft", "columnGap", "rowGap"] as const) {
const v = parseFloat(cs[p]);
if (!Number.isNaN(v) && !spacing.includes(Math.round(v * 100) / 100) && !cs[p].includes("env")) out.push(`${p} ${cs[p]} on ${el.tagName.toLowerCase()}.${(el.getAttribute("class") || "").split(" ").slice(0, 4).join(".")}`);
}
const radius = parseFloat(cs.borderTopLeftRadius);
if (radius > 0 && radius < 1000 && !radii.includes(radius) && radius * 2 < Math.min(r.width, r.height)) {
out.push(`radius ${cs.borderTopLeftRadius} on ${el.tagName.toLowerCase()}.${(el.getAttribute("class") || "").split(" ").slice(0, 4).join(".")}`);
}
}
}
return [...new Set(out)];
},
{ spacing: SPACING, radii: RADII },
);
expect(bad, "the shell uses only the spacing scale and the radii (DESIGN.md)").toEqual([]);
});
}
10 changes: 5 additions & 5 deletions dashboard/e2e/logs-stopped.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ for (const width of [1280, 390]) {
// Its severity is history: said, in the quiet tone a resolved finding uses.
const chip = row.locator('span[title="Critical while it was happening"]');
await expect(chip).toHaveText("Critical");
await expect(chip).not.toHaveClass(/text-red/);
await expect(chip).not.toHaveClass(/text-bad\b/);
await expect(row.locator('span[title="Critical"]')).toHaveCount(0);
// The live one beside it still reads as live, and comes first.
const live = page.getByTestId("finding-rec_live");
await expect(live.locator('span[title="Critical"]')).toHaveClass(/text-red/);
await expect(live.locator('span[title="Critical"]')).toHaveClass(/text-bad\b/);
await expect(live.getByRole("button", { name: /Create fix PR/ })).toBeVisible();
const ids = await page.locator('[data-testid^="finding-rec_"]').evaluateAll((els) => els.map((e) => e.getAttribute("data-testid")));
expect(ids).toEqual(["finding-rec_live", "finding-rec_stopped"]);
Expand Down Expand Up @@ -227,7 +227,7 @@ test("when the service itself went quiet the page says it can't tell, and the fi
"No matching line in the last 3 log checks, but the service itself wrote little or nothing then, so CoderHelm can't tell whether the error stopped.",
);
await expect(row).not.toContainText("Stopped:");
await expect(row.locator('span[title="Critical"]')).toHaveClass(/text-red/);
await expect(row.locator('span[title="Critical"]')).toHaveClass(/text-bad\b/);
await expect(row.getByRole("button", { name: /Create fix PR/ })).toBeVisible();
});

Expand Down Expand Up @@ -321,13 +321,13 @@ test("an incident whose findings all stopped reads Stopped, not as a live incide
await expect(row).toHaveAttribute("data-state", "stopped");
await expect(row).toContainText("Stopped: no matching line since");
await expect(row).toContainText("5 log checks in a row found none while the service kept logging.");
await expect(row.locator('span[title="Critical"]')).not.toHaveClass(/text-red/);
await expect(row.locator('span[title="Critical"]')).not.toHaveClass(/text-bad\b/);
// One of them is still live: the incident is live, with its own words.
await mockApi(page, { findings: [a, { ...b, status: "new", activity: null }] });
await page.reload();
const live = page.getByTestId(`incident-${incident.id}`);
await expect(live).toHaveAttribute("data-state", "live");
await expect(live).toContainText("The search domain was replaced; the service still read the old hostname.");
await expect(live).not.toContainText("Stopped:");
await expect(live.locator('span[title="Critical"]')).toHaveClass(/text-red/);
await expect(live.locator('span[title="Critical"]')).toHaveClass(/text-bad\b/);
});
6 changes: 3 additions & 3 deletions dashboard/scripts/ui-lint-allow.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"rule": "wide-button",
"file": "src/components/client-shell.tsx",
"text": "w-full rounded-lg bg-blue-600 px-4 py-2.5",
"text": "w-full rounded-lg bg-accent-emphasis px-4 py-2.5",
"why": "Sign-in, sign-up and reset forms sit in a narrow card; their submit buttons fill the card, not the screen."
},
{
Expand Down Expand Up @@ -32,13 +32,13 @@
{
"rule": "dashed-box",
"file": "src/app/foryou/parts.tsx",
"text": "border-l-2 border-dashed border-sky-400/40",
"text": "border-l-2 border-dashed border-info-line",
"why": "A suggestion's dashed left edge marks CoderHelm's proposal as not yet real (the approved For you design, from the suggestions research): it is one edge on a solid tinted block with real content, never an empty placeholder box."
},
{
"rule": "dashed-box",
"file": "src/app/foryou/page.tsx",
"text": "border-l-2 border-dashed border-sky-400/40",
"text": "border-l-2 border-dashed border-info-line",
"why": "A suggestion's dashed left edge marks CoderHelm's proposal as not yet real (the approved For you design, from the suggestions research): it is one edge on a solid tinted block with real content, never an empty placeholder box."
}
]
Loading
Loading