feat(web): mobile-first tokens and controls

44px controls, a separate 24px chip height, one row height, a gutter at
every width, min-width breakpoints, and the shared control and row
vocabulary in ui.ts. check-tokens now also rejects var() names that
nothing defines.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-10-24 17:28:22 +01:00
co-authored by Claude Opus 5.5
parent 460b82f039
commit ce6d38d044
4 changed files with 2848 additions and 2302 deletions
+40 -22
View File
@@ -40,14 +40,36 @@ const ICON_PATHS = {
],
chevronUp: ["M3 10.2l5-4.6 5 4.6"],
chevronDown: ["M3 5.8l5 4.6 5-4.6"],
chevronRight: ["M6 3l4.6 5L6 13"],
back: ["M13 8H3.4", "M7.4 3.8L3.2 8l4.2 4.2"],
play: ["M4.6 2.9v10.2c0 .4.4.6.7.4l7.8-5.1c.3-.2.3-.6 0-.8L5.3 2.5c-.3-.2-.7 0-.7.4Z"],
more: [
"M3.2 7.3a.7.7 0 1 1 0 1.4.7.7 0 0 1 0-1.4Z",
"M8 7.3a.7.7 0 1 1 0 1.4.7.7 0 0 1 0-1.4Z",
"M12.8 7.3a.7.7 0 1 1 0 1.4.7.7 0 0 1 0-1.4Z",
],
plus: ["M8 3v10", "M3 8h10"],
grid: [
"M2.5 2.5h4.4v4.4H2.5z",
"M9.1 2.5h4.4v4.4H9.1z",
"M2.5 9.1h4.4v4.4H2.5z",
"M9.1 9.1h4.4v4.4H9.1z",
],
list: ["M5.6 4h8", "M5.6 8h8", "M5.6 12h8", "M2.4 4h.01", "M2.4 8h.01", "M2.4 12h.01"],
library: ["M2.5 2.5h3v11h-3z", "M6.5 2.5h3v11h-3z", "M10.3 3.1l2.9-.8 2.3 10.6-2.9.7z"],
close: ["M3.6 3.6l8.8 8.8", "M12.4 3.6l-8.8 8.8"],
info: ["M8 1.8a6.2 6.2 0 1 1 0 12.4A6.2 6.2 0 0 1 8 1.8Z", "M8 7.2v4", "M8 4.8h.01"],
} as const;
export type IconName = keyof typeof ICON_PATHS;
/** Stroke glyph on the shared 16-grid; the control's aria-label carries the meaning. */
export function icon(name: keyof typeof ICON_PATHS): SVGSVGElement {
export function icon(name: IconName): SVGSVGElement {
const svg = document.createElementNS(SVG_NS, "svg");
svg.setAttribute("viewBox", "0 0 16 16");
svg.setAttribute("class", "icon");
svg.setAttribute("aria-hidden", "true");
svg.dataset.icon = name;
for (const d of ICON_PATHS[name]) {
const path = document.createElementNS(SVG_NS, "path");
path.setAttribute("d", d);
@@ -57,24 +79,27 @@ export function icon(name: keyof typeof ICON_PATHS): SVGSVGElement {
}
/**
* How much room the control has. A settings row can spell the confirmation
* out; a chip cannot, and says the same thing in one glyph.
* How much room the control has, and where the armed state explains itself.
*/
export interface ArmedDeleteOptions {
/**
* Chip scale: the control plate comes off and the armed state swaps the
* trash for a check instead of rendering the word "confirm", which a chip
* has no width for (§9.6 keeps a chip to one row). Everything else — the
* two clicks, the amber armed state, the 4-second disarm, the label — is
* the same control, so a chip and a settings row arm alike.
* Chip scale: the control plate comes off (§9.6 keeps a chip to one row).
* The two clicks, the amber armed state and the 4-second disarm are the
* same control either way.
*/
compact?: boolean;
/**
* The row's status slot. Arming writes "tap again to …" here and disarming
* clears it, so the button itself never changes size — the explanation
* lives beside it, not inside it.
*/
explain?: (text: string | null) => void;
}
/**
* The settings arm-then-confirm, icon-only: a trash glyph resting, a visible
* change of what the next click does while armed, so an accidental hit never
* destroys.
* The arm-then-confirm, icon-only: a trash glyph resting, an amber check
* while armed, in the same square either way, so an accidental hit never
* destroys and arming never moves its neighbours.
*/
export function armedDeleteIcon(
label: string,
@@ -83,12 +108,9 @@ export function armedDeleteIcon(
): HTMLButtonElement {
const button = document.createElement("button");
button.type = "button";
button.className = options.compact
? "control control-quiet control-icon control-micro"
: "control control-quiet control-icon";
button.className = options.compact ? "control-micro" : "control control-icon";
button.dataset.kind = "delete";
button.setAttribute("aria-label", label);
button.title = label;
button.replaceChildren(icon("trash"));
let armed = false;
let resetTimer: number | undefined;
@@ -97,8 +119,8 @@ export function armedDeleteIcon(
window.clearTimeout(resetTimer);
delete button.dataset.armed;
button.setAttribute("aria-label", label);
button.title = label;
button.replaceChildren(icon("trash"));
options.explain?.(null);
};
button.addEventListener("click", () => {
if (armed) {
@@ -109,13 +131,9 @@ export function armedDeleteIcon(
}
armed = true;
button.dataset.armed = "true";
if (options.compact) {
button.replaceChildren(icon("check"));
} else {
button.textContent = "confirm";
}
button.replaceChildren(icon("check"));
button.setAttribute("aria-label", `confirm — ${label}`);
button.title = `confirm — ${label}`;
options.explain?.(`tap again to ${label}`);
resetTimer = window.setTimeout(disarm, 4000);
});
button.addEventListener("blur", () => {