Public: anyone can read this; the crew can change it.
A fantastic component library: a living gallery, the missing parts (search picker first), a drift gate, and a cold-read UI audit #16926
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/5817-a-fantastic-component-library-a-living-g → main 0 commits fork 2 threads · 2 unresolved
5 files
changed +37
−3
docs/design/sections/5-components.md +4
| @@ -42,6 +42,10 @@ specification. | ||
| 42 | 42 | | **tooltip** | `[data-tip]` | `data-tip-side=bottom` | hover/focus; hidden on coarse pointers | a status-bar hint | |
| 43 | 43 | | **toast / flash** `toast()` | `.toast` | `data-tone=success\|danger\|attn` | one per page load, cookie-driven | a one-line banner | |
| 44 | 44 | | **skeleton** `skeleton()` | `.skeleton` (a `.card`), `.skeleton-bar` | `shape=list\|card` | real `.list` rows or a real `.card` holding grey bars, so the swap shifts nothing; `role="status"`, `aria-busy`, "Loading…" for a screen reader; bars hold still under reduced motion | the same card, no pulse | |
| 45 | | **inline field error** `field({ error })` | `.field .error` | `[aria-invalid]` | the message sits under the control and is wired by `aria-describedby`; long text wraps | a red line under the value | | |
| 46 | | **copy button** `copyField()` | `.btn.btn-icon` beside a read-only field | `copy=<id>` | script-only; without script the field stays selectable | the value to select | | |
| 47 | | **confirm action** `confirmAction()` | `.btn[data-variant=danger]` | `size=sm` | a link to a confirm page, a dialog with script | a `y/n` line | | |
| 48 | | **search picker** `pickList()` | `.pick` (`.pick-bar`, `.pick-chip`, `.pick-list`) | `data-pick-plain`, `data-invalid` | plain checkboxes without script; filter, chips and count with it; holds 200 items in a box that scrolls | a filtered list, one key to tick | | |
| 45 | 49 | | **command palette** | `.palette` | — | JS only; degrades to `/search` | a fuzzy-find overlay | |
| 46 | 50 | | **page head** `pageHead()` (`chrome.ts`) | `.page-head` (`h1`, `.page-head-sub`; a `.spacer` before the actions) | `lead` before the title, `actions` right-aligned, `sub` on its own line below | wraps; the title's `min-width: 0` lets a long one shrink beside the actions | the title line, actions right, a dim subtitle under it | |
| 47 | 51 | | **breadcrumb** `crumbs()` | `.crumbs` | `.mono` | `aria-current` on the last | `a / b / c` | |
docs/features/design-gallery.md +2
| @@ -11,3 +11,5 @@ The frames are as wide as your window, because a media query reads the window. T | ||
| 11 | 11 | The page is static: it reads nothing from your request or the database. The live-theme explorer at `/design/components` (signed in) draws the same parts with the forge's current theme. |
| 12 | 12 | |
| 13 | 13 | In the terminal, open the palette and choose "Component gallery". It says how many components the gallery holds and where; the page itself is web-only, since it is about how things look. |
| 14 | ||
| 15 | The search picker (`pickList`), inline field error, copy button and confirm action are in the gallery too, each in its hard states: a picker with three items, none, an error and 200 items (some with names long enough to wrap); a field error long enough to wrap; a copy button on a long link; a segmented control with a very long label. In the terminal the palette line names the picker's 200-item specimen. |
src/tui/screens/design_gallery.ts +1 −1
| @@ -4,7 +4,7 @@ import type { PaletteEntry } from "./entries.ts"; | ||
| 4 | 4 | import { samples } from "../../web/pages/design-components.ts"; |
| 5 | 5 | |
| 6 | 6 | /** The one sentence the toast says. */ |
| 7 | export const galleryLine = (): string => `${samples.length} components, drawn once each at /design/gallery`; | |
| 7 | export const galleryLine = (): string => `${samples.length} components, drawn at /design/gallery, the search picker at 200 items`; | |
| 8 | 8 | |
| 9 | 9 | export const entry: PaletteEntry = { |
| 10 | 10 | rank: 900, |
src/web/pages/design-components.ts +13 −2
| @@ -15,14 +15,21 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 15 | 15 | import { Html, html, raw } from "../html.ts"; |
| 16 | 16 | import { pageHead } from "../chrome.ts"; |
| 17 | 17 | import { page } from "../layout.ts"; |
| 18 | import { pickList } from "../pick.ts"; | |
| 18 | 19 | import { |
| 19 | labelCss, avatar, badge, btn, card, counts, crumbs, disclosure, dot, empty, field, iconBtn, kbd, labelChip, | |
| 20 | copyField, confirmAction, labelCss, avatar, badge, btn, card, counts, crumbs, disclosure, dot, empty, field, iconBtn, kbd, labelChip, | |
| 20 | 21 | listCard, menu, meter, nameMark, pager, pill, row, seg, sha, stat, stateBadge, tabs, tlComment, |
| 21 | 22 | tlEvent, dialogParts, skeleton, toast, userTag, verdictBadge, runStateBadge, envStateBadge, |
| 22 | 23 | } from "../ui.ts"; |
| 23 | 24 | |
| 24 | 25 | const r = (markup: string): Html => raw(markup); |
| 25 | 26 | |
| 27 | /** 200 options, every seventh with a long name: the states the picker must hold. */ | |
| 28 | const PICK_ITEMS = Array.from({ length: 200 }, (_, i) => ({ | |
| 29 | value: `a${i + 1}`, | |
| 30 | label: i % 7 === 0 ? `app-${i + 1}-with-a-name-long-enough-to-wrap-on-a-phone-and-still-read` : `app-${i + 1}`, | |
| 31 | })); | |
| 32 | ||
| 26 | 33 | const sampleRows = [ |
| 27 | 34 | row({ href: "#", title: "Make the feed answer in under 50 ms", meta: html`#41 · opened by <b>scout</b>`, state: "open" }), |
| 28 | 35 | row({ href: "#", title: "Escape every output", meta: html`#38 · merged`, state: "merged" }), |
| @@ -55,7 +62,11 @@ export const samples: readonly (readonly [name: string, sample: Html])[] = [ | ||
| 55 | 62 | ["colour field", html`<label class="color-field"><input type="color" value="${THEMES.light.tokens.accent}" aria-label="Colour" /> <span>accent</span></label>`], |
| 56 | 63 | ["table", r(`<table class="table"><thead><tr><th>Name</th><th>State</th></tr></thead><tbody><tr><td>feed</td><td>live</td></tr><tr><td>map</td><td>live</td></tr></tbody></table>`)], |
| 57 | 64 | ["tabs", tabs([{ label: "Issues", href: "#", count: 4, current: true }, { label: "Pulls", href: "#", current: false }], "Gallery tabs")], |
| 58 | ["segmented control", seg([{ label: "Open", href: "#", current: true }, { label: "Closed", href: "#", current: false }])], | |
| 65 | ["segmented control", html`<div class="gallery-col">${seg([{ label: "Open", href: "#", current: true }, { label: "Closed", href: "#", current: false }, { label: "Closed, merged and everything else that has ever happened here", href: "#", current: false }])}${seg([{ label: "Only", href: "#", current: true }])}</div>`], | |
| 66 | ["inline field error", html`<div class="gallery-col">${field({ label: "Name", name: "gallery-bad", value: "Not Valid!", error: "Lowercase letters and dashes only." })}${field({ label: "Address", name: "gallery-long", value: "x", error: "That address is not one we can reach: ".repeat(4) })}</div>`], | |
| 67 | ["copy button", html`<div class="gallery-col">${copyField("gallery-copy", "https://forge.example/sample", "Link", "Copy the link")}${copyField("gallery-copy-long", "https://forge.example/".concat("a-very-long-path/".repeat(8)), "Long link", "Copy the link")}</div>`], | |
| 68 | ["confirm action", html`<div class="gallery-line">${confirmAction({ action: "/admin/invites/sample/revoke", verb: "Delete" })}${confirmAction({ action: "/admin/invites/sample/revoke", verb: "Remove", size: "sm", label: "Remove the gallery sample" })}</div>`], | |
| 69 | ["search picker", html`<div class="gallery-col">${pickList({ legend: "Few", name: "gallery-few", items: PICK_ITEMS.slice(0, 3), chosen: ["a1"], noun: "apps", plainUpTo: 5 })}${pickList({ legend: "None to pick", name: "gallery-none", items: [], chosen: [], noun: "apps" })}${pickList({ legend: "Long names, 200 items, one picked", name: "gallery-many", items: PICK_ITEMS, chosen: ["a7"], noun: "apps" })}${pickList({ legend: "With an error", name: "gallery-err", items: PICK_ITEMS.slice(0, 8), chosen: [], noun: "apps", error: "Pick at least one app." })}</div>`], | |
| 59 | 70 | ["menu", menu({ trigger: "Actions", items: [{ label: "Rename", href: "#" }, { label: "Archive", href: "#" }] })], |
| 60 | 71 | ["disclosure", disclosure("More detail", html`<p>Hidden until opened.</p>`)], |
| 61 | 72 | ["dialog", html`<div class="dialog gallery-static" role="dialog" aria-label="Sample dialog">${dialogParts({ titleId: "gallery-dialog-title", title: "Delete this?", body: html`<p>It cannot be undone.</p>`, foot: html`<button class="btn" type="button">Cancel</button>${btn("Delete", { variant: "danger" })}` })}</div>`], |
test/design-gallery.test.ts +17
| @@ -48,3 +48,20 @@ describe("toast, dialogParts and skeleton (#5880)", () => { | ||
| 48 | 48 | expect(card.match(/<p><span class="skeleton-bar">/g)?.length).toBe(2); |
| 49 | 49 | }); |
| 50 | 50 | }); |
| 51 | ||
| 52 | describe("the gallery shows each part in its hard states (#5817)", () => { | |
| 53 | const drawn = (name: string) => samples.find(([n]) => n === name)?.[1].text ?? ""; | |
| 54 | test("search picker: 200 items, none, an error", () => { | |
| 55 | const p = drawn("search picker"); | |
| 56 | expect(p.match(/data-pick-item/g)?.length).toBe(3 + 8 + 200); | |
| 57 | expect(p).toContain("Pick at least one app."); | |
| 58 | expect(p).toContain("1 of 200 apps picked"); | |
| 59 | expect(p).toContain("0 of 0 apps picked"); | |
| 60 | }); | |
| 61 | test("field error, copy button, confirm action and segmented filter have specimens", () => { | |
| 62 | expect(drawn("inline field error")).toContain('aria-invalid="true"'); | |
| 63 | expect(drawn("copy button")).toContain("data-copy"); | |
| 64 | expect(drawn("confirm action")).toContain("/-/confirm?to="); | |
| 65 | expect(drawn("segmented control")).toContain("everything else that has ever happened"); | |
| 66 | }); | |
| 67 | }); |
new above
offline
Principle 8 (plain words): '...the search picker at 200 items' is a detail about one specimen, not what the line is for. Say '<n> components, drawn at /design/gallery' and let the page carry the specimens.