Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/agents/create-projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ them in the kit's shell, along with that module's `options` (`nouns`, `facts`,
- Draw no title or counts: the host shows them, so content starts at the top
of the frame (mark a content region with `data-projections-content`).
- Accent and focus colors are only for focus and selection; change colors only
for change status. No horizontal scrolling at 390 px. No network: the
for change status. For domain meaning that isn't a change (a tool that only
reads, a privileged write), use the kit's `tone` (`quiet` or `flag`) on
`Text` and `DataTable` rows, or `toneAttributes`, rather than a change color,
a dashed edge or opacity. No horizontal scrolling at 390 px. No network: the
sandbox blocks it, so bundle every asset.
- Never nest change colors: only the innermost changed elements are colored. A
modified card, row, table or boundary that shows changes inside it (added and
Expand Down
29 changes: 27 additions & 2 deletions docs/guides/renderer-kit-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,31 @@ 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 semibold, in the color it already has (a
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
`@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

Expand Down Expand Up @@ -344,7 +368,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
Expand Down
50 changes: 41 additions & 9 deletions docs/reference/renderer-kit.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion packages/cli/templates/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ them in the kit's shell, along with that module's `options` (`nouns`, `facts`,
- Draw no title or counts: the host shows them, so content starts at the top
of the frame (mark a content region with `data-projections-content`).
- Accent and focus colors are only for focus and selection; change colors only
for change status. No horizontal scrolling at 390 px. No network: the
for change status. For domain meaning that isn't a change (a tool that only
reads, a privileged write), use the kit's `tone` (`quiet` or `flag`) on
`Text` and `DataTable` rows, or `toneAttributes`, rather than a change color,
a dashed edge or opacity. No horizontal scrolling at 390 px. No network: the
sandbox blocks it, so bundle every asset.
- Never nest change colors: only the innermost changed elements are colored. A
modified card, row, table or boundary that shows changes inside it (added and
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions packages/renderers/kit/src/react/data-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -28,6 +29,7 @@ export function Row<T>({
diff,
progress,
emphasis,
tone,
selected,
onSelect,
locale,
Expand All @@ -38,6 +40,7 @@ export function Row<T>({
diff: boolean
progress: number
emphasis: number
tone: ((item: T) => Tone) | undefined
selected: boolean
onSelect: ((id: string) => void) | undefined
locale: string | undefined
Expand Down Expand Up @@ -81,6 +84,12 @@ export function Row<T>({
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) ? <span {...attributes}>{content}</span> : content
}
// Only a changed row's cells are changes: an unchanged one may still differ within a volatile value's tolerance.
const differs =
changed &&
Expand All @@ -90,18 +99,18 @@ export function Row<T>({
? 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 = <ValueChange layout="inline" before={read(row.before!)} after={read(row.after!)} />
if (differs && diff) content = <ValueChange layout="inline" before={toned(row.before!)} after={toned(row.after!)} />
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.
{
content = (
<span className="pk-change-pill pk-table-value" data-change={side === 'before' ? 'removed' : 'added'}>
<span className="sr-only">{side === 'before' ? 'was ' : 'now '}</span>
{read(item)}
{toned(item)}
</span>
)
} else content = <span className={join('pk-table-text', struck && 'pk-diff-text')}>{read(item)}</span>
} else content = <span className={join('pk-table-text', struck && 'pk-diff-text')}>{toned(item)}</span>
// 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.
Expand All @@ -110,7 +119,7 @@ export function Row<T>({
<span className="pk-table-reserve">
{content}
<span className="pk-table-reserve-other" aria-hidden="true">
{read((side === 'before' ? row.after : row.before) ?? item)}
{toned((side === 'before' ? row.after : row.before) ?? item)}
</span>
</span>
)
Expand Down
8 changes: 8 additions & 0 deletions packages/renderers/kit/src/react/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> extends SortableColumn<T> {
Expand Down Expand Up @@ -41,6 +42,11 @@ export interface DataTableProps<T> {
rowProgress?: (row: TableRow<T>) => number
/** A row's change emphasis (`RendererProps.emphasis`): 0 at both endpoints and before its step. */
emphasis?: (row: TableRow<T>) => 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. */
Expand Down Expand Up @@ -98,6 +104,7 @@ export function DataTable<T>({
progress = 1,
rowProgress,
emphasis,
tone,
selectedId = null,
onSelect,
sort = null,
Expand Down Expand Up @@ -175,6 +182,7 @@ export function DataTable<T>({
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}
Expand Down
17 changes: 14 additions & 3 deletions packages/renderers/kit/src/react/layout-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, whatever `weight` says). Change colors are never a
* tone (use the kit's status components).
*/
export function Text({
children,
Expand All @@ -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 (
<Tag className="pk-text" style={{fontSize: token.fontSize(size), fontWeight: token.fontWeight(weight), ...(color ? {color} : {})}}>
<Tag
className="pk-text"
{...toneAttributes(tone === 'muted' || tone === 'subtle' ? undefined : tone)}
style={{
fontSize: token.fontSize(size),
...(tone === 'flag' ? {} : {fontWeight: token.fontWeight(weight)}),
...(color ? {color} : {}),
}}
>
{children}
</Tag>
)
Expand Down
18 changes: 18 additions & 0 deletions packages/renderers/kit/src/tone.ts
Original file line number Diff line number Diff line change
@@ -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 semibold in the color it already has. 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<Tone, 'default'>} {
return tone && tone !== 'default' ? {'data-projections-tone': tone} : {}
}
17 changes: 17 additions & 0 deletions packages/renderers/kit/styles/text.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,20 @@
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 semibold in the color it already has. Neither uses a change hue, a
* dashed edge or opacity, so a tone never reads as a change, and a flag keeps a removed item's muted text muted. 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'] {
font-weight: var(--projections-font-weight-semibold);
}
.pk svg [data-projections-tone='quiet'] {
fill: var(--muted);
}
52 changes: 52 additions & 0 deletions packages/renderers/kit/test/tone.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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'}), /^<span class="pk-text" data-projections-tone="quiet" style="font-size:[^"]*;font-weight:/u)
assert.match(text({tone: 'flag', weight: 'normal'}), /^<span class="pk-text" data-projections-tone="flag" style="font-size:[^;"]*">/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,
/<span class="pk-table-text">write<\/span><span class="pk-table-reserve-other" aria-hidden="true"><span data-projections-tone="flag">write<\/span>/u,
)
assert.match(markup, /<span class="pk-table-text"><span data-projections-tone="quiet">read<\/span><\/span>/u)
assert.doesNotMatch(markup, /role="row"[^>]*data-projections-tone/u)
})

test('tones stay neutral: no change hue, dash or opacity, and a flag keeps the color it has', () => {
const css = readFileSync(new URL('../styles/text.css', import.meta.url), 'utf8')
const rules = [...css.matchAll(/[^{}]*\[data-projections-tone='(?:quiet|flag)'\][^{}]*\{([^}]*)\}/gu)].map(match => match[1])
assert.equal(rules.length, 3)
for (const rule of rules) {
assert.doesNotMatch(rule, /added|removed|modified|moved|pk-region|dash|opacity/u)
for (const value of rule.matchAll(/: ([^;]+);/gu)) {
assert.match(value[1], /^var\(--(?:text|muted|projections-font-weight-semibold)\)$/u)
}
}
for (const flag of css.matchAll(/\[data-projections-tone='flag'\][^{}]*\{([^}]*)\}/gu)) assert.doesNotMatch(flag[1], /color|fill/u)
})