From 302883e3ee067829e87b0b415b060afcb87615c0 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Wed, 2 Dec 2026 12:05:59 -0800 Subject: [PATCH 1/2] kit: Facts and ValueList, an item's facts as quiet text with changes marked inline Facts and Fact are a key-value list with human labels in the UI font, muted, in a column of their own, with a meta note beside a value and a change for a row that arrives or leaves. ValueList draws a list of values as text, each changed item marked inline in its hue with its sign, struck through when it leaves, rather than every item in a pill. ValueChange takes variant="text". Fields is Facts with code labels. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- changelog.d/facts-value-list.md | 5 + docs/agents/create-projection.md | 5 +- docs/guides/renderer-kit-components.md | 16 +- docs/reference/renderer-kit.md | 68 +++++- packages/cli/templates/SKILL.md | 5 +- packages/renderers/kit/react.css | 1 + packages/renderers/kit/src/react.ts | 1 + .../kit/src/react/diff-components.tsx | 41 +++- packages/renderers/kit/src/react/facts.tsx | 216 ++++++++++++++++++ .../kit/src/react/layout-components.tsx | 13 +- packages/renderers/kit/styles/facts.css | 111 +++++++++ packages/renderers/kit/test/facts.test.mjs | 78 +++++++ 12 files changed, 548 insertions(+), 12 deletions(-) create mode 100644 changelog.d/facts-value-list.md create mode 100644 packages/renderers/kit/src/react/facts.tsx create mode 100644 packages/renderers/kit/styles/facts.css create mode 100644 packages/renderers/kit/test/facts.test.mjs diff --git a/changelog.d/facts-value-list.md b/changelog.d/facts-value-list.md new file mode 100644 index 000000000..f36bfa3fd --- /dev/null +++ b/changelog.d/facts-value-list.md @@ -0,0 +1,5 @@ +--- +section: kit +--- + +- **`Facts` and `ValueList` render key-value and value lists as plain text**. `Facts` and `Fact` display key-value pairs with muted UI-font labels ("Runs on") in an aligned column; `meta` puts a note ("and 8 run steps") beside a value, and `change` marks an added or removed row. `ValueList` renders comma-separated or stacked values as text, marking added, removed, and changed items inline with change hues, signs, and strikethrough instead of wrapping each item in a pill like `ChangePills`. `ValueChange` accepts `variant="text"` for a single value change in the same style, and `Fields` is now `Facts` with code labels. See [Layout components](docs/guides/renderer-kit-components.md#layout-components). diff --git a/docs/agents/create-projection.md b/docs/agents/create-projection.md index 9a31fdc11..ea2287220 100644 --- a/docs/agents/create-projection.md +++ b/docs/agents/create-projection.md @@ -570,8 +570,9 @@ is its framework-free half, `/kit/react` its React components and hooks, and `/kit/react.css` their styles. Use it rather than your own markup and CSS: the kit already meets the checks the host holds every renderer to. The starter has no stylesheet: compose views from the kit's components (`ContentView`, `Group`, -`CardGrid`, `EntityCard`, `Fields`, `Stack`, `Inline`, `Text`, `Chip`, `Chips`) -and their props, +`CardGrid`, `EntityCard`, `Facts`, `ValueList`, `Fields`, `Stack`, `Inline`, +`Text`, `Chip`, `Chips`) and their props (`Facts` for properties and settings, +`ValueList` for value lists with inline change marks instead of pills), and for an inline style they don't cover use `token` (`token.space(2)`). For items with comparable properties (a row per item, a column per property), use the kit's `DataTable` rather than hand-built table markup: sortable headings diff --git a/docs/guides/renderer-kit-components.md b/docs/guides/renderer-kit-components.md index 5eae4ce9f..75dbdbae3 100644 --- a/docs/guides/renderer-kit-components.md +++ b/docs/guides/renderer-kit-components.md @@ -316,7 +316,21 @@ accept token scale steps rather than raw lengths or colors—this is how - `RelationshipList` and `RelationshipItem` list a card's relationships, each a selectable unit with its own ID, `presence`, and (in diff mode) `mark` and `changeText`. -- `Fields` and `Field` display name-value pairs with identifier-styled names. +- `Facts` and `Fact` render a key-value list with muted UI-font labels ("Runs + on") in an aligned column. `meta` adds a muted note after a value ("and 8 run + steps") instead of a separate row, and `change` marks an added or removed row. + `Fields` and `Field` are the same list with `labelFont="code"` for raw data + keys. +- `ValueList` renders a list of values as text, separated by commas (or + `separator="dot"`) and wrapping between items, or stacked one per line + (`layout="stack"`). Added items appear in the added hue after `+`, removed + items are struck through in the removed hue after `−`, and changed items show + the old value (`was`) struck through, an arrow, and the new value. Marks fade + with `emphasis` (inheriting the surrounding item's when omitted) and are + announced in words. Items are unboxed by default; `display="chips"` renders + them as chips (`ChangePills`) for small or selectable sets. + `ValueChange variant="text"` renders a single value change the same way, + without pills. - `Stack` and `Inline` arrange children in a vertical column or wrapping row with `gap={1…8}` steps from the spacing scale. - `Text` renders typography using `size` (`xs`, `sm`, `md`, `lg`, `xl`), diff --git a/docs/reference/renderer-kit.md b/docs/reference/renderer-kit.md index eaae6056e..ef06949c7 100644 --- a/docs/reference/renderer-kit.md +++ b/docs/reference/renderer-kit.md @@ -4227,6 +4227,26 @@ Props of `EntityCard`: one entity's card, its selection and its change. | `presence` | `"presence"?: number` | Presence 0..1 while an entity is added or removed by the playing step (`timeline.presence`); 1 by default. | | `selected` | `"selected": false \| true` | Whether the entity is the host's selection (`props.selectedId === id`): the card's button is pressed. | +### `Fact` + +```ts +Fact(__0: { "change"?: "added" | "modified" | "removed" | "renamed" | "unchanged"; "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; "emphasis"?: number; "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; "meta"?: 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 }): Element +``` + +One row of `Facts`: its label, its value and, optionally, a muted note after the value (`meta`: "and 8 run steps"), +so a count or a note sits beside a label rather than alone on a line. A row that arrives or leaves as a whole takes +`change`: its label is marked in the change's hue, struck through when it leaves, and said in words. + +### `Facts` + +```ts +Facts(__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; "label"?: string; "labelFont"?: "code" | "text" }): Element +``` + +A key-value list: each row a label in the UI font, muted, and its value, the labels in one column so every value +starts at the same place. Use it for an item's facts and settings, rather than pills; `labelFont="code"` is for +labels that are data keys (`Fields` is that). + ### `Field` ```ts @@ -4241,7 +4261,8 @@ One row of `Fields`: the name is a code name, in the monospace font. Fields(__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 }): Element ``` -Name and value rows, such as an entity's data. +Name and value rows whose names are data keys, such as an entity's raw `data`: `Facts` with code labels. For human +labels ("Runs on"), use `Facts` and `Fact`. ### `Fold` @@ -5140,14 +5161,55 @@ and set it. Spread them: ` | 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; "before"?: 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; "code"?: false | true; "layout"?: "inline" | "stacked" }): Element +ValueChange(__0: { "after"?: 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; "before"?: 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; "code"?: false | true; "layout"?: "inline" | "stacked"; "variant"?: "pills" | "text" }): Element ``` A value that changed: the old one struck through in a removed pill, then the new one in an added pill, stacked (the default) or on one line with an arrow. Assistive technology reads "was …, now …". A missing side shows only the other pill. `code` marks the values as identifiers (a type, a -version), in the monospace font. +version), in the monospace font. `variant="text"` draws the same change as +text, with no pills: the old value struck through in the removed hue, an +arrow, then the new one in the added hue (always on one line); use it in +key-value lists and running text, where pills would be loud. + +### `ValueItem` + +```ts +interface ValueItem +``` + +One item of a `ValueList`. + +| Member | Signature | Description | +|---|---|---| +| `change` | `"change"?: "added" \| "modified" \| "removed" \| "renamed" \| "unchanged" \| undefined` | The item's own change. Unchanged (the default) draws it plain. | +| `entityId` | `"entityId"?: string \| undefined` | Makes the item a selectable part (`data-entity-id`), with the list's `onSelect`. | +| `key` | `"key": string` | React key: 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` | What the item says: its value now (or, removed, its last value). | +| `was` | `"was"?: 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` | A modified item's previous value: drawn struck through before `label`, with an arrow (`ValueChange variant="text"`). | + +### `ValueList` + +```ts +ValueList(__0: { "className"?: string; "code"?: false | true; "display"?: "chips" | "text"; "emphasis"?: number; "items": Array; "label": string; "layout"?: "inline" | "stack"; "onSelect"?: undefined | { (id: string): void }; "selectedId"?: null | string | undefined; "separator"?: "comma" | "dot" | "none"; "sign"?: false | true }): Element +``` + +A list of values whose items may arrive, leave or change, as text: comma-separated on a line by default, or one per +line (`layout="stack"`). An arrived item is in the added hue after a `+`, a removed one struck through in the removed +hue after a `−`, and a modified one its old value struck through, an arrow, then its new one; each fades with +`emphasis` (left out, the `--emphasis` of the item around it) and is said in words. No item is boxed: for a few +items a reader picks out or selects, such as tools or services, `display="chips"` draws them as chips instead +(`ChangePills`). + +### `ValueText` + +```ts +ValueText(__0: { "after"?: 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; "before"?: 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 }): Element +``` + +A value that changed in place, as text: the old one struck through in the removed hue, an arrow, then the new one +in the added hue, with no pills. `ValueChange variant="text"` is this. ### `VariedMarker` diff --git a/packages/cli/templates/SKILL.md b/packages/cli/templates/SKILL.md index 66f6028e6..6a8c02932 100644 --- a/packages/cli/templates/SKILL.md +++ b/packages/cli/templates/SKILL.md @@ -535,8 +535,9 @@ is its framework-free half, `/kit/react` its React components and hooks, and `/kit/react.css` their styles. Use it rather than your own markup and CSS: the kit already meets the checks the host holds every renderer to. The starter has no stylesheet: compose views from the kit's components (`ContentView`, `Group`, -`CardGrid`, `EntityCard`, `Fields`, `Stack`, `Inline`, `Text`, `Chip`, `Chips`) -and their props, +`CardGrid`, `EntityCard`, `Facts`, `ValueList`, `Fields`, `Stack`, `Inline`, +`Text`, `Chip`, `Chips`) and their props (`Facts` for properties and settings, +`ValueList` for value lists with inline change marks instead of pills), and for an inline style they don't cover use `token` (`token.space(2)`). For items with comparable properties (a row per item, a column per property), use the kit's `DataTable` rather than hand-built table markup: sortable headings diff --git a/packages/renderers/kit/react.css b/packages/renderers/kit/react.css index f999f5889..e9a64af31 100644 --- a/packages/renderers/kit/react.css +++ b/packages/renderers/kit/react.css @@ -10,6 +10,7 @@ @import './styles/graph.css'; @import './styles/diff.css'; @import './styles/chips.css'; +@import './styles/facts.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 beba11a8e..4c7b940c3 100644 --- a/packages/renderers/kit/src/react.ts +++ b/packages/renderers/kit/src/react.ts @@ -24,6 +24,7 @@ export * from './react/chip.js' export * from './react/status-tab.js' export * from './react/generated.js' export * from './react/diff-components.js' +export * from './react/facts.js' export * from './react/icons.js' export {Fold, useFolds} from './react/fold.js' export {IdentifierText} from './react/identifiers.js' diff --git a/packages/renderers/kit/src/react/diff-components.tsx b/packages/renderers/kit/src/react/diff-components.tsx index d2af9ae8d..6372b7e7f 100644 --- a/packages/renderers/kit/src/react/diff-components.tsx +++ b/packages/renderers/kit/src/react/diff-components.tsx @@ -7,23 +7,33 @@ import {Chip, Chips} from './chip.js' * the new one in an added pill, stacked (the default) or on one line with an * arrow. Assistive technology reads "was …, now …". A missing side shows * only the other pill. `code` marks the values as identifiers (a type, a - * version), in the monospace font. + * version), in the monospace font. `variant="text"` draws the same change as + * text, with no pills: the old value struck through in the removed hue, an + * arrow, then the new one in the added hue (always on one line); use it in + * key-value lists and running text, where pills would be loud. */ export function ValueChange({ before, after, layout = 'stacked', code = false, + variant = 'pills', className, }: { before?: ReactNode after?: ReactNode layout?: 'stacked' | 'inline' code?: boolean + /** `pills` (the default): each side in its own pill; `text`: plain text in the change hues. */ + variant?: 'pills' | 'text' className?: string }) { const has = (value: ReactNode) => value !== undefined && value !== null && value !== false const label = code ? identifierAttributes : {} + if (variant === 'text') { + const text = (value: ReactNode) => (has(value) ? {value} : undefined) + return + } return ( {has(before) && ( @@ -128,3 +138,32 @@ export function SvgValueChange({ ) } + +/** + * A value that changed in place, as text: the old one struck through in the removed hue, an arrow, then the new one + * in the added hue, with no pills. `ValueChange variant="text"` is this. + */ +export function ValueText({before, after}: {before?: ReactNode; after?: ReactNode}) { + const has = (value: ReactNode) => value !== undefined && value !== null && value !== false + return ( + + {has(before) && ( + + was + {before} + + )} + {has(before) && has(after) && ( + + )} + {has(after) && ( + + {has(before) ? ', now ' : 'now '} + {after} + + )} + + ) +} diff --git a/packages/renderers/kit/src/react/facts.tsx b/packages/renderers/kit/src/react/facts.tsx new file mode 100644 index 000000000..cbed552dc --- /dev/null +++ b/packages/renderers/kit/src/react/facts.tsx @@ -0,0 +1,216 @@ +// Quiet text for a card's facts: a key-value list with human labels (`Facts`, `Fact`), and a list of values whose items +// arrive, leave or change, marked inline in their change's hue rather than each drawn as a pill (`ValueList`). +import type {ReactNode} from 'react' +import {identifier as identifierAttributes} from '@githubnext/projections-renderer-sdk/presentation' +import {statusLabels, type ChangeClassification} from '../emphasis.js' +import {ChangePills, ValueText} from './diff-components.js' + +const signs: Partial> = {added: '+', removed: '−', modified: '~', renamed: '~'} + +const emphasisStyle = (emphasis: number | undefined) => + emphasis === undefined ? undefined : ({'--emphasis': emphasis} as Record) + +/** + * A key-value list: each row a label in the UI font, muted, and its value, the labels in one column so every value + * starts at the same place. Use it for an item's facts and settings, rather than pills; `labelFont="code"` is for + * labels that are data keys (`Fields` is that). + */ +export function Facts({ + children, + labelFont = 'text', + label, + className, +}: { + children: ReactNode + /** `text` (the default) for human labels ("Runs on"); `code` for data keys (`timeoutMinutes`), in monospace. */ + labelFont?: 'text' | 'code' + /** The list's accessible name, when its context doesn't give one. */ + label?: string + className?: string +}) { + return ( +
+ {children} +
+ ) +} + +/** + * One row of `Facts`: its label, its value and, optionally, a muted note after the value (`meta`: "and 8 run steps"), + * so a count or a note sits beside a label rather than alone on a line. A row that arrives or leaves as a whole takes + * `change`: its label is marked in the change's hue, struck through when it leaves, and said in words. + */ +export function Fact({ + label, + children, + meta, + change = 'unchanged', + emphasis, +}: { + label: ReactNode + children?: ReactNode + meta?: ReactNode + change?: ChangeClassification + /** How strongly `change` shows, 0 to 1; left out, the row follows the `--emphasis` of the item around it. */ + emphasis?: number +}) { + const changed = change !== 'unchanged' + const Label = change === 'removed' ? 'del' : change === 'added' ? 'ins' : 'span' + return ( +
+
+ {changed ? ( + + ) : ( + label + )} +
+
+ {changed ? ( + + ) : ( + children + )} + {meta !== undefined && meta !== null && meta !== false && {meta}} +
+
+ ) +} + +/** One item of a `ValueList`. */ +export interface ValueItem { + /** React key: unique within the list and stable across renders. */ + key: string + /** What the item says: its value now (or, removed, its last value). */ + label: ReactNode + /** The item's own change. Unchanged (the default) draws it plain. */ + change?: ChangeClassification | undefined + /** A modified item's previous value: drawn struck through before `label`, with an arrow (`ValueChange variant="text"`). */ + was?: ReactNode + /** Makes the item a selectable part (`data-entity-id`), with the list's `onSelect`. */ + entityId?: string | undefined +} + +/** + * A list of values whose items may arrive, leave or change, as text: comma-separated on a line by default, or one per + * line (`layout="stack"`). An arrived item is in the added hue after a `+`, a removed one struck through in the removed + * hue after a `−`, and a modified one its old value struck through, an arrow, then its new one; each fades with + * `emphasis` (left out, the `--emphasis` of the item around it) and is said in words. No item is boxed: for a few + * items a reader picks out or selects, such as tools or services, `display="chips"` draws them as chips instead + * (`ChangePills`). + */ +export function ValueList({ + items, + label, + layout = 'inline', + separator = 'comma', + code = false, + sign = true, + display = 'text', + emphasis, + onSelect, + selectedId, + className, +}: { + items: readonly ValueItem[] + /** The list's accessible name. */ + label: string + /** `inline` (the default): items on a line that wraps between them; `stack`: one per line. */ + layout?: 'inline' | 'stack' + /** Between inline items: `comma` (the default), `dot` (a middle dot, for short tokens) or `none`. */ + separator?: 'comma' | 'dot' | 'none' + /** Sets every item as code (an identifier, a version, a path), in the monospace font. */ + code?: boolean + /** Puts each changed item's sign (`+`, `−`, `~`) before it, as a diff does (the default). */ + sign?: boolean + /** `text` (the default), or `chips` for a few items a reader picks out or selects. */ + display?: 'text' | 'chips' + /** How strongly changes show, 0 to 1; left out, the list follows the `--emphasis` of the item around it. */ + emphasis?: number + onSelect?: ((id: string) => void) | undefined + selectedId?: string | null | undefined + className?: string +}) { + if (display === 'chips') { + return ( + ({ + key: item.key, + label: item.label, + change: item.change === 'renamed' ? 'modified' : (item.change ?? 'unchanged'), + ...(item.entityId !== undefined ? {entityId: item.entityId} : {}), + }))} + label={label} + onSelect={onSelect} + selectedId={selectedId} + {...(className !== undefined ? {className} : {})} + /> + ) + } + const text = (content: ReactNode) => (code ? {content} : content) + return ( +
    + {items.map(item => { + const change = item.change ?? 'unchanged' + const id = item.entityId + const value = + change === 'modified' && item.was !== undefined ? ( + + ) : change === 'unchanged' ? ( + text(item.label) + ) : ( + + {text(item.label)} + + ) + return ( +
  • + {id !== undefined && onSelect ? ( + + ) : ( + value + )} +
  • + ) + })} +
+ ) +} + +/** A value marked with its own change, inline: its hue on the text, its sign before it, struck through when it leaves. */ +function Marked({change, sign, children}: {change: ChangeClassification; sign: boolean; children: ReactNode}) { + const Tag = change === 'removed' ? 'del' : change === 'added' ? 'ins' : 'span' + return ( + + {statusLabels[change]}: + {sign && signs[change] && ( + + )} + {children} + + ) +} diff --git a/packages/renderers/kit/src/react/layout-components.tsx b/packages/renderers/kit/src/react/layout-components.tsx index 8dd016e94..e9d7fea40 100644 --- a/packages/renderers/kit/src/react/layout-components.tsx +++ b/packages/renderers/kit/src/react/layout-components.tsx @@ -285,15 +285,22 @@ export function RelationshipItem({ ) } -/** Name and value rows, such as an entity's data. */ +/** + * Name and value rows whose names are data keys, such as an entity's raw `data`: `Facts` with code labels. For human + * labels ("Runs on"), use `Facts` and `Fact`. + */ export function Fields({children}: {children: ReactNode}) { - return
{children}
+ return ( +
+ {children} +
+ ) } /** One row of `Fields`: the name is a code name, in the monospace font. */ export function Field({name, children}: {name: string; children: ReactNode}) { return ( -
+
{name}
diff --git a/packages/renderers/kit/styles/facts.css b/packages/renderers/kit/styles/facts.css new file mode 100644 index 000000000..8cb9facf5 --- /dev/null +++ b/packages/renderers/kit/styles/facts.css @@ -0,0 +1,111 @@ +/* + * Facts (`Facts`, `Fact`, and `Fields` on the same rules): a key-value list, the labels muted in a column of their own + * so every value starts at the same place, each row on one baseline. Value lists (`ValueList`) and text value changes + * (`ValueChange variant="text"`): values as text, a changed one marked inline in its change's hue (`--pk-change-ink`) + * with its sign, struck through when it leaves, all fading with `--emphasis` so a change at an endpoint reads plain. No + * value is boxed. + */ +.pk .pk-facts { + display: grid; + grid-template-columns: max-content minmax(0, 1fr); + gap: var(--projections-space-1) var(--projections-space-3); + align-items: baseline; + margin: 0; + padding: 0; +} +.pk .pk-fact { + display: contents; +} +.pk .pk-fact > dt { + color: var(--muted); +} +.pk .pk-facts[data-label-font='code'] > .pk-fact > dt { + font-family: var(--font-mono); +} +.pk .pk-fact > dd { + min-width: 0; + margin: 0; + overflow-wrap: anywhere; +} +.pk .pk-fact-meta { + display: inline-block; + color: var(--muted); +} +.pk .pk-fact-meta:not(:first-child) { + margin-inline-start: var(--projections-space-1); +} + +.pk .pk-value-list { + display: inline; + margin: 0; + padding: 0; + list-style: none; + overflow-wrap: anywhere; +} +.pk .pk-value-item { + /* Each item stays whole where it fits, so a line breaks between items rather than inside one. */ + display: inline-block; + max-width: 100%; +} +.pk .pk-value-list:not([data-layout='stack']) > .pk-value-item:not(:last-child) { + margin-inline-end: var(--projections-space-1); +} +.pk .pk-value-list[data-separator='comma'] > .pk-value-item:not(:last-child)::after { + content: ','; + color: var(--muted); +} +.pk .pk-value-list[data-separator='dot'] > .pk-value-item:not(:last-child)::after { + content: ' ·'; + color: var(--muted); +} +.pk .pk-value-list[data-separator='none'] > .pk-value-item:not(:last-child) { + margin-inline-end: var(--projections-space-2); +} +.pk .pk-value-list[data-layout='stack'] { + display: flex; + flex-direction: column; + align-items: flex-start; +} +.pk .pk-value-list[data-layout='stack'] > .pk-value-item { + display: block; + max-width: 100%; +} + +.pk .pk-value-mark { + color: color-mix(in srgb, var(--pk-change-ink) calc(var(--emphasis, 1) * 100%), currentcolor); + text-decoration: none; +} +.pk del.pk-value-mark { + text-decoration: line-through; + text-decoration-color: color-mix(in srgb, currentcolor calc(var(--emphasis, 1) * 100%), transparent); +} +.pk .pk-value-sign { + margin-inline-end: 2px; + font-family: var(--font-mono); + font-weight: var(--projections-font-weight-semibold); + opacity: var(--emphasis, 1); +} +.pk .pk-value-change[data-variant='text'] { + display: inline; +} +.pk .pk-value-change[data-variant='text'] > .pk-value-arrow { + margin-inline: var(--projections-space-1); +} + +/* A selectable value: a part of the unit around it (`pk-part`), plain text that underlines on hover. */ +.pk .pk-value-select { + appearance: none; + margin: 0; + padding: 0; + border: 0; + background: none; + color: inherit; + font: inherit; + text-align: inherit; + cursor: pointer; +} +.pk .pk-value-select:hover { + text-decoration: underline; + text-decoration-color: var(--subtle); + text-underline-offset: 0.2em; +} diff --git a/packages/renderers/kit/test/facts.test.mjs b/packages/renderers/kit/test/facts.test.mjs new file mode 100644 index 000000000..cd04faf43 --- /dev/null +++ b/packages/renderers/kit/test/facts.test.mjs @@ -0,0 +1,78 @@ +import {test} from 'node:test' +import assert from 'node:assert/strict' +import {createElement} from 'react' +import {renderToStaticMarkup} from 'react-dom/server' +import {Fact, Facts, Field, Fields, ValueChange, ValueList} from '../dist/react.js' +import {plain} from './markup.mjs' + +const html = element => renderToStaticMarkup(element) + +test('facts are human labels in the UI font, each with its value and an optional note beside it', () => { + const markup = html(createElement(Facts, null, createElement(Fact, {label: 'Steps', meta: 'and 8 run steps'}, 'actions/checkout@v5'))) + assert.match(markup, /^
Steps<\/dt>
/u) + assert.doesNotMatch(markup, /data-projections-identifier/u) + assert.match(markup, /and 8 run steps<\/span><\/dd>/u) + // Raw data keys keep their code names, on the same rules. + assert.match( + html(createElement(Fields, null, createElement(Field, {name: 'timeoutMinutes'}, '40'))), + /class="pk-fields pk-facts" data-label-font="code"/u, + ) +}) + +test('a fact that leaves is struck through and said', () => { + const markup = html(createElement(Fact, {label: 'Container', change: 'removed', emphasis: 0.5}, 'node:22')) + assert.match(markup, /
/u) + assert.match(markup, /
node:22<\/del><\/dd>/u) + assert.equal(plain(markup), 'Removed: Containernode:22') +}) + +test('a value list is text: changed items marked inline with their sign, none boxed', () => { + const markup = html( + createElement(ValueList, { + label: 'Steps', + code: true, + items: [ + {key: 'a', label: 'checkout@v5'}, + {key: 'b', label: 'setup-node@v5', change: 'added'}, + {key: 'c', label: 'cache@v3', change: 'removed'}, + {key: 'd', label: 'upload@v4', was: 'upload@v3', change: 'modified'}, + ], + }), + ) + assert.match(markup, /^
    /u) + assert.doesNotMatch(markup, /pk-chip|pk-change-pill/u) + assert.match( + markup, + /Added: <\/span>
) @@ -102,7 +109,7 @@ export interface ValueItem { * hue after a `−`, and a modified one its old value struck through, an arrow, then its new one; each fades with * `emphasis` (left out, the `--emphasis` of the item around it) and is said in words. No item is boxed: for a few * items a reader picks out or selects, such as tools or services, `display="chips"` draws them as chips instead - * (`ChangePills`). + * (`ChangePills`), keeping each item's change, sign, previous value and code font. */ export function ValueList({ items, @@ -137,19 +144,31 @@ export function ValueList({ className?: string }) { if (display === 'chips') { + // Chips wrap in a row, so `layout` and `separator` don't apply; everything else does. return ( - ({ - key: item.key, - label: item.label, - change: item.change === 'renamed' ? 'modified' : (item.change ?? 'unchanged'), - ...(item.entityId !== undefined ? {entityId: item.entityId} : {}), - }))} - label={label} - onSelect={onSelect} - selectedId={selectedId} - {...(className !== undefined ? {className} : {})} - /> + + {items.map(item => { + const change = item.change ?? 'unchanged' + const id = item.entityId + return ( + + ) : ( + item.label + ) + } + font={code ? 'code' : 'text'} + change={change} + sign={sign} + {...(emphasis !== undefined ? {emphasis} : {})} + {...(id !== undefined && onSelect ? {id, onSelect, selected: selectedId === id} : {})} + /> + ) + })} + ) } const text = (content: ReactNode) => (code ? {content} : content) @@ -170,9 +189,9 @@ export function ValueList({ ) : change === 'unchanged' ? ( text(item.label) ) : ( - + {text(item.label)} - + ) return (
  • @@ -199,11 +218,26 @@ export function ValueList({ ) } -/** A value marked with its own change, inline: its hue on the text, its sign before it, struck through when it leaves. */ -function Marked({change, sign, children}: {change: ChangeClassification; sign: boolean; children: ReactNode}) { +/** + * One value marked with its own change, inline, as `ValueList` marks its items: its change's hue on the text, its sign + * before it (`sign`), struck through when it leaves, said in words, fading with `emphasis` (or the item's around it). + * Unchanged, it is the value alone. + */ +export function ValueMark({ + change = 'unchanged', + sign = true, + emphasis, + children, +}: { + change?: ChangeClassification + sign?: boolean + emphasis?: number + children: ReactNode +}) { + if (change === 'unchanged') return <>{children} const Tag = change === 'removed' ? 'del' : change === 'added' ? 'ins' : 'span' return ( - + {statusLabels[change]}: {sign && signs[change] && (