Skip to content
Merged
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: 5 additions & 0 deletions changelog.d/facts-value-list.md
Original file line number Diff line number Diff line change
@@ -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`. `ValueMark` marks one value the same way, and `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).
5 changes: 3 additions & 2 deletions docs/agents/create-projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion docs/guides/renderer-kit-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand Down
78 changes: 75 additions & 3 deletions docs/reference/renderer-kit.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/cli/templates/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/renderers/kit/react.css
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 1 addition & 0 deletions packages/renderers/kit/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
41 changes: 40 additions & 1 deletion packages/renderers/kit/src/react/diff-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) ? <span {...label}>{value}</span> : undefined)
return <ValueText before={text(before)} after={text(after)} {...(className !== undefined ? {className} : {})} />
}
return (
<span className={`pk-value-change${className ? ` ${className}` : ''}`} data-layout={layout}>
{has(before) && (
Expand Down Expand Up @@ -128,3 +138,32 @@ export function SvgValueChange({
</text>
)
}

/**
* 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, className}: {before?: ReactNode; after?: ReactNode; className?: string}) {
const has = (value: ReactNode) => value !== undefined && value !== null && value !== false
return (
<span className={className ? `pk-value-change ${className}` : 'pk-value-change'} data-variant="text">
{has(before) && (
<del className="pk-value-mark" data-change="removed">
<span className="sr-only">was </span>
{before}
</del>
)}
{has(before) && has(after) && (
<span className="pk-value-arrow" aria-hidden="true">
→
</span>
)}
{has(after) && (
<ins className="pk-value-mark" data-change="added">
<span className="sr-only">{has(before) ? ', now ' : 'now '}</span>
{after}
</ins>
)}
</span>
)
}
250 changes: 250 additions & 0 deletions packages/renderers/kit/src/react/facts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
// 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 {ValueChange, ValueText} from './diff-components.js'
import {Chip, Chips} from './chip.js'

const signs: Partial<Record<ChangeClassification, string>> = {added: '+', removed: '−', modified: '~', renamed: '~'}

const hasContent = (value: ReactNode) => value !== undefined && value !== null && value !== false && value !== ''

const emphasisStyle = (emphasis: number | undefined) =>
emphasis === undefined ? undefined : ({'--emphasis': emphasis} as Record<string, number>)

/**
* 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 (
<dl className={className ? `pk-facts ${className}` : 'pk-facts'} data-label-font={labelFont} aria-label={label}>
{children}
</dl>
)
}

/**
* 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 (
<div className="pk-fact" style={emphasisStyle(emphasis)}>
<dt>
{changed ? (
<Label className="pk-value-mark" data-change={change}>
<span className="sr-only">{statusLabels[change]}: </span>
{label}
</Label>
) : (
label
)}
</dt>
<dd>
{changed ? (
<Label className="pk-value-mark" data-change={change}>
{children}
</Label>
) : (
children
)}
{meta !== undefined && meta !== null && meta !== false && (
<span className="pk-fact-meta" data-alone={hasContent(children) ? undefined : ''}>
{meta}
</span>
)}
</dd>
</div>
)
}

/** 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`), keeping each item's change, sign, previous value and code font.
*/
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') {
// Chips wrap in a row, so `layout` and `separator` don't apply; everything else does.
return (
<Chips label={label} {...(className !== undefined ? {className} : {})}>
{items.map(item => {
const change = item.change ?? 'unchanged'
const id = item.entityId
return (
<Chip
key={item.key}
label={
change === 'modified' && item.was !== undefined ? (
<ValueChange layout="inline" code={code} before={item.was} after={item.label} />
) : (
item.label
)
}
font={code ? 'code' : 'text'}
change={change}
sign={sign}
{...(emphasis !== undefined ? {emphasis} : {})}
{...(id !== undefined && onSelect ? {id, onSelect, selected: selectedId === id} : {})}
/>
)
})}
</Chips>
)
}
const text = (content: ReactNode) => (code ? <span {...identifierAttributes}>{content}</span> : content)
return (
<ul
className={className ? `pk-value-list ${className}` : 'pk-value-list'}
data-layout={layout}
data-separator={layout === 'inline' ? separator : undefined}
aria-label={label}
style={emphasisStyle(emphasis)}
>
{items.map(item => {
const change = item.change ?? 'unchanged'
const id = item.entityId
const value =
change === 'modified' && item.was !== undefined ? (
<ValueText before={text(item.was)} after={text(item.label)} />
) : change === 'unchanged' ? (
text(item.label)
) : (
<ValueMark change={change} sign={sign}>
{text(item.label)}
</ValueMark>
)
return (
<li key={item.key} className="pk-value-item">
{id !== undefined && onSelect ? (
<button
type="button"
className={id === selectedId ? 'pk-value-select pk-part selected' : 'pk-value-select pk-part'}
data-entity-id={id}
aria-pressed={id === selectedId}
onClick={event => {
event.stopPropagation()
onSelect(id)
}}
>
{value}
</button>
) : (
value
)}
</li>
)
})}
</ul>
)
}

/**
* 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 (
<Tag className="pk-value-mark" data-change={change} style={emphasisStyle(emphasis)}>
<span className="sr-only">{statusLabels[change]}: </span>
{sign && signs[change] && (
<span className="pk-value-sign" aria-hidden="true">
{signs[change]}
</span>
)}
{children}
</Tag>
)
}
Loading