From c2e6ab721742ad9e8eacf2d296a5980627cc9c82 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Mon, 30 Nov 2026 21:22:56 -0800 Subject: [PATCH 1/4] Kit: add tones, quiet and flag, for domain meaning that isn't a change A tone says how much an item asks for attention apart from its change: quiet mutes a lesser item's text, flag sets a domain flag's text semibold in the full foreground. Neither uses a change hue, a dash or opacity. Text and DataTable rows take a tone; toneAttributes sets data-projections-tone on anything else. A table cell carries each version's tone, so its reserved width holds. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/guides/renderer-kit-components.md | 28 +++++++++- docs/reference/renderer-kit.md | 35 ++++++++++++- packages/renderers/kit/src/index.ts | 1 + .../kit/src/react/data-table-row.tsx | 17 +++++-- .../renderers/kit/src/react/data-table.tsx | 8 +++ .../kit/src/react/layout-components.tsx | 17 +++++-- packages/renderers/kit/src/tone.ts | 18 +++++++ packages/renderers/kit/styles/text.css | 21 ++++++++ packages/renderers/kit/test/tone.test.mjs | 51 +++++++++++++++++++ 9 files changed, 185 insertions(+), 11 deletions(-) create mode 100644 packages/renderers/kit/src/tone.ts create mode 100644 packages/renderers/kit/test/tone.test.mjs diff --git a/docs/guides/renderer-kit-components.md b/docs/guides/renderer-kit-components.md index 4f12f6355..e6387008d 100644 --- a/docs/guides/renderer-kit-components.md +++ b/docs/guides/renderer-kit-components.md @@ -309,7 +309,30 @@ accept token scale steps rather than raw lengths or colors—this is how - `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`), - `weight`, and `tone` (`default`, `muted`, `subtle`). + `weight`, and `tone` (`default`, `muted`, `subtle`, or one of the kit's tones, + `quiet` and `flag`; see [Tones](#tones)). + +## Tones + +A tone says how much an item asks for attention, apart from its change. Use it +for domain meaning that isn't a change between revisions: + +- `quiet` is a lesser item: a tool that only reads, a cost known only in part. + Its text is muted. +- `flag` is a domain flag that isn't a change: a write, a privileged permission, + a policy exception. Its text is the full foreground at semibold weight. +- `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 +`@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 +marking still wins: a value change or a removed item's struck-through text keeps +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. ## Data tables @@ -344,7 +367,8 @@ export function View(props: RendererProps) { `changed(before, after)` returns true. - **Rows** — Pass `model.entities` or any compatible `TableRow` list (`id`, `before`, `after`, `status`). Each row is a ring unit with `data-entity-id`, - and its first cell serves as the select button. + and its first cell serves as the select button. `tone(item)` gives a row a + [tone](#tones) from the version it shows. - **Sorting** — Every sortable column header is a button (with `aria-sort` on the active column) that toggles sort direction. Configure sorting with `sort: 'number' | 'string' | (a, b) => number | false`. Strings use natural diff --git a/docs/reference/renderer-kit.md b/docs/reference/renderer-kit.md index 5934bb18d..ee3ab6c1c 100644 --- a/docs/reference/renderer-kit.md +++ b/docs/reference/renderer-kit.md @@ -3423,6 +3423,34 @@ tokenVar(name: "border-width" | "border-width-thick" | "chart-1" | "chart-10" | `var(--projections-)`: a theme token as a CSS value, for the rare inline style. +### `Tone` + +```ts +type Tone = "default" | "flag" | "quiet" +``` + +A tone: how much an item asks for attention, independent of its change. `quiet` is a lesser item (one that only +reads, a value known only in part), its text muted; `flag` is a domain flag that isn't a change (a write, a +privileged permission), its text in the full foreground at semibold weight. Neither uses a change hue, a dashed edge +or opacity, so a tone never reads as added, removed or modified, and an item's change marking still wins over it. + +### `toneAttributes` + +```ts +toneAttributes(tone: "default" | "flag" | "quiet" | undefined): { "data-projections-tone"?: "flag" | "quiet" } +``` + +The attribute that carries a tone (`data-projections-tone`), for any element (HTML or SVG text). Spread it; the +default tone adds nothing. The kit's styles color and weight the element by it. + +### `tones` + +```ts +tones: Array<"default" | "flag" | "quiet"> +``` + +The tones, in order of attention. + ### `TrackRun` ```ts @@ -3827,6 +3855,7 @@ Props of `DataTable`. | `scope` | `"scope"?: ChangesScope \| undefined` | The Changes scope (`RendererProps.scope`): each run of rows it doesn't show, in the sorted order, folds into one row that opens in place. | | `selectedId` | `"selectedId"?: null \| string` | The host's selection (`RendererProps.selectedId`). | | `sort` | `"sort"?: null \| { "column": string; "direction": "ascending" \| "descending" }` | The sort; the rows' own order when `null` or absent. | +| `tone` | `"tone"?: { (item: T): "default" \| "flag" \| "quiet" }` | A row's tone (`Tone`), from the version it shows: `quiet` mutes a lesser row's text, `flag` sets a flagged row's text semibold. A changed cell's value change keeps its own colors. | ### `EdgeArrowMarker` @@ -4491,11 +4520,13 @@ What `useTableProps` reads from a kit renderer's props. ### `Text` ```ts -Text(__0: { "as"?: "a" | "abbr" | "address" | "animate" | "animateMotion" | "animateTransform" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "circle" | "cite" | "clipPath" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "defs" | "del" | "desc" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "ellipse" | "em" | "embed" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "fieldset" | "figcaption" | "figure" | "filter" | "footer" | "foreignObject" | "form" | "g" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "image" | "img" | "input" | "ins" | "kbd" | "keygen" | "label" | "legend" | "li" | "line" | "linearGradient" | "link" | "main" | "map" | "mark" | "marker" | "mask" | "menu" | "menuitem" | "meta" | "metadata" | "meter" | "mpath" | "nav" | "noindex" | "noscript" | "object" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "path" | "pattern" | "picture" | "polygon" | "polyline" | "pre" | "progress" | "q" | "radialGradient" | "rect" | "rp" | "rt" | "ruby" | "s" | "samp" | "script" | "search" | "section" | "select" | "set" | "slot" | "small" | "source" | "span" | "stop" | "strong" | "style" | "sub" | "summary" | "sup" | "svg" | "switch" | "symbol" | "table" | "tbody" | "td" | "template" | "text" | "textPath" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "tspan" | "u" | "ul" | "use" | "var" | "video" | "view" | "wbr" | "webview" | ComponentClass | FunctionComponent; "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; "size"?: "lg" | "md" | "sm" | "xl" | "xs"; "tone"?: "default" | "muted" | "subtle"; "weight"?: "bold" | "medium" | "normal" | "semibold" }): Element +Text(__0: { "as"?: "a" | "abbr" | "address" | "animate" | "animateMotion" | "animateTransform" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "circle" | "cite" | "clipPath" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "defs" | "del" | "desc" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "ellipse" | "em" | "embed" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "fieldset" | "figcaption" | "figure" | "filter" | "footer" | "foreignObject" | "form" | "g" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "image" | "img" | "input" | "ins" | "kbd" | "keygen" | "label" | "legend" | "li" | "line" | "linearGradient" | "link" | "main" | "map" | "mark" | "marker" | "mask" | "menu" | "menuitem" | "meta" | "metadata" | "meter" | "mpath" | "nav" | "noindex" | "noscript" | "object" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "path" | "pattern" | "picture" | "polygon" | "polyline" | "pre" | "progress" | "q" | "radialGradient" | "rect" | "rp" | "rt" | "ruby" | "s" | "samp" | "script" | "search" | "section" | "select" | "set" | "slot" | "small" | "source" | "span" | "stop" | "strong" | "style" | "sub" | "summary" | "sup" | "svg" | "switch" | "symbol" | "table" | "tbody" | "td" | "template" | "text" | "textPath" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "tspan" | "u" | "ul" | "use" | "var" | "video" | "view" | "wbr" | "webview" | ComponentClass | FunctionComponent; "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; "size"?: "lg" | "md" | "sm" | "xl" | "xs"; "tone"?: "default" | "flag" | "muted" | "quiet" | "subtle"; "weight"?: "bold" | "medium" | "normal" | "semibold" }): Element ``` Text in the theme's type: a step of the type scale, a weight and a tone. `muted` and `subtle` are for secondary -text; change colors are never a tone (use the kit's status components). +text. The kit's tones (`Tone`) say how much the text asks for attention: `quiet` for a lesser item, `flag` for a +domain flag that isn't a change (semibold in the full foreground, whatever `weight` says). Change colors are never a +tone (use the kit's status components). ### `useBorderWidths` diff --git a/packages/renderers/kit/src/index.ts b/packages/renderers/kit/src/index.ts index 232d64699..8b7c29ddf 100644 --- a/packages/renderers/kit/src/index.ts +++ b/packages/renderers/kit/src/index.ts @@ -51,6 +51,7 @@ export * from './table-controls.js' export * from './fit.js' export * from './zoom.js' export * from './palette.js' +export * from './tone.js' export { variedBeyond, variedBeyondLabel, diff --git a/packages/renderers/kit/src/react/data-table-row.tsx b/packages/renderers/kit/src/react/data-table-row.tsx index 393e4db49..8afd84664 100644 --- a/packages/renderers/kit/src/react/data-table-row.tsx +++ b/packages/renderers/kit/src/react/data-table-row.tsx @@ -5,6 +5,7 @@ import {identifier as identifierAttributes} from '@githubnext/projections-render import {changeMark} from '../diff/model.js' import {isChanged} from '../emphasis.js' import {sortedVersion, type TableRow, type TableValue} from '../table.js' +import {toneAttributes, type Tone} from '../tone.js' import {ChangeStatus} from './components.js' import {ValueChange} from './diff-components.js' import type {DataTableColumn} from './data-table.js' @@ -28,6 +29,7 @@ export function Row({ diff, progress, emphasis, + tone, selected, onSelect, locale, @@ -38,6 +40,7 @@ export function Row({ diff: boolean progress: number emphasis: number + tone: ((item: T) => Tone) | undefined selected: boolean onSelect: ((id: string) => void) | undefined locale: string | undefined @@ -81,6 +84,12 @@ export function Row({ content ) } + // Each version in its own tone, so a cell's reserved width holds when the tone changes with the version. + const toned = (version: T) => { + const content = read(version) + const attributes = toneAttributes(tone?.(version)) + return attributes['data-projections-tone'] && shown(content) ? {content} : content + } // Only a changed row's cells are changes: an unchanged one may still differ within a volatile value's tolerance. const differs = changed && @@ -90,7 +99,7 @@ export function Row({ ? column.changed(row.before, row.after) : column.value !== undefined && !Object.is(column.value(row.before), column.value(row.after))) let content: ReactNode - if (differs && diff) content = + if (differs && diff) content = else if (differs && emphasis > 0) // The version shown, as a pill in its side's hue while the change is emphasized; at the endpoints, plain text // exactly as an unchanged cell draws it. @@ -98,10 +107,10 @@ export function Row({ content = ( {side === 'before' ? 'was ' : 'now '} - {read(item)} + {toned(item)} ) - } else content = {read(item)} + } else content = {toned(item)} // Outside the diff a cell shows one version at a time; the other is laid out under it, unseen, so the column // keeps one width for the whole transition and nothing moves when the value switches. Every cell has the same // structure, changed or not. @@ -110,7 +119,7 @@ export function Row({ {content} ) diff --git a/packages/renderers/kit/src/react/data-table.tsx b/packages/renderers/kit/src/react/data-table.tsx index 92e20729b..151add5dc 100644 --- a/packages/renderers/kit/src/react/data-table.tsx +++ b/packages/renderers/kit/src/react/data-table.tsx @@ -5,6 +5,7 @@ import {tableSortOf, tableSortValue} from '../table-controls.js' import {Row} from './data-table-row.js' import {Fold, useFolds} from './fold.js' import type {ChangesScope} from '../scope.js' +import type {Tone} from '../tone.js' /** One column of a `DataTable`: its heading, what its cells show and how it sorts. */ export interface DataTableColumn extends SortableColumn { @@ -41,6 +42,11 @@ export interface DataTableProps { rowProgress?: (row: TableRow) => number /** A row's change emphasis (`RendererProps.emphasis`): 0 at both endpoints and before its step. */ emphasis?: (row: TableRow) => number + /** + * A row's tone (`Tone`), from the version it shows: `quiet` mutes a lesser row's text, `flag` sets a flagged row's + * text semibold. A changed cell's value change keeps its own colors. + */ + tone?: (item: T) => Tone /** The host's selection (`RendererProps.selectedId`). */ selectedId?: string | null /** Selects a row (`RendererProps.onSelect`), when its heading is activated. */ @@ -98,6 +104,7 @@ export function DataTable({ progress = 1, rowProgress, emphasis, + tone, selectedId = null, onSelect, sort = null, @@ -175,6 +182,7 @@ export function DataTable({ diff={diff} progress={rowProgress ? rowProgress(entry.item) : progress} emphasis={emphasis ? emphasis(entry.item) : 0} + tone={tone} selected={selectedId === entry.item.id} onSelect={onSelect} locale={locale} diff --git a/packages/renderers/kit/src/react/layout-components.tsx b/packages/renderers/kit/src/react/layout-components.tsx index 5f3bf5ace..90521581f 100644 --- a/packages/renderers/kit/src/react/layout-components.tsx +++ b/packages/renderers/kit/src/react/layout-components.tsx @@ -12,6 +12,7 @@ import {ChangeFooter, ChangeStatus, Identifier, NameLine} from './components.js' import {changeMark} from '../diff/model.js' import {Icon} from './icons.js' import type {ChangeClassification} from '../emphasis.js' +import {toneAttributes, type Tone} from '../tone.js' interface StatusChange { status: Status @@ -336,7 +337,9 @@ export function Inline({ /** * Text in the theme's type: a step of the type scale, a weight and a tone. `muted` and `subtle` are for secondary - * text; change colors are never a tone (use the kit's status components). + * text. The kit's tones (`Tone`) say how much the text asks for attention: `quiet` for a lesser item, `flag` for a + * domain flag that isn't a change (semibold in the full foreground, whatever `weight` says). Change colors are never a + * tone (use the kit's status components). */ export function Text({ children, @@ -348,12 +351,20 @@ export function Text({ children: ReactNode size?: FontSizeStep weight?: FontWeightStep - tone?: 'default' | 'muted' | 'subtle' + tone?: Tone | 'muted' | 'subtle' as?: ElementType }) { const color = tone === 'muted' ? token.color('fg-muted') : tone === 'subtle' ? token.color('fg-subtle') : undefined return ( - + {children} ) diff --git a/packages/renderers/kit/src/tone.ts b/packages/renderers/kit/src/tone.ts new file mode 100644 index 000000000..2a721c00a --- /dev/null +++ b/packages/renderers/kit/src/tone.ts @@ -0,0 +1,18 @@ +/** + * A tone: how much an item asks for attention, independent of its change. `quiet` is a lesser item (one that only + * reads, a value known only in part), its text muted; `flag` is a domain flag that isn't a change (a write, a + * privileged permission), its text in the full foreground at semibold weight. Neither uses a change hue, a dashed edge + * or opacity, so a tone never reads as added, removed or modified, and an item's change marking still wins over it. + */ +export type Tone = 'default' | 'quiet' | 'flag' + +/** The tones, in order of attention. */ +export const tones: readonly Tone[] = ['quiet', 'default', 'flag'] + +/** + * The attribute that carries a tone (`data-projections-tone`), for any element (HTML or SVG text). Spread it; the + * default tone adds nothing. The kit's styles color and weight the element by it. + */ +export function toneAttributes(tone: Tone | undefined): {'data-projections-tone'?: Exclude} { + return tone && tone !== 'default' ? {'data-projections-tone': tone} : {} +} diff --git a/packages/renderers/kit/styles/text.css b/packages/renderers/kit/styles/text.css index e00fc637a..7fa0a2143 100644 --- a/packages/renderers/kit/styles/text.css +++ b/packages/renderers/kit/styles/text.css @@ -129,3 +129,24 @@ white-space: nowrap; border: 0; } + +/* + * Tones (`data-projections-tone`, the kit's `Tone`): how much an item asks for attention, apart from its change. A + * quiet item's text is muted; a flagged one's is the full foreground at semibold weight. Both stay in the neutral + * foreground, never a change hue, a dashed edge or opacity, so a tone never reads as a change. Text inside a quiet item + * that reads the kit's text color (a name button, say) is muted with it. + */ +.pk [data-projections-tone='quiet'] { + --text: var(--muted); + color: var(--muted); +} +.pk [data-projections-tone='flag'] { + color: var(--text); + font-weight: var(--projections-font-weight-semibold); +} +.pk svg [data-projections-tone='quiet'] { + fill: var(--muted); +} +.pk svg [data-projections-tone='flag'] { + fill: var(--text); +} diff --git a/packages/renderers/kit/test/tone.test.mjs b/packages/renderers/kit/test/tone.test.mjs new file mode 100644 index 000000000..9d57670fd --- /dev/null +++ b/packages/renderers/kit/test/tone.test.mjs @@ -0,0 +1,51 @@ +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 {toneAttributes} from '../dist/index.js' +import {DataTable, Text} from '../dist/react.js' + +test('a tone is an attribute, and the default tone adds none', () => { + assert.deepEqual(toneAttributes('quiet'), {'data-projections-tone': 'quiet'}) + assert.deepEqual(toneAttributes('flag'), {'data-projections-tone': 'flag'}) + assert.deepEqual(toneAttributes('default'), {}) + assert.deepEqual(toneAttributes(undefined), {}) +}) + +test('Text carries its tone, and a flag sets its own weight', () => { + const text = props => renderToStaticMarkup(createElement(Text, props, 'reads')) + assert.match(text({tone: 'quiet'}), /^/u) + assert.doesNotMatch(text({tone: 'muted'}), /data-projections-tone/u) + assert.doesNotMatch(text({}), /data-projections-tone/u) +}) + +test("a table row's cells carry each version's tone, so the reserved width holds when it changes", () => { + const columns = [{id: 'name', label: 'Name', value: item => item.name}] + const rows = [ + {id: 'w', before: {name: 'write', flagged: true}, after: {name: 'write', flagged: false}, status: 'unchanged'}, + {id: 'r', before: {name: 'read', quiet: true}, after: {name: 'read', quiet: true}, status: 'unchanged'}, + ] + const tone = item => (item.flagged ? 'flag' : item.quiet ? 'quiet' : 'default') + const markup = renderToStaticMarkup(createElement(DataTable, {label: 'Tools', columns, rows, comparing: true, progress: 1, tone})) + // The row shows After (default), and reserves Before's width in Before's tone. + assert.match( + markup, + /write<\/span>