Description list
Slant / Content
Terms and their values in one or two columns, with nested groups, values to copy, and a message where a value is missing.
Demo
Usage
import { DescriptionList, RelativeTime } from '@tuttn/slant'
// Uniform facts: an items array. A missing value reads "Not set"; a nested
// group's term heads its own list.
<DescriptionList columns={2} items={[
{ term: 'Run', value: 'run_8f2c91', copyable: true, mono: true },
{ term: 'Started', value: <RelativeTime date={start} /> },
{ term: 'Owner' },
{ term: 'Limits', items: [{ term: 'CPU', value: '4 cores' }, { term: 'Memory', value: '16 GB' }] },
]} />
// Copy something other than what shows, and name the button yourself.
<DescriptionList items={[
{ term: 'Token', value: 'sk-…3f9a', copyable: fullToken, copyLabel: 'Copy the full token', mono: true },
]} />
// Terms above their values, smaller, with your own word for a missing value.
<DescriptionList layout="stacked" size="sm" emptyText="None" items={facts} />
// Rich items: the compound form.
<DescriptionList>
<DescriptionList.Item term="Model" value="opus" copyable />
<DescriptionList.Item term="Status" value={<Badge tone="success">Running</Badge>} />
</DescriptionList>Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly DescriptionItem[] | — | The items, in order: `{ term, value?, copyable?, copyLabel?, mono?, description?, items?, id? }`. |
children | ReactNode | — | `DescriptionList.Item` parts, when there are no `items`. |
columns | 1 | 2 | 1 | One column, or two that drop to one in a narrow container (under about 500px). |
layout | 'inline' | 'stacked' | 'inline' | The term beside its value, or above it. |
size | 'sm' | 'md' | 'md' | The type scale: `sm` for side panels and dense cards. |
emptyText | ReactNode | messages.noValue | What a missing value shows, muted. |
DescriptionList.Item term | ReactNode | — | The term: what the value is. |
DescriptionList.Item value | ReactNode | — | The value. A missing one (undefined, null or '') shows the list's emptyText. |
DescriptionList.Item copyable | boolean | string | — | Adds a copy button after the value. true copies a string or number value (anything else as the text it shows); a string is the text to copy instead. |
DescriptionList.Item copyLabel | string | messages.copyTerm(term) | The copy button's accessible name; messages.copy when the term isn't a string. |
DescriptionList.Item mono | boolean | — | Sets the value in the monospace font. |
DescriptionList.Item description | ReactNode | — | A hint under the value. |
DescriptionList.Item items | readonly DescriptionItem[] | — | Makes the item a nested group, headed by its term. |
…rest | HTMLAttributes | — | className, style, other attributes and the ref go on the <dl>, and on each DescriptionList.Item's <div>. |
Keyboard
| Tab | moves through the copy buttons, and anything focusable in the values |
| Enter / Space | on a copy button, copies its value |
Accessibility
- A real
<dl>: each item is a<div>holding a<dt>and a<dd>, which is valid inside adl, so a screen reader announces a list of terms and their definitions. A group is the same, its<dd>holding a nested<dl>. - A missing value reads
emptyText(messages.noValue, “Not set”) in words, muted, and the item getsdata-empty, so nothing is left blank. - The copy button is icon-only, named
copyLabelormessages.copyTerm(term)(“Copy Run”). After a copy it shows a check and is named “Copied” (messages.copied) for 1.6 seconds, keeping focus, and the root’s polite announcer says it too. - Where the clipboard is missing or refuses, the value’s text is selected so it can be copied by hand, and the announcer says so (
messages.copySelected).
Layout
layout="inline" puts each term beside its value, the term taking a third of the item; "stacked" puts it above. columns={2} lays the items out in two columns while each can be 15rem wide and drops to one below that, with no container query, so the list sizes to its content wherever it sits. A nested group always has one column and takes the list's layout, size and emptyText.
Copying
copyable copies a string or number value as it is. For any other value it copies the text it shows, so pass a string to copy something else: the full token behind a masked one, an id behind its link. An item with no value has no copy button.