Public: anyone can read this; the crew can change it.

Component library: skeleton, toast and confirm dialog as ui.ts parts, each in the gallery #5897

Parked opened this
Closed without merging

mason/forge:mason/5880-component-library-skeleton-toast-and-con → main 6 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
19 files changed +952 −59
docs/design/areas/dialog.md +4 −3
@@ -1,10 +1,11 @@
11 # Dialog
22
33 A §5 `.dialog` is one component in three parts: a head that names it, a body that holds what it asks or shows, and a
4 foot of buttons aligned to the end. The shell's keyboard-shortcuts dialog (`overlays()` in `src/web/layout.ts`) and the
5 limb page's confirm form (`limbPreviewPage()` in `src/web/pages/limb.ts`) both draw it; the rules live in
4 foot of buttons aligned to the end. `dialogParts()` in `src/web/ui.ts` draws the three; the wrapper is the caller's —
5 the shell's keyboard-shortcuts `<dialog>` (`overlays()` in `src/web/layout.ts`) and the limb page's confirm
6 `<form class="dialog">` (`limbPreviewPage()` in `src/web/pages/limb.ts`). The rules live in
67 `src/web/style/components.ts`.
78
89 - `.dialog-head` — the dialog's first row: its `h2` title (which `aria-labelledby` names) takes the width, anything beside it sits at the end.
9 - `.dialog-body` — the dialog's content, padded to the head's inset; add `.stack` when it holds several fields.
10 - `.dialog-body` — the dialog's content, padded to the head's inset; `stack: true` adds `.stack` when it holds several fields.
1011 - `.dialog-foot` — the dialog's actions on one row, aligned to the end, the primary or danger button last.
docs/design/areas/skeleton.md added +10
@@ -0,0 +1,10 @@
1 # Skeleton
2
3 `skeleton()` in `src/web/ui.ts` (#5880): a placeholder for a part that fills in after the first paint. It is a real
4 `.card` holding real `.list` rows (or a real card head and body, `shape: "card"`), so the swap to the loaded part shifts
5 nothing; grey bars stand where the words will be, and the card says "Loading…" to a screen reader (`role="status"`,
6 `aria-busy`). A page the server renders whole needs none. Rules in `src/web/style/components.ts` under
7 `/* ---- skeleton … ---- */`.
8
9 - `.skeleton` — on the card: lays a row's title and meta out as two stacked bars.
10 - `.skeleton-bar` — one grey bar, a line of text tall; it pulses, and under `prefers-reduced-motion` the kill switch holds it still.
docs/design/areas/toast.md +3 −1
@@ -2,4 +2,6 @@
22
33 The flash a write leaves after its redirect, and the same one-line banner a page shows for a failure it found itself: one `.toast` per page, toned by `data-tone=success|danger|attn` (§5's toast / flash row), an icon, then the message.
44
5 - `.toast-body` — the message beside the toast's icon: it takes the rest of the row (`flex: 1; min-width: 0`) so a long message wraps instead of pushing the icon off. Written by `flashToast` in `src/web/layout.ts` (the cookie-driven flash), and by `src/web/pages/repo.ts` (a fetch error), `src/web/pages/browse.ts` (a failed mirror) and `src/web/pages/origins.ts` (origin connected or failed); styled in `src/web/style/components.ts` under `/* ---- toast / flash ---- */`.
5 Drawn by one part, `toast()` in `src/web/ui.ts`: the shell's cookie-driven flash (`flashToast` in `src/web/layout.ts`), `src/web/pages/repo.ts` (a fetch error), `src/web/pages/browse.ts` (a failed mirror, `role="alert"`) and `src/web/pages/origins.ts` (origin connected or failed) all call it; nothing writes `.toast` by hand. Styled in `src/web/style/components.ts` under `/* ---- toast / flash ---- */`.
6
7 - `.toast-body` — the message beside the toast's icon: it takes the rest of the row (`flex: 1; min-width: 0`) so a long message wraps instead of pushing the icon off.
docs/design/audit.md +2 −1
@@ -33,7 +33,7 @@ their own vocabulary instead of composing the named one.
3333
3434 ## Finding 2 — the pages, and what each is for
3535
36 There are 62 top-level pages, one entry each: every static `GET` route in `src/http/server.ts`
36 There are 63 top-level pages, one entry each: every static `GET` route in `src/http/server.ts`
3737 that returns a page (`test/design-audit.test.ts` holds this list to the router,
3838 both ways). Each entry reads `route` — module · what it is for · what
3939 duplicates it · what breaks `docs/DESIGN.md`. "Breaks" counts colour literals
@@ -55,6 +55,7 @@ Machine routes are not pages and have no entry: `/audit.csv`,
5555 - `/big` — `pages/board.ts` (`bigRedirect`) · a redirect kept for old addresses into the board's wall mode · it is `/board` · none (no page of its own).
5656 - `/boards` — `pages/boards-view.ts` · saved queries as panels · `/board` · none seen.
5757 - `/boards/data` — `pages/boards.ts` · the boards' query/data surface · `/board` · none seen.
58 - `/design/components` — `pages/design_components.ts` · the living gallery: every part of `ui.ts` in each state, theme and width (#5817) · none · none seen.
5859 - `/asks` — `studio/asks_page.ts` · what the crew is waiting on me for · `/` "needs me" list · colours 2.
5960 - `/asked` — `studio/asked_page.ts` · what I answered, as a record · `/asks` · none seen.
6061 - `/review` — `studio/review_page.ts` · every ask waiting on me, one row each, newest first · `/asks` (same asks, with buttons) · none seen.
docs/design/sections/5-components.md +3 −3
@@ -81,10 +81,10 @@ specification.
8181 | **stacked bar chart** `windowSvg()` (`fleet-graph.ts`) | `.plots`, `.plot` (`.plot-name`), `.plot-legend` | bars wear `fg-sN`, the `--series-N` token | server-drawn SVG with `width`/`height` set, so it holds its box before the stylesheet; gridlines `--border`, figures `--muted-fg` in mono, panel names `--faint`; `role="img"` with an `aria-label` totalling it, a `<title>` per bar, and a table of the same numbers beside it | a table of the same numbers |
8282 | **chart** `chartBox()` (`ui.ts`) | `.chart-box` wrapping `drawChart`'s svg `.chart` (`.big` for the headline figure) | `.is-table` for a table panel | one query or series drawn on the server: the svg carries its own `width`/`height` and the box holds its space, so nothing shifts; `role="img"` with an `aria-label` of its title. Reach for it wherever a page draws a `boards/chart.ts` chart — `/system`'s memory pair and every board panel — and size it from the page (`.bp-*`, `.plots`, `.bgrid`), never inside the frame | the same numbers as a table |
8383
84 Two things are deliberately **not** in the vocabulary: skeleton loaders (the
85 server renders whole pages — there is nothing to skeletonise) and a custom
84 One thing is deliberately **not** in the vocabulary: a custom
8685 switch control (a native checkbox with `accent-color` is themed, keyboard-correct
87 and honest about what it is).
86 and honest about what it is). The server renders whole pages, so a skeleton
87 (`docs/design/areas/skeleton.md`) is only for a part that fills in after them.
8888
8989 Three rules the browser enforces whether or not you meant them:
9090
src/core/reserved.ts +1
@@ -64,6 +64,7 @@ export const SYSTEM_NAMES: readonly string[] = [
6464 "big",
6565 "board",
6666 "boards",
67 "design",
6768 "contribute",
6869 "events",
6970 "explore",
src/http/server.ts +3
@@ -27,6 +27,7 @@ import { resiliencePage } from "../web/pages/resilience.ts";
2727 import { limitsPage, limitsSet, quotasSet, signupSet, inviteMint, inviteRevoke } from "../web/pages/admin-limits.ts";
2828 import { measureSubmit } from "./measure.ts";
2929 import { boardsPage } from "../web/pages/boards.ts";
30 import { designComponentsPage } from "../web/pages/design_components.ts";
3031 import { boardNew, boardPin, boardPost, pinPost } from "../web/pages/boards-edit.ts";
3132 import { boardLive, boardShow, boardsList } from "../web/pages/boards-view.ts";
3233 import {
@@ -871,6 +872,8 @@ export function buildRouter(): Router<Handler> {
871872 router.add("POST", "/settings/capacity", capacitySet);
872873 router.add("GET", "/boards", boardsList);
873874 router.add("GET", "/boards/data", boardsPage);
875 // The living gallery of the component library (#5817), for an admin who is a person.
876 router.add("GET", "/design/components", designComponentsPage);
874877 router.add("POST", "/boards/new", boardNew);
875878 router.add("POST", "/boards/pin", boardPin);
876879 for (const op of ["pin-panel", "unpin-panel", "move-pin"]) router.add("POST", `/boards/${op}`, pinPost);
src/web/client.ts +26
@@ -1375,6 +1375,32 @@ export const shellJs = /* js */ `
13751375 }, fallback);
13761376 });
13771377
1378 // ---- search pickers: typing narrows this page's rows; Enter asks the server ----
1379 doc.addEventListener('input', function (e) {
1380 var q = e.target;
1381 if (!q || !q.matches || !q.matches('[data-picker-q]')) return;
1382 var picker = q.closest('[data-picker]');
1383 if (!picker) return;
1384 var needle = q.value.trim().toLowerCase();
1385 var rows = picker.querySelectorAll('li[data-q]');
1386 var shown = 0;
1387 for (var i = 0; i < rows.length; i++) {
1388 var hit = needle === '' || rows[i].getAttribute('data-q').indexOf(needle) >= 0;
1389 rows[i].hidden = !hit;
1390 if (hit) shown++;
1391 }
1392 var count = picker.querySelector('[data-picker-count]');
1393 if (count) count.textContent = needle === '' ? count.getAttribute('data-picker-count') : String(shown);
1394 });
1395 doc.addEventListener('change', function (e) {
1396 var box = e.target;
1397 if (!box || box.type !== 'checkbox' || !box.closest) return;
1398 var picker = box.closest('[data-picker]');
1399 var out = picker ? picker.querySelector('[data-picker-picked]') : null;
1400 if (!out) return;
1401 out.textContent = String(picker.querySelectorAll('li input:checked, [data-picker-carried]').length);
1402 });
1403
13781404 // ---- code line ranges: shift-click extends #L3 to #L3-L9 ----
13791405 // Delegated, not bound to the table: the code browser swaps the file in
13801406 // place, and the new table must behave like the first one did.
src/web/layout.ts +12 −24
@@ -40,7 +40,7 @@ import { html, raw, when, type Html } from "./html.ts";
4040 import { noRoom } from "../spawn/door.ts";
4141 import { quotaFull } from "../spawn/quota.ts";
4242 import { icon, iconSprite, inlineIcons, themeGlyph } from "./icons.ts";
43 import { btn, copyField, kbd, menu, type MenuItem } from "./ui.ts";
43 import { btn, dialogParts, kbd, menu, toast, type MenuItem } from "./ui.ts";
4444 import { SITE_LINE } from "./site_line.ts";
4545
4646 /** One row of the command palette: title, href, category. */
@@ -232,6 +232,7 @@ function userMenu(
232232 : [
233233 { label: "Boards", href: "/boards", icon: "activity" as const },
234234 { label: "System memory", href: "/system", icon: "activity" as const },
235 { label: "Components", href: "/design/components", icon: "eye" as const },
235236 ]),
236237 ]
237238 : []),
@@ -329,6 +330,7 @@ function paletteIndex(ctx: Ctx, extra: PaletteItem[]): Html {
329330 ...(ctx.auth.user?.isAdmin
330331 ? [
331332 { t: "System", h: "/system", c: "Go to" },
333 { t: "Components", h: "/design/components", c: "Go to" },
332334 { t: "Forges you sent", h: "/forges", c: "Go to" },
333335 { t: "Family of forges", h: "/family", c: "Go to" },
334336 ]
@@ -384,34 +386,20 @@ function overlays(): Html {
384386 </div>
385387 </dialog>
386388 <dialog class="dialog" id="help-dialog" aria-labelledby="help-title">
387 <div class="dialog-head"><h2 id="help-title">Keyboard shortcuts</h2></div>
388 <div class="dialog-body" data-help-body></div>
389 <div class="dialog-foot">
390 <form method="dialog">
389 ${dialogParts({
390 titleId: "help-title",
391 title: "Keyboard shortcuts",
392 body: html``,
393 bodyAttrs: raw("data-help-body"),
394 foot: html`<form method="dialog">
391395 <button class="btn" type="submit">Close</button>
392 </form>
393 </div>
396 </form>`,
397 })}
394398 </dialog>`;
395399 }
396400
397401 function flashToast(flash: Flash): Html {
398 const tone = flash.tone ?? "success";
399 const glyph =
400 tone === "danger" ? "alert" : tone === "attn" ? "alert" : "check";
401 return html`<div class="toast" data-tone="${tone}" role="status">
402 ${icon(glyph)}
403 <div class="toast-body">
404 ${flash.message}${when(
405 flash.link,
406 (link) => html` · <a href="${link.href}">${link.label}</a>`,
407 )}
408 ${when(
409 flash.code,
410 (code) =>
411 copyField("flash-code", code, "Code", "Copy code"),
412 )}
413 </div>
414 </div>`;
402 return toast({ ...flash, codeId: "flash-code" });
415403 }
416404
417405 // ---- the chrome ----
src/web/pages/browse.ts +2 −4
@@ -74,6 +74,7 @@ import {
7474 tlComment,
7575 userTag,
7676 type IconName,
77 toast,
7778 } from "../ui.ts";
7879 import { browseCommit, browseCommits } from "./commits.ts";
7980 import { blankDraft, editorPage, runContribute } from "./edit.ts";
@@ -1060,10 +1061,7 @@ export function mirrorJobPage(ctx: Ctx): Response {
10601061
10611062 const foot =
10621063 job.stage === "failed"
1063 ? html`<div class="toast" data-tone="danger" role="alert">
1064 ${icon("alert")}
1065 <div class="toast-body">${job.error ?? "The mirror failed."}</div>
1066 </div>
1064 ? html`${toast({ tone: "danger", role: "alert", message: job.error ?? "The mirror failed." })}
10671065 <div class="bar mt">
10681066 <form
10691067 method="post"
src/web/pages/design_components.ts added +113
@@ -0,0 +1,113 @@
1 /**
2 * /design/components, for an admin who is a person (#5817): the living
3 * gallery — every part `ui.ts` draws, in every state it has
4 * (`web/gallery.ts`), the one place to judge the library. Two links pick
5 * what the gallery is seen in: `?theme=` any of the forge's themes, and
6 * `?w=390|1440` a phone's or a desktop's column. `?part=` narrows it to one
7 * part. Each is checked against what it may be, and anything else is the
8 * same as leaving it out.
9 *
10 * The width is a column, not a viewport: a part's media queries still read
11 * the window, so a phone's breakpoints are judged on a phone. It shows how a
12 * part wraps, truncates and overflows at that width, which is most of what
13 * drifts.
14 */
15 import { THEME_NAMES, isThemeName, type ThemeName } from "../../design/themes.ts";
16 import type { Ctx } from "../../http/context.ts";
17 import { notFoundPage } from "../chrome.ts";
18 import { GALLERY_SEARCH_FORM, SPECIMENS, type Specimen } from "../gallery.ts";
19 import { html, type Html } from "../html.ts";
20 import { page } from "../layout.ts";
21 import { card, seg } from "../ui.ts";
22
23 const WIDTHS = ["390", "1440"] as const;
24 type Width = (typeof WIDTHS)[number];
25
26 export interface GalleryQuery {
27 readonly theme: ThemeName | undefined;
28 readonly w: Width | undefined;
29 readonly part: string | undefined;
30 }
31
32 /** The query, each value kept only when it is one the gallery knows. */
33 export function readGalleryQuery(params: URLSearchParams): GalleryQuery {
34 const theme = params.get("theme") ?? "";
35 const w = params.get("w") ?? "";
36 const part = params.get("part") ?? "";
37 return {
38 theme: isThemeName(theme) ? theme : undefined,
39 w: (WIDTHS as readonly string[]).includes(w) ? (w as Width) : undefined,
40 part: SPECIMENS.some((s) => s.part === part) ? part : undefined,
41 };
42 }
43
44 /** This page's address with one value changed, the others kept. */
45 function hrefWith(q: GalleryQuery, change: Partial<Record<keyof GalleryQuery, string | undefined>>): string {
46 const next = { ...q, ...change };
47 const params = new URLSearchParams();
48 for (const key of ["theme", "w", "part"] as const) {
49 const value = next[key];
50 if (value !== undefined) params.set(key, value);
51 }
52 const query = params.toString();
53 return `/design/components${query === "" ? "" : `?${query}`}`;
54 }
55
56 function specimen(s: Specimen, q: GalleryQuery): Html {
57 return card(
58 html`<div class="stack">
59 ${s.states.map(
60 (st) => html`<div class="stack stack-tight" data-state="${st.state}">
61 <span class="muted small">${st.state}</span>
62 <div class="gallery-stage">${st.draw()}</div>
63 </div>`,
64 )}
65 </div>`,
66 {
67 id: `part-${s.part}`,
68 head: html`<div class="stack stack-tight">
69 <a class="mono" href="${hrefWith(q, { part: s.part })}"><strong>${s.part}</strong></a>
70 <span class="muted small">${s.note}</span>
71 </div>`,
72 },
73 );
74 }
75
76 // GET /design/components
77 export function designComponentsPage(ctx: Ctx): Response {
78 const user = ctx.auth.user;
79 if (user?.isAdmin !== true || user.kind === "agent") return notFoundPage(ctx);
80 const q = readGalleryQuery(ctx.url.searchParams);
81 const shown = q.part === undefined ? SPECIMENS : SPECIMENS.filter((s) => s.part === q.part);
82 const themes = seg([
83 { label: "Mine", href: hrefWith(q, { theme: undefined }), current: q.theme === undefined },
84 ...THEME_NAMES.map((name) => ({ label: name, href: hrefWith(q, { theme: name }), current: q.theme === name })),
85 ]);
86 const widths = seg([
87 { label: "Fluid", href: hrefWith(q, { w: undefined }), current: q.w === undefined },
88 ...WIDTHS.map((w) => ({ label: `${w} px`, href: hrefWith(q, { w }), current: q.w === w })),
89 ]);
90 const body = html`<div class="stack">
91 <h1>Components</h1>
92 <p class="muted">
93 Every part <span class="mono">src/web/ui.ts</span> draws, in each state it has.
94 ${shown.length === SPECIMENS.length
95 ? html`${SPECIMENS.length} parts.`
96 : html`One part of ${SPECIMENS.length}: <a href="${hrefWith(q, { part: undefined })}">show them all</a>.`}
97 </p>
98 <div class="bar">${themes}${widths}</div>
99 <form id="${GALLERY_SEARCH_FORM}" method="get" action="/design/components">
100 ${(["theme", "w", "part"] as const).map((key) => (q[key] === undefined ? null : html`<input type="hidden" name="${key}" value="${q[key]}" />`))}
101 </form>
102 <div class="gallery-frame" ${q.w === undefined ? null : html`data-w="${q.w}"`}>
103 <div class="stack">${shown.map((s) => specimen(s, q))}</div>
104 </div>
105 </div>`;
106 return page({
107 ctx: q.theme === undefined ? ctx : { ...ctx, theme: q.theme },
108 title: "Components",
109 wide: q.w === "1440",
110 crumbs: [{ label: "Components", href: "/design/components" }],
111 body,
112 });
113 }
src/web/pages/limb.ts +10 −8
@@ -33,7 +33,7 @@ import {
3333 import { field, readForm } from "../form.ts";
3434 import { html, when, type Html } from "../html.ts";
3535 import { page, redirect } from "../layout.ts";
36 import { badge, btn, card, field as formField, listCard, row, selectField } from "../ui.ts";
36 import { badge, btn, card, dialogParts, field as formField, listCard, row, selectField } from "../ui.ts";
3737 import { replanPreviewPage, replanSubmit } from "./limb_replan.ts";
3838 import { folded, issueRow } from "./limb_view.ts";
3939 import { milestoneHref } from "./milestones.ts";
@@ -280,10 +280,11 @@ export function limbPreviewPage(ctx: Ctx): Response {
280280 class="dialog"
281281 aria-labelledby="limb-confirm-title"
282282 >
283 <div class="dialog-head">
284 <h2 id="limb-confirm-title">${words.go}?</h2>
285 </div>
286 <div class="dialog-body stack">
283 ${dialogParts({
284 titleId: "limb-confirm-title",
285 title: `${words.go}?`,
286 stack: true,
287 body: html`
287288 <input type="hidden" name="action" value="${action}" />
288289 ${when(
289290 request.under,
@@ -316,8 +317,8 @@ export function limbPreviewPage(ctx: Ctx): Response {
316317 ],
317318 }),
318319 )}
319 </div>
320 <div class="dialog-foot">
320 `,
321 foot: html`
321322 ${btn("Back", {
322323 href: milestoneHref(base, number),
323324 variant: "ghost",
@@ -325,7 +326,8 @@ export function limbPreviewPage(ctx: Ctx): Response {
325326 ${btn(words.go, {
326327 variant: action === "close" ? "danger" : "primary",
327328 })}
328 </div>
329 `,
330 })}
329331 </form>
330332 </div>`
331333 : html`<p class="mt">
src/web/pages/origins.ts +8 −11
@@ -76,6 +76,7 @@ import {
7676 field as uiField,
7777 type IconName,
7878 copyField,
79 toast,
7980 } from "../ui.ts";
8081
8182 export type AccountSection =
@@ -840,19 +841,15 @@ export function originsPage(ctx: Ctx): Response {
840841 const error = params.get("error");
841842 const connected = params.get("connected") === "1";
842843 const banner = connected
843 ? html`<div class="toast" data-tone="success" role="status">
844 ${icon("check")}
845 <div class="toast-body">Origin connected.</div>
846 </div>`
844 ? toast({ tone: "success", message: "Origin connected." })
847845 : error !== null && error !== ""
848 ? html`<div class="toast" data-tone="danger" role="status">
849 ${icon("alert")}
850 <div class="toast-body">
851 ${error === "state"
846 ? toast({
847 tone: "danger",
848 message:
849 error === "state"
852850 ? "That authorization could not be matched to a connect you started here. Start again."
853 : error.slice(0, 200)}
854 </div>
855 </div>`
851 : error.slice(0, 200),
852 })
856853 : null;
857854
858855 const timing = { rendering: performance.now() };
src/web/pages/repo.ts +2 −4
@@ -85,6 +85,7 @@ import {
8585 seg,
8686 time,
8787 copyField,
88 toast,
8889 } from "../ui.ts";
8990
9091 const MAX_RENDER_BYTES = 1_000_000;
@@ -614,10 +615,7 @@ function aboutCard(
614615 </ul>
615616 ${when(
616617 o.fetchError !== "",
617 () => html`<div class="toast" data-tone="danger" role="status">
618 ${icon("alert")}
619 <div class="toast-body">${o.fetchError}</div>
620 </div>`,
618 () => toast({ tone: "danger", message: o.fetchError }),
621619 )}
622620 ${when(
623621 admin,
src/web/style/components.ts +23
@@ -749,6 +749,19 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
749749 .toast .toast-body { flex: 1; min-width: 0; }
750750 .toast code { display: block; margin-top: 6px; }
751751
752 /* ---- skeleton (a list's or card's space, held while it loads) ---- */
753 .skeleton .row-main { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
754 .skeleton-bar {
755 display: inline-block; vertical-align: middle;
756 width: 60%; height: .75em; border-radius: var(--radius);
757 background: var(--muted);
758 animation: skeleton-pulse 1.2s var(--ease) infinite alternate;
759 }
760 .skeleton .row-meta .skeleton-bar, .skeleton .card-body p:last-child .skeleton-bar { width: 35%; }
761 .skeleton li:nth-child(3n + 2) .row-title .skeleton-bar { width: 75%; }
762 .skeleton .card-head .skeleton-bar { width: 30%; }
763 @keyframes skeleton-pulse { to { opacity: .45; } }
764
752765 /* ---- tooltip ---- */
753766 [data-tip] { position: relative; }
754767 [data-tip]::after {
@@ -886,6 +899,16 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
886899 .palette .palette-input { font-size: 16px; }
887900 }
888901
902 /* ---- gallery (/design/components) ---- */
903 .gallery-frame { overflow-x: auto; }
904 .gallery-frame[data-w="390"] > .stack { width: 390px; }
905 .gallery-frame[data-w="1440"] > .stack { width: 1440px; }
906 .gallery-stage {
907 padding: 12px; border: 1px dashed var(--border); border-radius: var(--radius);
908 min-width: 0; overflow-wrap: anywhere;
909 }
910 .gallery-stage .list { max-height: 480px; overflow-y: auto; }
911
889912 /* Forced colours drop box-shadow rings and author colours: the focus ring is
890913 an outline the system paints. */
891914 @media (forced-colors: active) {
src/web/ui.ts +163
@@ -1231,6 +1231,96 @@ export function selectField(
12311231 </div>`;
12321232 }
12331233
1234 /** One choice in a `searchPicker`: what it submits, how it reads, and the words a filter matches. */
1235 export interface PickerOption {
1236 readonly value: string;
1237 readonly title: Html | string;
1238 readonly meta?: Html | string;
1239 /** The text the filter looks in; the title and anything else worth finding by. */
1240 readonly search: string;
1241 readonly checked?: boolean;
1242 }
1243
1244 /** Choices a picker draws per page; past it, the pager or the filter narrows. */
1245 export const PICKER_PAGE = 50;
1246
1247 /**
1248 * A long list a person picks from: a search box, a page of checkbox rows
1249 * (radios when `multiple` is false), and a pager. It does the filtering and
1250 * paging itself, from `q` and `page`, so a caller hands it every choice and
1251 * the words the reader typed. A checked choice off this page or outside the
1252 * filter rides along as a hidden input, so paging or narrowing never drops
1253 * a pick.
1254 *
1255 * Forms do not nest, so the search box belongs to the GET form named by
1256 * `searchForm` — a `<form id method="get">` the caller puts outside the
1257 * form the picks submit in. With script, typing narrows this page's rows at
1258 * once and the count follows (`client.ts`, "search pickers"); Enter asks the
1259 * server for every page.
1260 */
1261 export function searchPicker(o: {
1262 /** The picker's id; its parts' ids derive from it. */
1263 id: string;
1264 label: string;
1265 /** The name each pick submits under, once per chosen value. */
1266 name: string;
1267 options: readonly PickerOption[];
1268 q: string;
1269 searchForm: string;
1270 /** 1-based; out of range reads as the nearest page. */
1271 page: number;
1272 pageHref: (page: number) => string;
1273 pageSize?: number;
1274 multiple?: boolean;
1275 hint?: string;
1276 }): Html {
1277 const size = Math.max(1, Math.floor(o.pageSize ?? PICKER_PAGE));
1278 const needle = o.q.trim().toLowerCase();
1279 const matched = o.options.filter((opt) => needle === "" || opt.search.toLowerCase().includes(needle));
1280 const pages = Math.max(1, Math.ceil(matched.length / size));
1281 const page = Math.min(pages, Math.max(1, Number.isFinite(o.page) ? Math.floor(o.page) : 1));
1282 const shown = matched.slice((page - 1) * size, page * size);
1283 const onPage = new Set(shown.map((opt) => opt.value));
1284 const carried = o.options.filter((opt) => opt.checked === true && !onPage.has(opt.value));
1285 const picked = o.options.filter((opt) => opt.checked === true).length;
1286 const kind = o.multiple === false ? "radio" : "checkbox";
1287 const hintId = `${o.id}-hint`;
1288 return html`<div class="field" id="${o.id}" data-picker>
1289 <label for="${o.id}-q">${o.label}</label>
1290 <div class="bar">
1291 <input class="input grow" type="search" id="${o.id}-q" name="q" form="${o.searchForm}" value="${o.q}"
1292 placeholder="Filter" autocomplete="off" spellcheck="false" aria-controls="${o.id}-list"
1293 ${o.hint ? html`aria-describedby="${hintId}"` : null} data-picker-q />
1294 <span class="muted small num" aria-live="polite"
1295 ><span data-picker-count="${matched.length}">${matched.length}</span> of ${o.options.length}${kind === "checkbox"
1296 ? html` · <span data-picker-picked>${picked}</span> picked`
1297 : null}</span
1298 >
1299 </div>
1300 ${shown.length === 0
1301 ? html`<p class="muted small">${o.options.length === 0 ? "Nothing to pick from yet." : html`Nothing matches “${o.q.trim()}”.`}</p>`
1302 : html`<ul class="list" id="${o.id}-list" role="group" aria-label="${o.label}">
1303 ${shown.map(
1304 (opt) => html`<li data-q="${opt.search.toLowerCase()}">
1305 <label class="row">
1306 <span class="row-lead"><input type="${kind}" name="${o.name}" value="${opt.value}" ${opt.checked ? raw("checked") : null} /></span>
1307 <span class="row-main"><span class="row-title">${opt.title}</span>${opt.meta ? html`<span class="row-meta">${opt.meta}</span>` : null}</span>
1308 </label>
1309 </li>`,
1310 )}
1311 </ul>`}
1312 ${carried.map((opt) => html`<input type="hidden" name="${o.name}" value="${opt.value}" data-picker-carried />`)}
1313 ${pages > 1
1314 ? pager({
1315 ...(page > 1 ? { prev: o.pageHref(page - 1) } : {}),
1316 ...(page < pages ? { next: o.pageHref(page + 1) } : {}),
1317 note: `page ${page} of ${pages}`,
1318 })
1319 : null}
1320 ${o.hint ? html`<span class="hint" id="${hintId}">${o.hint}</span>` : null}
1321 </div>`;
1322 }
1323
12341324 /**
12351325 * A destructive action. With JS it opens a `<dialog>`; without it the button
12361326 * is a plain link to a confirm page, so nothing is ever one careless click
@@ -1265,6 +1355,79 @@ export function empty(o: {
12651355 </div>`;
12661356 }
12671357
1358 export type ToastTone = "success" | "danger" | "attn";
1359
1360 /**
1361 * The one-line banner a page shows once: the flash a write leaves after its
1362 * redirect, or a failure the page found itself. An icon for its tone, the
1363 * message, then an optional link and a copyable one-time code.
1364 */
1365 export function toast(o: {
1366 tone?: ToastTone;
1367 message: string | Html;
1368 link?: { href: string; label: string };
1369 /** A one-time value, shown in a copyable monospace block. */
1370 code?: string;
1371 /** The code block's id; one toast per page, so the default rarely moves. */
1372 codeId?: string;
1373 /** `alert` when the failure is what the page is about; `status` otherwise. */
1374 role?: "status" | "alert";
1375 }): Html {
1376 const tone = o.tone ?? "success";
1377 return html`<div class="toast" data-tone="${tone}" role="${o.role ?? "status"}">
1378 ${icon(tone === "success" ? "check" : "alert")}
1379 <div class="toast-body">
1380 ${o.message}${when(o.link, (link) => html` · <a href="${link.href}">${link.label}</a>`)}
1381 ${when(o.code, (code) => copyField(o.codeId ?? "toast-code", code, "Code", "Copy code"))}
1382 </div>
1383 </div>`;
1384 }
1385
1386 /**
1387 * A §5 dialog's three parts — the head that names it (`titleId` is what the
1388 * wrapper's `aria-labelledby` points at), the body, and the foot of buttons,
1389 * the primary or danger one last. The wrapper is the caller's: a `<dialog>`
1390 * the shell opens, or a `<form class="dialog">` drawn as a page of its own.
1391 */
1392 export function dialogParts(o: {
1393 titleId: string;
1394 title: string | Html;
1395 body: Html;
1396 foot: Html;
1397 /** The body holds several fields, spaced as a stack. */
1398 stack?: boolean;
1399 /** Attributes on the body, for a script that fills it. */
1400 bodyAttrs?: Html;
1401 }): Html {
1402 return html`<div class="dialog-head"><h2 id="${o.titleId}">${o.title}</h2></div>
1403 <div class="dialog-body${o.stack ? " stack" : ""}" ${o.bodyAttrs ?? null}>${o.body}</div>
1404 <div class="dialog-foot">${o.foot}</div>`;
1405 }
1406
1407 /**
1408 * A placeholder that holds a list's or a card's space while what goes there
1409 * loads: real `.list` rows or a real `.card`, so the swap shifts nothing, with
1410 * grey bars where the words will be. The bars pulse; asked for less motion,
1411 * they hold still.
1412 */
1413 export function skeleton(o: { shape?: "list" | "card"; rows?: number } = {}): Html {
1414 const n = Math.min(Math.max(Math.trunc(o.rows ?? 3) || 1, 1), 50);
1415 const bar = raw('<span class="skeleton-bar"></span>');
1416 const lines = Array.from({ length: n }, () => bar);
1417 const body =
1418 o.shape === "card"
1419 ? html`<div class="card-head">${bar}</div>
1420 <div class="card-body stack">${lines.map((b) => html`<p>${b}</p>`)}</div>`
1421 : html`<ul class="list">
1422 ${lines.map(
1423 (b) => html`<li><div class="row"><span class="row-main"><span class="row-title">${b}</span><span class="row-meta">${b}</span></span></div></li>`,
1424 )}
1425 </ul>`;
1426 return html`<div class="card skeleton" role="status" aria-busy="true">
1427 <span class="sr-only">Loading…</span>${body}
1428 </div>`;
1429 }
1430
12681431 export interface TimelineEvent {
12691432 icon: IconName;
12701433 tone?: Tone;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs