From b66a0cd32fc9b1ed59cd799c8319203173b304a0 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Mon, 30 Nov 2026 21:37:40 -0800 Subject: [PATCH 1/4] Kit: add Chip and Chips, and rebuild ChangePills on them A chip is one small item as a pill: a category dot, a monospace label, trailing content and a tone. A changed chip is painted in its hue (or only signed, inside an item already marked), struck through when removed, all fading with emphasis, and can hang a status tab whose width it always reserves. Chips is a wrapping list that can keep the tabs' room. ChangePills is now a Chips list of signed chips and gains a modified state. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/guides/renderer-kit-components.md | 42 ++++- docs/guides/renderer-kit.md | 6 +- docs/reference/renderer-kit.md | 56 +++++- eslint-suppressions.json | 5 - .../browser/agentic-workflows.spec.ts | 14 +- .../agentic-workflows/src/styles.css | 6 +- packages/renderers/kit/react.css | 1 + packages/renderers/kit/src/react.ts | 1 + packages/renderers/kit/src/react/chip.tsx | 159 ++++++++++++++++++ .../kit/src/react/diff-components.tsx | 64 ++----- packages/renderers/kit/styles/chips.css | 122 ++++++++++++++ packages/renderers/kit/styles/diff.css | 43 +---- packages/renderers/kit/styles/regions.css | 2 +- packages/renderers/kit/test/chip.test.mjs | 74 ++++++++ packages/renderers/kit/test/diff.test.mjs | 17 +- 15 files changed, 492 insertions(+), 120 deletions(-) create mode 100644 packages/renderers/kit/src/react/chip.tsx create mode 100644 packages/renderers/kit/styles/chips.css create mode 100644 packages/renderers/kit/test/chip.test.mjs diff --git a/docs/guides/renderer-kit-components.md b/docs/guides/renderer-kit-components.md index f3404f18d..6fbf31e63 100644 --- a/docs/guides/renderer-kit-components.md +++ b/docs/guides/renderer-kit-components.md @@ -324,8 +324,8 @@ for domain meaning that isn't a change between revisions: removed item's text stays muted). - `default` is everything else, and adds nothing. -`Text` and `DataTable` (`tone={item => …}`, from the version a row shows) take a -`tone`. Anything else spreads `toneAttributes(tone)` (from +`Text`, `Chip` and `DataTable` (`tone={item => …}`, from the version a row +shows) take a `tone`. Anything else spreads `toneAttributes(tone)` (from `@githubnext/projections/kit`), which sets `data-projections-tone` on an HTML element or SVG text. A tone stays neutral: it never uses a change hue, a dashed edge, or opacity, so it never reads as added, removed, or modified. Change @@ -335,6 +335,44 @@ its own colors inside a toned item. A table cell carries the tone of each version it lays out, so a column's reserved width holds when a row's tone changes between revisions. +## Chips + +A chip is one small item as a pill: a tool, a binary, a tag. `Chip` draws an +optional category `dot` (a CSS color, such as a palette's color for the item's +category), its `label` (monospace as an identifier by default; `font="text"` for +words), trailing content as its children (a count, a note), and a +[tone](#tones). `Chips` lays chips out as a wrapping list (`label` names it). + +- **Change.** `change` is the chip's own change (`added`, `removed`, `modified`, + `renamed`). A changed chip is painted in its hue, a removed one struck through + and muted, all fading with `emphasis` (or, left out, the `--emphasis` of the + item around it), so a chip at an endpoint reads plain. Assistive technology + hears the change in words. `sign` adds the diff's `+`, `−` or `~` before the + label. Set `paint={false}` for a chip that arrives or leaves with an item + already marked around it, so change colors never nest: its sign and words + still say it. +- **Status tab.** `status` hangs a `StatusTab` of that change under the chip, + fading with `emphasis`. The chip reserves the tab's width at every frame, so + it is never narrower than its tab and never changes width; put such chips in + ``, which keeps the tab's room under every line. +- **Selection.** With `id` and `onSelect` a chip is a button that selects the + item. It is a part (`pk-part`) of the unit around it, or, with `unit`, a ring + unit of its own. + +```tsx + + {tools.map(tool => ( + + {tool.calls} + + ))} + +``` + +`ChangePills` is a `Chips` list of signed chips for a list whose items arrive, +leave or change. + ## Data tables When your entities share comparable properties, reach for `DataTable` instead of diff --git a/docs/guides/renderer-kit.md b/docs/guides/renderer-kit.md index 42195f465..490aee218 100644 --- a/docs/guides/renderer-kit.md +++ b/docs/guides/renderer-kit.md @@ -365,9 +365,9 @@ Building a solid diff mode takes seven steps: arrow) the new value in an added pill, read to assistive tech as "was …, now …". `SvgValueChange` provides the SVG single-line equivalent (`pk-svg-was`, `pk-svg-arrow`, `pk-svg-now`). - - `ChangePills({items, label, onSelect?, selectedId?})` renders added and - removed list items as `+` / `−` pills with worded changes alongside plain - unchanged items for context. Pills with an `entityId` are selectable parts. + - `ChangePills({items, label, onSelect?, selectedId?})` renders changed list + items as `+` / `−` / `~` chips (`Chip`), worded, beside plain unchanged + ones. Pills with an `entityId` are selectable parts. - `fieldChanges(before, after, {fields})` and `fieldLines(row, {fields, exclude, object})` extract differing fields (`formatValue` formats values as extracted; `sameValue` compares diff --git a/docs/reference/renderer-kit.md b/docs/reference/renderer-kit.md index f4a7f0ac2..484a02bc8 100644 --- a/docs/reference/renderer-kit.md +++ b/docs/reference/renderer-kit.md @@ -3766,10 +3766,9 @@ endpoints and with highlighting off. ChangePills(__0: { "className"?: string; "items": Array; "label": string; "onSelect"?: undefined | { (id: string): void }; "selectedId"?: null | string | undefined }): Element ``` -A list whose items arrive and leave, as pills: added ones with `+` in the -added hue, removed ones with `−` struck through in the removed hue, and -unchanged ones plain, for context. Each says its change to assistive -technology. Pills with an `entityId` are buttons that select it. +A list whose items arrive, leave or change, as chips (`Chip`): added ones with `+` in the added hue, removed ones +with `−` struck through in the removed hue, modified ones with `~` in the modified hue, and unchanged ones plain, for +context. Each says its change to assistive technology. Pills with an `entityId` are buttons that select it. ### `ChangeStatus` @@ -3781,6 +3780,53 @@ A change-status cell of fixed width, for table-like rows that keep their status in a column: reserved on every row, filled while the change is emphasized. `width` defaults to room for one part (`~ Modified`). +### `Chip` + +```ts +Chip(__0: ChipProps): Element +``` + +One small item as a pill: an optional category dot, its label (monospace by default) and trailing content, in a +neutral edge. A changed chip is painted in its change's hue (fading with `emphasis`), struck through when removed, +and can carry its sign and a status tab; assistive technology hears its change in words. With `id` and `onSelect` +it is a button that selects the item. + +### `ChipProps` + +```ts +interface ChipProps +``` + +Props of `Chip`. + +| Member | Signature | Description | +|---|---|---| +| `change` | `"change"?: "added" \| "modified" \| "removed" \| "renamed" \| "unchanged" \| undefined` | The chip's own change. Unchanged (the default) draws it plain. | +| `children` | `"children"?: Iterable \| Promise \| ReactElement \| Promise \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined } \| { new (props: any, context: any): Component }> \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined> \| ReactElement \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined> \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined } \| { new (props: any, context: any): Component }> \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined` | What follows the label: a count, a note. | +| `className` | `"className"?: string \| undefined` | More classes on the chip. | +| `description` | `"description"?: string \| undefined` | Extra words for assistive technology, after the label. | +| `dot` | `"dot"?: string \| undefined` | A category's color (a CSS color, such as a palette's color for the item's category), as a dot before the label. | +| `emphasis` | `"emphasis"?: number \| undefined` | How strongly the change is shown (`RendererProps.emphasis`), 0 to 1: the hue and the status tab fade with it. Left out, the chip follows the `--emphasis` of the item around it (fully shown when there is none). | +| `font` | `"font"?: "code" \| "text" \| undefined` | `code` (the default) sets the label in the monospace font as an identifier; `text` keeps the UI font. | +| `id` | `"id"?: string \| undefined` | Makes the chip a button that selects this ID (`data-entity-id`), with `onSelect`. | +| `label` | `"label": Iterable \| Promise \| ReactElement \| Promise \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined } \| { new (props: any, context: any): Component }> \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined> \| ReactElement \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined> \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined } \| { new (props: any, context: any): Component }> \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined` | What the chip names. | +| `onSelect` | `"onSelect"?: undefined \| { (id: string): void }` | Selects the chip's item (`RendererProps.onSelect`). | +| `paint` | `"paint"?: false \| true \| undefined` | Paints the change: the chip's edge and fill in its hue (the default). Turn it off for a chip that arrives or leaves with an item already marked around it, so change colors never nest; its sign and words still say it. | +| `selected` | `"selected"?: false \| true \| undefined` | Whether the host has selected the chip's item (`RendererProps.selectedId`). | +| `sign` | `"sign"?: false \| true \| undefined` | Puts the change's sign (`+`, `−`, `~`) before the label, as a diff does. | +| `status` | `"status"?: undefined \| { "renamed"?: false \| true \| undefined; "status": "added" \| "modified" \| "removed" \| "unchanged"; "varied"?: Array \| undefined }` | A status tab hanging under the chip (`StatusTab`), for its change in words; keep its room with ``. | +| `tone` | `"tone"?: "default" \| "flag" \| "quiet" \| undefined` | How much the chip asks for attention apart from its change (`Tone`). | +| `unit` | `"unit"?: false \| true \| undefined` | Marks the chip as a ring unit of its own (`data-projections-unit`), for a chip that is an item. By default a selectable chip is a part (`pk-part`) of the unit around it. | + +### `Chips` + +```ts +Chips(__0: { "children": Iterable | Promise | ReactElement | Promise | Promise | ReactElement | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component }> | ReactPortal | bigint | false | null | number | string | true | undefined> | ReactElement | Promise | ReactElement | ReactPortal | bigint | false | null | number | string | true | undefined> | Promise | ReactElement | ReactPortal | bigint | false | null | number | string | true | undefined } | { new (props: any, context: any): Component }> | ReactPortal | bigint | false | null | number | string | true | undefined; "className"?: string | undefined; "label": string; "tabs"?: false | true | undefined }): Element +``` + +Chips in a wrapping list, each a list item. `tabs` keeps a status tab's room under every line, so nothing moves +when a chip's status appears. + ### `ContentView` ```ts @@ -4278,7 +4324,7 @@ One pill of a `ChangePills` list. | Member | Signature | Description | |---|---|---| -| `change` | `"change"?: "added" \| "removed" \| "unchanged"` | Added and removed pills carry a + or − sign and their hue; unchanged ones are plain. | +| `change` | `"change"?: "added" \| "modified" \| "removed" \| "unchanged"` | Changed pills carry a sign (+, − or ~) and their hue; unchanged ones are plain. | | `entityId` | `"entityId"?: string` | Makes the pill a selectable part (`data-entity-id`), activated with `onSelect`. | | `key` | `"key": string` | React key for the pill: unique within the list and stable across renders. | | `label` | `"label": Iterable \| Promise \| ReactElement \| Promise \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined } \| { new (props: any, context: any): Component }> \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined> \| ReactElement \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined> \| Promise \| ReactElement \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined } \| { new (props: any, context: any): Component }> \| ReactPortal \| bigint \| false \| null \| number \| string \| true \| undefined` | The pill's content. | diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 214583b71..2615f28bc 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -2495,11 +2495,6 @@ "count": 1 } }, - "packages/renderers/kit/src/react/diff-components.tsx": { - "@typescript-eslint/no-non-null-assertion": { - "count": 1 - } - }, "packages/renderers/kit/src/react/drag-pan.ts": { "@typescript-eslint/no-non-null-assertion": { "count": 2 diff --git a/packages/renderers/agentic-workflows/browser/agentic-workflows.spec.ts b/packages/renderers/agentic-workflows/browser/agentic-workflows.spec.ts index 6d5af618e..16ee1e618 100644 --- a/packages/renderers/agentic-workflows/browser/agentic-workflows.spec.ts +++ b/packages/renderers/agentic-workflows/browser/agentic-workflows.spec.ts @@ -86,13 +86,13 @@ test('the diff draws each workflow once in its group, with each section’s dire const card = renderer.frame.locator(`[data-entity-id="${bot}"]`) const section = (id: string) => card.locator(`.aw-section[data-section="${id}"]`) await expect(section('loads').locator('.aw-direction')).toHaveText('Widened') - await expect(section('loads').locator('.pk-change-pill[data-change="removed"]')).toContainText('skills/check-links') - await expect(section('repos').locator('.pk-change-pill[data-change="added"]')).toHaveText(/octo-org\/docs-site/u) + await expect(section('loads').locator('.pk-chip[data-change="removed"]')).toContainText('skills/check-links') + await expect(section('repos').locator('.pk-chip[data-change="added"]')).toHaveText(/octo-org\/docs-site/u) // A limit that moves reads old → new: in one pill when short, as the old pill leaving and the new arriving when not. const examples = renderer.frame.locator('[data-entity-id="workflow:.github/workflows/docs-bot-examples.md"]') await expect(examples.locator('.aw-section[data-section="budgets"] .pk-value-change')).toHaveText(/60 min.*30 min/u) - await expect(section('budgets').locator('.pk-change-pill[data-change="removed"]')).toHaveText(/2,000/u) - await expect(section('budgets').locator('.pk-change-pill[data-change="added"]')).toHaveText(/5,000/u) + await expect(section('budgets').locator('.pk-chip[data-change="removed"]')).toHaveText(/2,000/u) + await expect(section('budgets').locator('.pk-chip[data-change="added"]')).toHaveText(/5,000/u) // A lock state that changes reads old → new on the card's meta line. const lock = renderer.frame.locator(`[data-entity-id="${triage}"] .aw-meta .pk-value-change`) await expect(lock.locator('[data-change="removed"] .aw-lock')).toHaveText('Lock current') @@ -106,8 +106,8 @@ test('side by side, each pane draws its own revision without the diff’s signs, const renderer = await open(page, {comparison, mode: 'after'}) await layout(renderer) const card = renderer.frame.locator(`[data-entity-id="${bot}"]`) - await expect(card.locator('.aw-section[data-section="loads"] .pk-change-pill')).not.toContainText(['check-links']) - await expect(card.locator('.pk-pill-sign').first()).toBeHidden() + await expect(card.locator('.aw-section[data-section="loads"] .pk-chip')).not.toContainText(['check-links']) + await expect(card.locator('.pk-chip-sign').first()).toBeHidden() await renderer.seek(1, {highlighting: 0}) await expect(card.locator('.aw-direction')).toHaveCount(0) }) @@ -118,7 +118,7 @@ test('the default comparator still marks every entry, without directions', async await expect.poll(() => facts(renderer)).toEqual(['1 lock file out of date']) const card = renderer.frame.locator(`[data-entity-id="${bot}"]`) await expect(card.locator('.aw-direction')).toHaveCount(0) - await expect(card.locator('.pk-change-pill[data-change="added"]').first()).toBeVisible() + await expect(card.locator('.pk-chip[data-change="added"]').first()).toBeVisible() }) test('the matrix marks capabilities that arrive and leave, and selects a workflow from its row', async ({page}) => { diff --git a/packages/renderers/agentic-workflows/src/styles.css b/packages/renderers/agentic-workflows/src/styles.css index 2f29df8b1..9667f8900 100644 --- a/packages/renderers/agentic-workflows/src/styles.css +++ b/packages/renderers/agentic-workflows/src/styles.css @@ -28,7 +28,7 @@ color: var(--muted); } /* A side-by-side pane tints the entries that differ from the other revision, without the diff's signs. */ -.aw-view:not([data-side='diff']) .pk-pill-sign { +.aw-view:not([data-side='diff']) .pk-chip-sign { display: none; } /* An entry's words and code spans wrap as one run inside its pill. */ @@ -63,12 +63,12 @@ * In a pill the lock is the label: its words are one (`pk-label`), and its icon centres beside them, both on whole * pixels, so the pill's own label holds the lock's box rather than trimming a line around it. */ -.pk .pk-pill-label.pk-label:has(> .aw-lock) { +.pk .pk-chip-label.pk-label:has(> .aw-lock) { display: flex; text-box: none; padding-block: 0; } -.pk-pill-label > .aw-lock { +.pk-chip-label > .aw-lock { align-items: center; } .aw-lock:not([data-lock='current']) { diff --git a/packages/renderers/kit/react.css b/packages/renderers/kit/react.css index d30efecd0..f999f5889 100644 --- a/packages/renderers/kit/react.css +++ b/packages/renderers/kit/react.css @@ -9,6 +9,7 @@ @import './styles/generated.css'; @import './styles/graph.css'; @import './styles/diff.css'; +@import './styles/chips.css'; @import './styles/layout.css'; @import './styles/scope.css'; @import './styles/table.css'; diff --git a/packages/renderers/kit/src/react.ts b/packages/renderers/kit/src/react.ts index 04c933ba3..2674d62e6 100644 --- a/packages/renderers/kit/src/react.ts +++ b/packages/renderers/kit/src/react.ts @@ -18,6 +18,7 @@ export { usePaintHold, } from './react/shell/frame.js' export * from './react/components.js' +export * from './react/chip.js' export * from './react/status-tab.js' export * from './react/generated.js' export * from './react/diff-components.js' diff --git a/packages/renderers/kit/src/react/chip.tsx b/packages/renderers/kit/src/react/chip.tsx new file mode 100644 index 000000000..0b4531354 --- /dev/null +++ b/packages/renderers/kit/src/react/chip.tsx @@ -0,0 +1,159 @@ +// A chip: one small item as a pill (a category dot, a label, trailing content), its change painted, signed or said in a +// status tab under it, and `Chips`, a wrapping list of them that keeps room for those tabs. +import {Children, type ReactNode} from 'react' +import {identifier as identifierAttributes} from '@githubnext/projections-renderer-sdk/presentation' +import {statusLabels, type ChangeClassification} from '../emphasis.js' +import type {StatusChange} from '../svg-status.js' +import {toneAttributes, type Tone} from '../tone.js' +import {StatusTab} from './status-tab.js' + +const signs: Partial> = {added: '+', removed: '−', modified: '~', renamed: '~'} + +/** Props of `Chip`. */ +export interface ChipProps { + /** What the chip names. */ + label: ReactNode + /** `code` (the default) sets the label in the monospace font as an identifier; `text` keeps the UI font. */ + font?: 'code' | 'text' | undefined + /** The chip's own change. Unchanged (the default) draws it plain. */ + change?: ChangeClassification | undefined + /** + * Paints the change: the chip's edge and fill in its hue (the default). Turn it off for a chip that arrives or + * leaves with an item already marked around it, so change colors never nest; its sign and words still say it. + */ + paint?: boolean | undefined + /** Puts the change's sign (`+`, `−`, `~`) before the label, as a diff does. */ + sign?: boolean | undefined + /** + * How strongly the change is shown (`RendererProps.emphasis`), 0 to 1: the hue and the status tab fade with it. Left + * out, the chip follows the `--emphasis` of the item around it (fully shown when there is none). + */ + emphasis?: number | undefined + /** A status tab hanging under the chip (`StatusTab`), for its change in words; keep its room with ``. */ + status?: StatusChange | undefined + /** A category's color (a CSS color, such as a palette's color for the item's category), as a dot before the label. */ + dot?: string | undefined + /** How much the chip asks for attention apart from its change (`Tone`). */ + tone?: Tone | undefined + /** What follows the label: a count, a note. */ + children?: ReactNode + /** Makes the chip a button that selects this ID (`data-entity-id`), with `onSelect`. */ + id?: string | undefined + /** Whether the host has selected the chip's item (`RendererProps.selectedId`). */ + selected?: boolean | undefined + /** Selects the chip's item (`RendererProps.onSelect`). */ + onSelect?: ((id: string) => void) | undefined + /** + * Marks the chip as a ring unit of its own (`data-projections-unit`), for a chip that is an item. By default a + * selectable chip is a part (`pk-part`) of the unit around it. + */ + unit?: boolean | undefined + /** Extra words for assistive technology, after the label. */ + description?: string | undefined + /** More classes on the chip. */ + className?: string | undefined +} + +/** + * One small item as a pill: an optional category dot, its label (monospace by default) and trailing content, in a + * neutral edge. A changed chip is painted in its change's hue (fading with `emphasis`), struck through when removed, + * and can carry its sign and a status tab; assistive technology hears its change in words. With `id` and `onSelect` + * it is a button that selects the item. + */ +export function Chip({ + label, + font = 'code', + change = 'unchanged', + paint = true, + sign = false, + emphasis, + status, + dot, + tone, + children, + id, + selected = false, + onSelect, + unit = false, + description, + className, +}: ChipProps) { + const changed = change !== 'unchanged' + const painted = changed && paint + const classes = ['pk-chip', id !== undefined && !unit && 'pk-part', selected && 'selected', className].filter(Boolean).join(' ') + // The chip's own emphasis, else the item's around it. + const style: Record | undefined = emphasis === undefined ? undefined : {'--emphasis': emphasis} + const attributes = { + className: classes, + ...(painted ? {'data-change': change} : {}), + ...(changed ? {'data-chip-change': change} : {}), + ...(id !== undefined ? {'data-entity-id': id} : {}), + ...(unit ? {'data-projections-unit': ''} : {}), + style, + } + const content = ( + <> + {status && ( + + )} + + {dot !== undefined && + {status && } + + ) + if (id !== undefined && onSelect) { + return ( + + ) + } + return {content} +} + +/** + * Chips in a wrapping list, each a list item. `tabs` keeps a status tab's room under every line, so nothing moves + * when a chip's status appears. + */ +export function Chips({ + children, + label, + tabs = false, + className, +}: { + children: ReactNode + /** The list's accessible name. */ + label: string + tabs?: boolean | undefined + className?: string | undefined +}) { + return ( +
    + {Children.map(children, child => + child === null || child === undefined || child === false ? null :
  • {child}
  • , + )} +
+ ) +} diff --git a/packages/renderers/kit/src/react/diff-components.tsx b/packages/renderers/kit/src/react/diff-components.tsx index 46e2004c4..d2af9ae8d 100644 --- a/packages/renderers/kit/src/react/diff-components.tsx +++ b/packages/renderers/kit/src/react/diff-components.tsx @@ -1,5 +1,6 @@ import type {ReactNode} from 'react' import {identifier as identifierAttributes} from '@githubnext/projections-renderer-sdk/presentation' +import {Chip, Chips} from './chip.js' /** * A value that changed: the old one struck through in a removed pill, then @@ -56,17 +57,16 @@ export interface PillItem { key: string /** The pill's content. */ label: ReactNode - /** Added and removed pills carry a + or − sign and their hue; unchanged ones are plain. */ - change?: 'added' | 'removed' | 'unchanged' + /** Changed pills carry a sign (+, − or ~) and their hue; unchanged ones are plain. */ + change?: 'added' | 'removed' | 'modified' | 'unchanged' /** Makes the pill a selectable part (`data-entity-id`), activated with `onSelect`. */ entityId?: string } /** - * A list whose items arrive and leave, as pills: added ones with `+` in the - * added hue, removed ones with `−` struck through in the removed hue, and - * unchanged ones plain, for context. Each says its change to assistive - * technology. Pills with an `entityId` are buttons that select it. + * A list whose items arrive, leave or change, as chips (`Chip`): added ones with `+` in the added hue, removed ones + * with `−` struck through in the removed hue, modified ones with `~` in the modified hue, and unchanged ones plain, for + * context. Each says its change to assistive technology. Pills with an `entityId` are buttons that select it. */ export function ChangePills({ items, @@ -83,46 +83,18 @@ export function ChangePills({ className?: string }) { return ( -
    - {items.map(item => { - const change = item.change && item.change !== 'unchanged' ? item.change : undefined - const content = ( - <> - {change && ( - - )} - {change && {change === 'added' ? 'Added: ' : 'Removed: '}} - {item.label} - - ) - const selected = item.entityId !== undefined && selectedId === item.entityId - return ( -
  • - {item.entityId !== undefined && onSelect ? ( - - ) : ( - - {content} - - )} -
  • - ) - })} -
+ + {items.map(item => ( + + ))} + ) } diff --git a/packages/renderers/kit/styles/chips.css b/packages/renderers/kit/styles/chips.css new file mode 100644 index 000000000..84aedd1b3 --- /dev/null +++ b/packages/renderers/kit/styles/chips.css @@ -0,0 +1,122 @@ +/* + * Chips (`Chip`, `Chips`): a small item as a pill, the same metrics as a value pill. Its body is one line of labels + * (`pk-label`, so their capitals line up and centre): a category dot, a sign, the label and trailing content. A chip + * with a status tab reserves the tab's width in a zero-height row (`pk-chip-reserve`), so it is never narrower than + * its tab and keeps one width while the tab fades in and out. + */ +.pk-chips { + display: flex; + flex-wrap: wrap; + align-items: flex-start; + gap: var(--projections-space-1); + min-width: 0; + margin: 0; + padding: 0; + list-style: none; +} +/* Room for a tab under every line (``): under each line, and under the last. */ +.pk-chips[data-tabs] { + row-gap: calc(var(--pk-tab-height) + var(--projections-space-1)); + column-gap: var(--projections-space-2); + padding-bottom: var(--pk-tab-height); +} +.pk-chip-item { + display: contents; +} +.pk .pk-chip { + --pk-chip-radius: var(--projections-radius-sm); + appearance: none; + position: relative; + display: inline-flex; + flex-direction: column; + align-items: center; + max-width: 100%; + min-width: 0; + margin: 0; + padding: 0 var(--projections-label-padding-x); + border: var(--projections-border-width) solid var(--divider); + border-radius: var(--pk-chip-radius); + background: var(--raised); + color: var(--text); + font: inherit; + font-size: var(--projections-font-size-xs); + line-height: var(--projections-line-height); + text-align: left; + text-decoration: none; + overflow-wrap: anywhere; +} +.pk button.pk-chip { + cursor: pointer; +} +.pk .pk-chip[data-change] { + border-color: color-mix(in srgb, var(--pk-region-edge) calc(var(--emphasis, 1) * 100%), var(--divider)); + background: color-mix(in srgb, var(--pk-region-fill) calc(var(--emphasis, 1) * 100%), var(--raised)); +} +.pk-chip-body { + display: inline-flex; + align-items: center; + gap: 0.35em; + max-width: 100%; + min-width: 0; +} +.pk-chip-label { + min-width: 0; +} +/* A chip whose label is a value change (`ValueChange`) is framed by its two pills: it draws no frame of its own. */ +.pk .pk-chip:has(.pk-chip-label > .pk-value-change) { + padding: 0; + border-color: transparent; + background: transparent; +} +/* A label holding a value change holds its two pills, each centring its own text. */ +.pk .pk-chip-label.pk-label:has(> .pk-value-change) { + text-box: none; + padding-block: 0; +} +/* + * Removed: struck through and muted, painted or not, so removal never rests on color alone. Both fade with the + * chip's emphasis, so a removed chip at an endpoint reads plain. + */ +.pk .pk-chip[data-chip-change='removed'] .pk-chip-label { + color: color-mix(in srgb, var(--muted) calc(var(--emphasis, 1) * 100%), var(--text)); + text-decoration: line-through color-mix(in srgb, currentColor calc(var(--emphasis, 1) * 100%), transparent); +} +.pk-chip-sign { + flex: none; + font-family: var(--font-mono); + font-weight: var(--projections-font-weight-semibold); + color: color-mix(in srgb, var(--pk-change-ink) calc(var(--emphasis, 1) * 100%), var(--muted)); +} +/* No nested change colors: an unpainted chip, inside an item marked around it, says its change by its glyph alone. */ +.pk .pk-chip:not([data-change]) .pk-chip-sign { + color: var(--muted); +} +.pk-chip-dot { + flex: none; + width: 0.5rem; + height: 0.5rem; + border-radius: var(--projections-radius-full); +} +.pk-chip-trailing { + flex: none; + color: var(--muted); +} +.pk .pk-chip-reserve { + display: flex; + height: 0; + overflow: hidden; + visibility: hidden; + pointer-events: none; +} +.pk .pk-chip-reserve > .pk-status-tab-room { + position: static; + height: 0; +} +/* Selected: the part tint; the SDK's ring marks the chip's unit, so the chip draws no ring of its own. */ +.pk .pk-chip.pk-part.selected { + background-image: linear-gradient(var(--pk-part-tint), var(--pk-part-tint)); +} +.pk .pk-chip:focus-visible { + outline: var(--projections-focus-ring-width) solid var(--focus); + outline-offset: var(--projections-focus-ring-offset); +} diff --git a/packages/renderers/kit/styles/diff.css b/packages/renderers/kit/styles/diff.css index 7d95add90..861e5a930 100644 --- a/packages/renderers/kit/styles/diff.css +++ b/packages/renderers/kit/styles/diff.css @@ -25,7 +25,7 @@ /* * Change pills: an old value struck through in the removed hue above (or before) the new one in the added hue - * (`ValueChange`), and lists whose items arrive and leave (`ChangePills`). Data is shown verbatim. + * (`ValueChange`). Lists whose items arrive and leave (`ChangePills`) are chips (`chips.css`). Data is shown verbatim. */ .pk-value-change { display: inline-flex; @@ -44,18 +44,6 @@ .pk-value-arrow { color: var(--muted); } -.pk-change-pills { - display: flex; - flex-wrap: wrap; - gap: var(--projections-space-1); - min-width: 0; - margin: 0; - padding: 0; - list-style: none; -} -.pk-change-pill-item { - display: contents; -} .pk .pk-change-pill { appearance: none; display: inline-flex; @@ -76,42 +64,13 @@ text-decoration: none; overflow-wrap: anywhere; } -/* A pill whose label is a value change (`ValueChange`) is framed by its two pills: it draws no frame of its own around them. */ -.pk .pk-change-pill:has(> .pk-pill-label > .pk-value-change) { - padding: 0; - border-color: transparent; - background: transparent; -} -/* A label holding a value change holds its two pills, each centring its own text. */ -.pk .pk-pill-label.pk-label:has(> .pk-value-change) { - text-box: none; - padding-block: 0; -} -.pk button.pk-change-pill { - cursor: pointer; -} .pk .pk-change-pill[data-change] { border-color: color-mix(in srgb, var(--pk-region-edge) calc(var(--emphasis, 1) * 100%), var(--divider)); background: color-mix(in srgb, var(--pk-region-fill) calc(var(--emphasis, 1) * 100%), var(--raised)); } -.pk .pk-change-pill[data-change='removed'] :is(.pk-pill-label), .pk del.pk-change-pill { text-decoration: line-through; } -.pk-pill-sign { - flex: none; - font-family: var(--font-mono); - font-weight: var(--projections-font-weight-semibold); - color: color-mix(in srgb, var(--pk-change-ink) calc(var(--emphasis, 1) * 100%), var(--muted)); -} -/* Selected: the part tint; the SDK's ring marks the pill's unit, so the pill draws no ring of its own. */ -.pk .pk-change-pill.selected { - background-image: linear-gradient(var(--pk-part-tint), var(--pk-part-tint)); -} -.pk .pk-change-pill:focus-visible { - outline: var(--projections-focus-ring-width) solid var(--focus); - outline-offset: var(--projections-focus-ring-offset); -} /* `SvgValueChange`: old struck in the removed hue, an arrow, then the new value in the added hue. */ .pk-svg-was { diff --git a/packages/renderers/kit/styles/regions.css b/packages/renderers/kit/styles/regions.css index 81fdf9707..200e870b7 100644 --- a/packages/renderers/kit/styles/regions.css +++ b/packages/renderers/kit/styles/regions.css @@ -145,7 +145,7 @@ * tab hands back a neutral corner and edge rather than leaving the pill open. */ .pk :has(> .pk-status-tab-room > .pk-status-tab) { - --pk-tab-corner: calc(var(--projections-radius) * (1 - var(--emphasis, 1))); + --pk-tab-corner: calc(var(--pk-chip-radius, var(--projections-radius)) * (1 - var(--emphasis, 1))); border-end-start-radius: var(--pk-tab-corner); } .pk :has(> .pk-status-tab-room[data-flush] > .pk-status-tab) { diff --git a/packages/renderers/kit/test/chip.test.mjs b/packages/renderers/kit/test/chip.test.mjs new file mode 100644 index 000000000..bcd0fb600 --- /dev/null +++ b/packages/renderers/kit/test/chip.test.mjs @@ -0,0 +1,74 @@ +import {test} from 'node:test' +import assert from 'node:assert/strict' +import {readFileSync} from 'node:fs' +import {createElement} from 'react' +import {renderToStaticMarkup} from 'react-dom/server' +import {Chip, Chips} from '../dist/react.js' +import {plain} from './markup.mjs' + +const html = element => renderToStaticMarkup(element) +const chip = props => html(createElement(Chip, props)) + +test('a chip is a dot, a monospace label and trailing content, in that order', () => { + const markup = chip({label: 'bash', dot: 'var(--projections-chart-1)', children: '×3', tone: 'quiet'}) + assert.match( + markup, + /^