@charcuterie/ui 4.30.0 → 4.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +7 -2
  2. package/docs/README.md +573 -0
  3. package/docs/building-an-app.md +231 -0
  4. package/docs/components/Accordion.md +106 -0
  5. package/docs/components/ActionMenu.md +63 -0
  6. package/docs/components/ActionTiles.md +233 -0
  7. package/docs/components/AdaptiveGrid.md +215 -0
  8. package/docs/components/Alert.md +99 -0
  9. package/docs/components/AnchorLink.md +23 -0
  10. package/docs/components/Avatar.md +153 -0
  11. package/docs/components/Badge.md +81 -0
  12. package/docs/components/BadgeButton.md +84 -0
  13. package/docs/components/Board.md +277 -0
  14. package/docs/components/Breadcrumbs.md +87 -0
  15. package/docs/components/Button.md +72 -0
  16. package/docs/components/ButtonLink.md +81 -0
  17. package/docs/components/Card.md +114 -0
  18. package/docs/components/CatalogPicker.md +250 -0
  19. package/docs/components/Chart.md +39 -0
  20. package/docs/components/Checkbox.md +197 -0
  21. package/docs/components/ColorPicker.md +99 -0
  22. package/docs/components/ColorSchemeSwitcher.md +92 -0
  23. package/docs/components/ColorSchemeToggle.md +98 -0
  24. package/docs/components/Combobox.md +175 -0
  25. package/docs/components/CommandPalette.md +120 -0
  26. package/docs/components/ComparisonChart.md +31 -0
  27. package/docs/components/CopyButton.md +112 -0
  28. package/docs/components/DataTable.md +170 -0
  29. package/docs/components/DatePicker.md +225 -0
  30. package/docs/components/Dialog.md +134 -0
  31. package/docs/components/DropRail.md +107 -0
  32. package/docs/components/EmptyState.md +65 -0
  33. package/docs/components/Field.md +215 -0
  34. package/docs/components/FieldGroup.md +45 -0
  35. package/docs/components/FileDropZone.md +98 -0
  36. package/docs/components/GroupedList.md +189 -0
  37. package/docs/components/Header.md +76 -0
  38. package/docs/components/HtmlEditor-html-editor.md +76 -0
  39. package/docs/components/HtmlView-html-editor.md +47 -0
  40. package/docs/components/HtmlView-html-view.md +47 -0
  41. package/docs/components/IconButton.md +52 -0
  42. package/docs/components/LaneTimeline.md +254 -0
  43. package/docs/components/Lightbox.md +101 -0
  44. package/docs/components/Listbox.md +109 -0
  45. package/docs/components/LiveStatusIndicator.md +60 -0
  46. package/docs/components/LogViewer.md +142 -0
  47. package/docs/components/Main.md +247 -0
  48. package/docs/components/MarkdownEditor.md +262 -0
  49. package/docs/components/MarkdownEditorCodeMirror-markdown-editor-codemirror.md +230 -0
  50. package/docs/components/MarkdownLine.md +187 -0
  51. package/docs/components/MarkdownView-markdown-editor-codemirror.md +235 -0
  52. package/docs/components/MediaTile.md +106 -0
  53. package/docs/components/Menu.md +209 -0
  54. package/docs/components/MetricCard.md +38 -0
  55. package/docs/components/Modal.md +89 -0
  56. package/docs/components/Nav.md +167 -0
  57. package/docs/components/NavBar.md +190 -0
  58. package/docs/components/Picker.md +132 -0
  59. package/docs/components/Popover.md +135 -0
  60. package/docs/components/PortraitTiles.md +169 -0
  61. package/docs/components/ProgressBar.md +70 -0
  62. package/docs/components/ProgressCard.md +65 -0
  63. package/docs/components/QueryBuilder.md +132 -0
  64. package/docs/components/RadioGroup.md +165 -0
  65. package/docs/components/Rail.md +79 -0
  66. package/docs/components/RangeSlider.md +144 -0
  67. package/docs/components/ReactRouterAdapter-react-router.md +27 -0
  68. package/docs/components/ReactRouterLink-react-router.md +23 -0
  69. package/docs/components/ReorderList.md +143 -0
  70. package/docs/components/RouterLinkProvider.md +33 -0
  71. package/docs/components/ScheduleBoard.md +41 -0
  72. package/docs/components/ScrollMemoryProvider.md +33 -0
  73. package/docs/components/SearchInput.md +46 -0
  74. package/docs/components/SegmentedControl.md +98 -0
  75. package/docs/components/Select.md +169 -0
  76. package/docs/components/Shell.md +162 -0
  77. package/docs/components/Skeleton.md +48 -0
  78. package/docs/components/Slider.md +128 -0
  79. package/docs/components/SortableTableHeader.md +84 -0
  80. package/docs/components/Spinner.md +50 -0
  81. package/docs/components/Stepper.md +121 -0
  82. package/docs/components/Swatch.md +79 -0
  83. package/docs/components/Switch.md +80 -0
  84. package/docs/components/TableColumns.md +29 -0
  85. package/docs/components/TableViewport.md +42 -0
  86. package/docs/components/Tabs.md +184 -0
  87. package/docs/components/TextLink.md +106 -0
  88. package/docs/components/TimecodeInput.md +222 -0
  89. package/docs/components/Toast.md +108 -0
  90. package/docs/components/ToastRegion.md +35 -0
  91. package/docs/components/Toolbar.md +118 -0
  92. package/docs/components/Tooltip.md +94 -0
  93. package/docs/components/UnstyledLink.md +21 -0
  94. package/docs/components/ValuePairs.md +30 -0
  95. package/docs/components/VirtualizedGrid.md +204 -0
  96. package/docs/components/VisuallyHidden.md +39 -0
  97. package/docs/components/WeekdayIndicator.md +39 -0
  98. package/docs/hooks/useAdaptiveColumns.md +111 -0
  99. package/docs/hooks/useCommandPalette.md +40 -0
  100. package/docs/hooks/useCommandPaletteHotkeys.md +33 -0
  101. package/docs/hooks/useDeploymentUpdate.md +39 -0
  102. package/docs/hooks/useLastPresentValue.md +23 -0
  103. package/docs/hooks/useListMotion.md +65 -0
  104. package/docs/hooks/useNavLayout.md +59 -0
  105. package/docs/hooks/usePresence.md +39 -0
  106. package/docs/hooks/useRouterLink.md +22 -0
  107. package/docs/hooks/useValueChangeMotion.md +28 -0
  108. package/package.json +7 -5
  109. package/skills/charcuterie/SKILL.md +17 -0
  110. package/skills/charcuterie/references/build-a-screen.md +6 -0
  111. package/skills/charcuterie/references/create-a-component.md +6 -0
  112. package/src/AdaptiveGrid/AdaptiveGrid.stories.tsx +1 -1
  113. package/src/Tabs/Tabs.stories.tsx +1 -1
  114. package/src/VirtualizedGrid/VirtualizedGrid.stories.tsx +65 -28
  115. package/src/VirtualizedGrid/VirtualizedGrid.test.tsx +29 -0
  116. package/src/shell.storyHelpers.tsx +3 -3
@@ -0,0 +1,215 @@
1
+ # AdaptiveGrid
2
+
3
+ ```ts
4
+ import { AdaptiveGrid } from "@charcuterie/ui"
5
+ ```
6
+
7
+ **Height is spent before width.** A column is something this grid is *forced* into when
8
+ the items will not stack inside the window — never something it takes because a monitor
9
+ is wide.
10
+
11
+ That is the opposite of every wrapping grid in the fleet today. `auto-fill, minmax()`
12
+ takes every column the width allows, which is how you end up with seven items strung
13
+ across an ultrawide and nothing below the fold.
14
+
15
+ ## Fill a media workspace
16
+
17
+ Opt in with `layout="fill"` when a gallery or printer fleet should spend the
18
+ available width even if its cards would fit in a taller stack. Set `maxColumns`
19
+ and `minColumnInlineSize` for the content. The shared 16px gap counts toward the
20
+ column floor. Multiple columns use the whole container; a lone column retains
21
+ its reading measure. The default remains height-first.
22
+
23
+ ## The rule in one sentence
24
+
25
+ > If you're going to vertically scroll anyway, widen the items. If you're not, keep them
26
+ > in a smaller grid so they all still fit on screen.
27
+
28
+ Mechanically:
29
+
30
+ 1. Ask how many items stack in the space available — the viewport's block size, minus
31
+ whatever chrome sits above and below.
32
+ 2. Divide the item count by that. **That** is how many columns are needed.
33
+ 3. Only then ask how many columns actually fit across the container, and take the smaller
34
+ of the two.
35
+
36
+ Step 3 can only ever *reduce* the answer. Width is a veto, not a reason.
37
+
38
+ ## The part that reads backwards
39
+
40
+ Same nine items, same width, three heights — and the **taller** window takes **fewer**
41
+ columns. A 1440x900 laptop gets three columns while a larger 1920x1080 monitor gets two.
42
+
43
+ That is not a bug and it is not a tuned breakpoint. The taller window stacks the same nine
44
+ items in fewer stacks, so it needs fewer stacks. If you "fix" it, you have thrown the rule
45
+ away and rebuilt `auto-fill`.
46
+
47
+ ## The content cap widens as columns are added
48
+
49
+ The other half of the complaint this answers is pages that are "1 column, but waaaaaaay
50
+ too wide". So the cap around the grid is not a constant:
51
+
52
+ | Columns | Cap |
53
+ | --- | --- |
54
+ | 1 | 56rem |
55
+ | 2 | 72rem |
56
+ | 3 | 106rem |
57
+ | 4 | 140rem |
58
+
59
+ One column stays at a reading measure, because a 2000px-wide card is not a better card —
60
+ it is one line of text the eye has to track from bezel to bezel. The page earns its width
61
+ by having something to fill it with.
62
+
63
+ The three numbers behind that table are `contentInlineSize` in `@charcuterie/tokens`,
64
+ beside `screen` and `containerQuery`, and every part is overridable per call. The
65
+ arithmetic lives in `getContentMaxInlineSize` and is not a token.
66
+
67
+ ## When to reach for it
68
+
69
+ Reach for it when **all** of these are true:
70
+
71
+ - The items wrap, and there could be few or many of them.
72
+ - They are roughly the same height, and you can measure one.
73
+ - Scrolling is a cost rather than the point — a rack of bays, a fleet of hosts, a set of
74
+ status cards. Ideally the user never scrolls at all.
75
+
76
+ Do **not** reach for it for a feed, a search-results list, or anything else that is
77
+ inherently long. The rule optimises for "it all fits", and content that will never all fit
78
+ gets nothing from it.
79
+
80
+ ## The one number you must measure
81
+
82
+ `itemBlockSize` is the only required option and the only genuinely app-specific one.
83
+ Measure it off a running page rather than deriving it from padding, and **err high** — over-
84
+ estimating makes the grid reach for a column slightly early, and a page that scrolls when
85
+ it did not have to is the entire complaint. It only has to be right to within about one
86
+ item; being one out shifts a borderline window by one column, which is taste.
87
+
88
+ `chromeBlockSize` is everything down the page that is not the grid: header, rails, filter
89
+ rows, labels. It defaults to `0`.
90
+
91
+ ## It measures its container, not the window
92
+
93
+ Three grids, one browser window, three different answers. The inline size comes off a
94
+ `ResizeObserver` on the grid's own container, so a grid sitting beside a rail is told the
95
+ truth about the room it has — the container-query thesis this library is built on, applied
96
+ to a layout decision instead of a card's internals.
97
+
98
+ The block size is the exception, and it has to be: the question is "will this scroll", and
99
+ an element in normal flow is exactly as tall as its contents, so measuring the grid always
100
+ answers "it fits." That number comes from the viewport, behind an injectable
101
+ `blockSizeResolver` for Electron windows, fixed-height kiosk panels, and tests.
102
+
103
+ ⚠️ **Never apply the returned cap to the element being measured.** If you wire
104
+ `useAdaptiveColumns` by hand, the observed box and the capped box must be different
105
+ elements. Collapse them and the fold reads back its own narrowed output: one column,
106
+ forever, with no error anywhere. `AdaptiveGrid` enforces this structurally — an uncapped
107
+ outer box it measures, an inner box it caps.
108
+
109
+ ## Composing with a shell
110
+
111
+ `AdaptiveGrid` caps itself, so it is correct standing alone. If you want the **page chrome**
112
+ to widen with the grid rather than the grid rattling around inside a fixed column, hoist
113
+ the hook to the page and hand the pieces out:
114
+
115
+
116
+
117
+ The `Main` region takes a caller-supplied max inline size; the ref goes on whatever box
118
+ sits **outside** that cap.
119
+
120
+ ## Manual override
121
+
122
+ `"auto"` is always in the list. A picker that only offers numbers once a number has been
123
+ chosen is a one-way door — it strands someone on a layout they tried once with no route
124
+ back to the mode that adapts.
125
+
126
+ Pass `storageKey` to remember the choice across visits, namespaced to your app; the
127
+ library will not invent that string for you. Omit it and the choice lasts the session and
128
+ is written nowhere. Every unreadable stored value — a corrupt key, a browser that refuses
129
+ storage, a count the picker cannot offer — falls back to `"auto"`, so a bad value costs a
130
+ preference rather than a page.
131
+
132
+ ## Why the tracks are an inline style
133
+
134
+ `repeat(N, minmax(0, 1fr))` is interpolated, and a className may not be. Tailwind v4 scans
135
+ source *text* for complete class strings, so `grid-cols-${columns}` generates nothing at
136
+ all — no error, no warning, an unstyled element. A class-per-count would need every count
137
+ to survive the scan; an inline style needs none. `tailwindCandidates.test.ts` rejects the
138
+ interpolated form outright.
139
+
140
+ ## `min-w-0` is not optional
141
+
142
+ Every child gets `min-w-0`, applied by the component rather than asked for. A grid item's
143
+ automatic minimum size is `min-content`, so one long unbroken string — a file path, a URL —
144
+ widens its own track and shoves the whole grid past the viewport. The rule that stops it
145
+ has to sit on children the caller owns, which is why it is not your job to remember.
146
+
147
+ You still owe your own items a wrap or a `truncate`; `min-w-0` lets the track get small
148
+ enough for that clipping to matter.
149
+
150
+ Keep DOM order consistent with reading order when the layout reflows. Let the children supply their own semantic names and interactive behavior.
151
+
152
+ ```tsx
153
+ import { Card } from "@charcuterie/ui"
154
+
155
+ <AdaptiveGrid itemBlockSize={180}>
156
+ <Card heading="Planning" />
157
+ <Card heading="Implementation" />
158
+ </AdaptiveGrid>
159
+ ```
160
+
161
+ ## Published TypeScript API
162
+
163
+ ```ts
164
+ const AdaptiveGrid: ({ blockSizeResolver, children, chromeBlockSize, className, columns, itemBlockSize, itemCount, layout: gridLayout, maxColumns, minColumnInlineSize, storageKey, }: AdaptiveGridProps) => ReactNode
165
+
166
+ type AdaptiveGridProps = {
167
+ /**
168
+ * Where the available block size is read from. Defaults to the
169
+ * viewport, which is the only thing that can answer "will this
170
+ * scroll".
171
+ */
172
+ blockSizeResolver?: BlockSizeResolver;
173
+ children: ReactNode;
174
+ /**
175
+ * Everything down the page that is not this grid, in CSS px —
176
+ * header, rails, filter rows. Subtracted before asking how many
177
+ * items stack.
178
+ */
179
+ chromeBlockSize?: number;
180
+ className?: string;
181
+ /**
182
+ * Draw this many columns instead of the automatic answer — the
183
+ * manual override, for a picker or a page that hoisted
184
+ * `useAdaptiveColumns` itself.
185
+ */
186
+ columns?: number;
187
+ /**
188
+ * One item's block size in CSS px. **The one genuinely
189
+ * app-specific number.** Measure it off a running page and err
190
+ * high: a page that scrolls when it did not have to is the
191
+ * complaint this component exists to answer.
192
+ */
193
+ itemBlockSize: number;
194
+ /**
195
+ * How many items to lay out. Defaults to the number of children,
196
+ * and is worth passing explicitly when the rendered count churns
197
+ * — a grid that reflowed every time one item finished loading
198
+ * would be worse than one that is an item out.
199
+ */
200
+ itemCount?: number;
201
+ /** Fill the container with readable columns instead of spending height first. */
202
+ layout?: GridLayout;
203
+ /** The most columns the automatic answer will take. */
204
+ maxColumns?: number;
205
+ /** The narrowest a column may be, in CSS px. */
206
+ minColumnInlineSize?: number;
207
+ /**
208
+ * The `localStorage` key a manual choice is remembered under.
209
+ * Namespace it to the app; omit it and nothing is written.
210
+ */
211
+ storageKey?: string;
212
+ };
213
+ ```
214
+
215
+ [Full declarations](../../dist/AdaptiveGrid/AdaptiveGrid.d.ts)
@@ -0,0 +1,99 @@
1
+ # Alert
2
+
3
+ ```ts
4
+ import { Alert } from "@charcuterie/ui"
5
+ ```
6
+
7
+ **The component M5 found, rather than one the plan predicted.** rip-deck spells this shape
8
+ four times — `TowerAlerts`, `UsbAlertBanner`, `LoadedDiscsBanner`, `VerdictBadge` — and two
9
+ of those carry a byte-identical `TONE_CLASS` map of hardcoded hexes with no light mode.
10
+ mux-magic spells the same idea a third way in `statusClassMap`.
11
+
12
+ ## It is a block by default, and a landmark only when named
13
+
14
+ `label` decides, and the evidence divides cleanly.
15
+
16
+ The **banners** are one alert at the top of a page and want to be addressable —
17
+ `getByRole("region", { name: "USB connection alert" })`. They pass a `label`.
18
+
19
+ The **verdict** renders inside every bay card, and one of its two forms is the single
20
+ sentence *"Part of the tower-wide problem above."* Nine landmarks sharing one name is axe's
21
+ `landmark-unique`, so it passes none.
22
+
23
+ A component that always took the landmark would fail its own a11y gate on a nine-bay tower.
24
+ One that never took it leaves three `<section aria-label>` wrappers hand-rolled in the
25
+ consumer — which is what rip-deck has today.
26
+
27
+ ## The heading is not a heading element
28
+
29
+ An alert's headline is a **sentence** — "Bay 7 is reading with errors; clean the disc and
30
+ try again" — not a node in the document outline. Nine bays' worth of those as `<h3>`s
31
+ builds a table of contents out of nine complaints, which is worse for a screen reader than
32
+ no outline entry at all.
33
+
34
+ `Card` and `EmptyState` take a real `headingLevel` precisely because their headings *are*
35
+ short outline nodes. This one is styled text, and `label` is how it becomes findable.
36
+
37
+ ## It does not announce, and that is a component boundary
38
+
39
+ No `role="alert"`, no `aria-live`. Two reasons, and the second is the load-bearing one:
40
+
41
+ 1. A live region takes **no accessible name from its content**
42
+ ([decision](https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-07-29-status-regions-carry-an-aria-label.md)),
43
+ so an announcing variant needs a name that duplicates the sentence it is announcing.
44
+ 2. `role="alert"` on a `<section>` **overrides the landmark**. It cannot be both a thing
45
+ you can scope queries to and a thing that interrupts you.
46
+
47
+ A thing that interrupts you is a `Toast` (M6). This is a thing that is *on the page*.
48
+
49
+ ## The evidence is a list
50
+
51
+ `details` renders a `<ul>`, so a screen reader announces "list, 3 items" instead of running
52
+ three measurements together into one sentence. The key is `${index}-${line}` rather than
53
+ the line itself, because **evidence repeats**: two drives both reporting "3 read errors" is
54
+ the normal case on a tower, not an edge one.
55
+
56
+ ```tsx
57
+ <Alert heading="Connection interrupted" intent="warning"
58
+ description="Changes are saved locally until you reconnect." />
59
+ ```
60
+
61
+ ## Published TypeScript API
62
+
63
+ ```ts
64
+ const Alert: ({ actions, className, description, details, heading, intent, label, size, ...sectionProps }: AlertProps) => ReactNode
65
+
66
+ type AlertProps = Omit<ComponentPropsWithRef<"section">, "children"> & {
67
+ /** Buttons. Laid out beside the text at `cq-sm` and up. */
68
+ actions?: ReactNode;
69
+ /** The quiet second line — counts, timestamps, provenance. */
70
+ description?: ReactNode;
71
+ /**
72
+ * The evidence, one line each. A list rather than a paragraph
73
+ * because that is what it is, and because a screen reader then
74
+ * announces "list, 3 items" instead of running three measurements
75
+ * together into one sentence.
76
+ */
77
+ details?: readonly string[];
78
+ /**
79
+ * The sentence. A `ReactNode` rather than a `string` because
80
+ * rip-deck's verdicts qualify themselves inline — *"…(suspected —
81
+ * retry in another drive to confirm)"* — and splitting that across
82
+ * two props would let the qualifier drift away from the claim it
83
+ * qualifies.
84
+ */
85
+ heading: ReactNode;
86
+ intent?: IntentName;
87
+ /**
88
+ * Present ⇒ this is a **named landmark** and
89
+ * `getByRole("region", { name })` finds it. Absent ⇒ a plain
90
+ * block, because a `<section>` with no accessible name is
91
+ * `generic` rather than `region`. See below; the default is
92
+ * deliberate.
93
+ */
94
+ label?: string;
95
+ size?: AlertSize;
96
+ };
97
+ ```
98
+
99
+ [Full declarations](../../dist/Alert/Alert.d.ts)
@@ -0,0 +1,23 @@
1
+ # AnchorLink
2
+
3
+ ```ts
4
+ import { AnchorLink } from "@charcuterie/ui"
5
+ ```
6
+
7
+ Use the plain anchor fallback in a custom router adapter. Use `TextLink` for visible text navigation or `UnstyledLink` to preserve an app's link treatment. Provide link text that names the destination.
8
+
9
+ ```tsx
10
+ <AnchorLink href="/help">Help</AnchorLink>
11
+ ```
12
+
13
+ ## Published TypeScript API
14
+
15
+ ```ts
16
+ const AnchorLink: ({ href, ...anchorProps }: RouterLinkProps) => ReactNode
17
+
18
+ type RouterLinkProps = Omit<ComponentPropsWithRef<"a">, "href"> & {
19
+ href: string;
20
+ };
21
+ ```
22
+
23
+ [Full declarations](../../dist/RouterLink/AnchorLink.d.ts)
@@ -0,0 +1,153 @@
1
+ # Avatar
2
+
3
+ ```ts
4
+ import { Avatar } from "@charcuterie/ui"
5
+ ```
6
+
7
+ A person, as a coloured chip — a glyph or an initial, with the name attached where only
8
+ assistive technology and a hover can reach it. It exists to **delete a printed name**: a
9
+ board whose cards all say "Owner" has spent a column on a word that a colour says faster.
10
+
11
+ ## Unassigned draws nothing, and the component owns that
12
+
13
+ `name` accepts `null` and `undefined`, and either one renders `null`. That is the decision,
14
+ not an accident of the type.
15
+
16
+ A grey "None" placeholder is a design system talking over the reader: it repeats a fact
17
+ nobody needed, down every unassigned row, at the same visual weight as the chips that mean
18
+ something. The alternative — a ternary at every call site — puts the same decision in a
19
+ board, a table, a card footer and a detail pane, each written on a different day, and the
20
+ one that forgets is the one that ships the grey circle. Absence is expressed once, here.
21
+ It is the same call `Board` makes with `onMove`: no handler means no affordance rather than
22
+ a dead one.
23
+
24
+ An app that genuinely wants to *say* "unassigned" still can. That is text, or an
25
+ `EmptyState`, and neither of them is an avatar.
26
+
27
+ Where a column of rows has to keep one start edge, **the layout reserves the slot** — a
28
+ grid column sized in `em` of the row's own type, which the unassigned row leaves empty.
29
+ That is a decision about alignment, made once by the thing that owns the alignment, rather
30
+ than a placeholder chip pretending to be data. `InAList` below is that composition.
31
+
32
+ Keep the wrapper. A component that returns `null` contributes **no grid item**, so a bare
33
+ `<Avatar>` in a grid cell lets the unassigned row's next element slide into the reserved
34
+ column — the one way this goes wrong, and it goes wrong silently.
35
+
36
+ ## The name is never visible text
37
+
38
+ `role="img"` with an `aria-label`, exactly as `Swatch` does, so
39
+ `getByRole("img", { name })` is one stable handle whether the chip is showing a photo, a
40
+ glyph or two letters. `title` carries the same string for a pointer — the letters `AL` are
41
+ not a name, and hover is the only channel a sighted reader has.
42
+
43
+ There is deliberately no `isNameVisible`. An avatar with its name printed beside it is a
44
+ name with a decoration in front of it; a layout that wants that should print the name and
45
+ skip the chip.
46
+
47
+ ## The colour is derived, never invented
48
+
49
+ `categorical` is the ten-wide non-semantic scale — the same one `Badge` takes — and **not**
50
+ an `intent`. An intent is a claim the design system makes about state, and a person is not
51
+ `danger`.
52
+
53
+ With no `categorical`, the index comes from `getCategoricalIndex` in
54
+ `@charcuterie/tokens`: a pure function of the key, so the same person is the same colour on
55
+ every machine, on every reload, and in a server render. Pass `categoricalKey` with the
56
+ user's **id** wherever one exists — the hash does no normalization on purpose, so hashing a
57
+ name means a rename or a trailing space silently repaints somebody the reader had already
58
+ learned to recognise.
59
+
60
+ Ten colours means collisions past ten people. That is a property of the palette rather than
61
+ a fault in the hash: the colour helps you *scan* a list, and the accessible name is what
62
+ identifies.
63
+
64
+ ## A photo is never the only thing
65
+
66
+ `imageUrl` is optional and falls back to the initials when it is absent, when it 404s, and
67
+ when a signed URL has expired. A hand-rolled avatar shows the browser's broken-image glyph
68
+ in all three, because nobody writes the `onError` handler until they have seen it happen.
69
+
70
+ The failed URL is stored rather than a `hasFailed` boolean, so a second photo gets its own
71
+ attempt with no effect syncing a prop back into state.
72
+
73
+ ## There is no `AvatarGroup`
74
+
75
+ Deliberately. A stack of overlapping chips with a `+3` needs answers to which three
76
+ survive, in what order, and what the overflow announces — and no consumer has asked the
77
+ question yet. A row of `Avatar`s in a flex box is what a multi-assignee list looks like
78
+ until one does.
79
+
80
+ ```tsx
81
+ <Avatar name="Alex Smith" size="sm" />
82
+ ```
83
+
84
+ ## Published TypeScript API
85
+
86
+ ```ts
87
+ const Avatar: ({ appearance, categorical, categoricalKey, className, icon, imageUrl, initials, name, size, title, ...spanProps }: AvatarProps) => ReactNode
88
+
89
+ type AvatarProps = Omit<ComponentPropsWithRef<"span">, "children"> & {
90
+ /**
91
+ * The same three the rest of the categorical family wears, minus
92
+ * `ghost` — a chip with no fill and no border is a floating
93
+ * letter, and the whole job here is to be a **shape** the eye
94
+ * finds in a list.
95
+ */
96
+ appearance?: Exclude<IntentAppearance, "ghost">;
97
+ /**
98
+ * The colour, when somebody has chosen one. Omitted, it is derived
99
+ * — see `categoricalKey` — so an avatar always has a colour and
100
+ * never has to be given one.
101
+ */
102
+ categorical?: CategoricalIndex;
103
+ /**
104
+ * What the derived colour is hashed from when `categorical` is
105
+ * absent. Defaults to `name`.
106
+ *
107
+ * Pass the **user's id** wherever one exists. `getCategoricalIndex`
108
+ * does no normalization on purpose, so hashing the name means a
109
+ * rename — or a trailing space — silently repaints a person the
110
+ * reader had already learned to recognise. An id does not move.
111
+ */
112
+ categoricalKey?: string;
113
+ /**
114
+ * A glyph instead of the initials — a robot for an agent account,
115
+ * a lock for a service account. The library ships **no icons**, so
116
+ * this is the app's own
117
+ * (decision).
118
+ * It is decoration: the name still travels in `aria-label`, and a
119
+ * glyph the font cannot render must not be the only thing
120
+ * carrying who this is.
121
+ */
122
+ icon?: ReactNode;
123
+ /**
124
+ * A photo. Optional, and **it is never the only thing** — a
125
+ * request that 404s, a signed URL that expired, or an app that
126
+ * simply has no photos falls back to the initials with no empty
127
+ * box in between.
128
+ */
129
+ imageUrl?: string;
130
+ /**
131
+ * The letters, when the derivation is wrong. Derived from `name`
132
+ * otherwise: the first character of each of the first two
133
+ * whitespace-separated words, upper-cased.
134
+ *
135
+ * Worth passing for a name the split gets wrong — a mononym that
136
+ * wants two letters, a name whose family part comes first, a
137
+ * handle with punctuation in it.
138
+ */
139
+ initials?: string;
140
+ /**
141
+ * Who this is. Read by assistive technology and shown on hover;
142
+ * **never printed as visible text**, which is the entire point of
143
+ * the component.
144
+ *
145
+ * Nullable, and that is a decision rather than a loose type — see
146
+ * the note on the component about what an unassigned row draws.
147
+ */
148
+ name: string | null | undefined;
149
+ size?: AvatarSize;
150
+ };
151
+ ```
152
+
153
+ [Full declarations](../../dist/Avatar/Avatar.d.ts)
@@ -0,0 +1,81 @@
1
+ # Badge
2
+
3
+ ```ts
4
+ import { Badge } from "@charcuterie/ui"
5
+ ```
6
+
7
+ Four repos, and rip-deck declares the **identical** `TONE_CLASS` map twice —
8
+ `VerdictBadge.tsx` and `TowerAlerts.tsx`, same five hardcoded hexes, related only by
9
+ copy-paste. mux-magic's `statusClassMap` is the same idea spelled a third way, keyed by a
10
+ bare `string`, so an unrecognised status renders with no colour and no error.
11
+
12
+ ## Where the status half lives
13
+
14
+ `intent` covers the colour. Which *state* maps to which intent — and what it is called in
15
+ English — lives in `statusIntent.ts` as exhaustive switches over the machines
16
+ `@charcuterie/logic` ships:
17
+
18
+
19
+
20
+ That is the whole of mux-magic's `StatusBadge`, and adding a state to the machine is a
21
+ compile error here rather than a blank pill in production.
22
+
23
+ ## Colour a user picked: `categorical`
24
+
25
+ `intent` is six colours that each **mean** something, and that is exactly wrong for a
26
+ label somebody named "Homelab". So there is a second family — numbered, not named:
27
+
28
+ ```tsx
29
+ <Badge categorical={4}>Homelab</Badge>
30
+ ```
31
+
32
+ Ten indexes, each with the same seven roles an intent has, generated per variant and
33
+ contrast-gated in **both** schemes. The point of the gating is that the choice is safe:
34
+ a user picking from this palette cannot pick one that is unreadable.
35
+
36
+ `intent` and `categorical` are **mutually exclusive in the type**. A badge is one colour,
37
+ and `<Badge intent="danger" categorical={3}>` is a question with no answer rather than a
38
+ precedence rule to remember.
39
+
40
+ ### Rows that predate the feature
41
+
42
+ `getCategoricalIndex(key)` from `@charcuterie/tokens` is a pure function from a string to
43
+ an index — stable across runs, machines and a server-rendered copy — so a hundred existing
44
+ labels get colours with no migration and no `Math.random()` handing the same row a
45
+ different colour on every reload. It is a **fallback**, never an override:
46
+
47
+
48
+
49
+ Hash the row's **id** where one exists. The function deliberately does not normalize, so
50
+ renaming a label renames its colour too — and with ten colours, two labels in twelve will
51
+ share one. That is a property of the palette, not of the hash: the colour helps you scan a
52
+ list, the text is what says which label it is.
53
+
54
+ ### When it is `Swatch` instead
55
+
56
+ `Swatch` takes a colour arriving from the world — a physical sticker on a controller, an
57
+ accent extracted off an album — which is arbitrary, unthemeable and uncheckable. This
58
+ family is a curated set the design system owns and re-themes. Ungoverned colour is
59
+ `Swatch`; a choice from a palette is `categorical`.
60
+
61
+ ## No implicit role
62
+
63
+ A badge is a word about something else. It is not a live region, and `role="status"` would
64
+ make every re-render announce itself. Where a status genuinely needs announcing, that is
65
+ `LiveStatusIndicator`; where a badge needs a name beyond its text, `aria-label` still
66
+ works. Hover styling is deliberately absent too — `INTENT_HOVER_CLASS` is opt-in, so a
67
+ verdict pill cannot imply it is clickable.
68
+
69
+ ## Published TypeScript API
70
+
71
+ ```ts
72
+ const Badge: ({ appearance, categorical, children, className, icon, intent, overflow, size, title, ...spanProps }: BadgeProps) => ReactNode
73
+
74
+ type BadgeProps = ComponentPropsWithRef<"span"> & BadgeShapeProps & {} & ({
75
+ categorical?: never;
76
+ } | {
77
+ intent?: never;
78
+ });
79
+ ```
80
+
81
+ [Full declarations](../../dist/Badge/Badge.d.ts)
@@ -0,0 +1,84 @@
1
+ # BadgeButton
2
+
3
+ ```ts
4
+ import { BadgeButton } from "@charcuterie/ui"
5
+ ```
6
+
7
+ **A badge you can press.** It takes `Badge`'s visual props and paints identically to it —
8
+ and it is a real `<button>`.
9
+
10
+ QueuePilot is where this came from. Its poster tiles carry per-entry settings as *tags*: a
11
+ default entry says nothing, and every tag you do see is a deviation worth reading. Each one
12
+ opens the panel that changes it, so each one is pressable — and all six were spelled
13
+ `<button className="badge tagbtn …">`, a hand-painted pill in app CSS, because the library
14
+ had no way to make `Badge` pressable. The same shape turns up on a start-point chip, a
15
+ group chip and a pool's Exclude chip.
16
+
17
+ ## It is the same pill, not a copy of it
18
+
19
+ `Badge` and `BadgeButton` both build their pill through `useBadgeShape`, so the class list,
20
+ the icon slot, the truncation and the only-when-clipped `title` are read once rather than
21
+ duplicated. `BadgeButton.test.tsx` then compares the two elements' **computed** styles in
22
+ the real browser, which is the version of that claim a refactor cannot quietly break.
23
+
24
+ ## What the element buys, and none of it is paint
25
+
26
+ Focus, the tab order, Enter **and** Space, `:disabled`, form participation, and a `button`
27
+ role a screen reader announces as pressable. A `<span onClick>` has none of them, and
28
+ `getByRole("button", { name })` — what every test and every agent driving the app matches
29
+ on — finds nothing at all.
30
+
31
+ ## Why not `asChild`, and why not `Badge` growing an `onClick`
32
+
33
+ This library has no polymorphism pattern and has not needed one. Adding `asChild` here would
34
+ make every future component answer "can it be something else?" instead of "what is it?",
35
+ and the precedent already exists in the other direction: `ButtonLink` is a sibling of
36
+ `Button` for exactly this reason.
37
+
38
+ An element type that changes as a **side effect** of passing a handler is worse. Forget the
39
+ handler and the control silently ships as a `<span>` — not focusable, not in the tab order,
40
+ invisible to `getByRole`, with no error anywhere. `onClick` is required here instead, so a
41
+ pill nobody can press is a `Badge` by construction.
42
+
43
+ ## Two defaults worth knowing
44
+
45
+ **`type="button"`.** These chips sit inside forms — QueuePilot's entry sheet is one — and
46
+ the platform's default of `submit` would make a "change the start point" chip save the whole
47
+ dialog. It is overridable, because a badge-shaped submit is a real thing.
48
+
49
+ **`ghost` is excluded**, inherited from `Badge`: a pill that paints nothing until hovered
50
+ has no pill left, and a control that only advertises itself on hover cannot be found by
51
+ touch.
52
+
53
+ ```tsx
54
+ function ActiveFilter({ filterActive }: { filterActive: () => void }) {
55
+ return <BadgeButton onClick={filterActive}>Active</BadgeButton>
56
+ }
57
+ ```
58
+
59
+ ## Published TypeScript API
60
+
61
+ ```ts
62
+ const BadgeButton: ({ appearance, categorical, children, className, icon, intent, isDisabled, overflow, size, title, type, ...buttonProps }: BadgeButtonProps) => ReactNode
63
+
64
+ type BadgeButtonProps = Omit<ComponentPropsWithRef<"button">, "disabled"> & BadgeShapeProps & {
65
+ /**
66
+ * Required, and that is the component's argument in one line: a
67
+ * pill nobody can press is a `Badge`, and a pill that looks
68
+ * pressable and is not is the defect this exists to stop.
69
+ */
70
+ onClick: NonNullable<ComponentPropsWithRef<"button">["onClick"]>;
71
+ /**
72
+ * `isDisabled`, not `disabled` — the same prop `Button` keeps
73
+ * instead of the native one, so a control's disabled state is
74
+ * spelled one way across the library.
75
+ */
76
+ isDisabled?: boolean;
77
+ } & ({
78
+ categorical?: never;
79
+ } | {
80
+ intent?: never;
81
+ });
82
+ ```
83
+
84
+ [Full declarations](../../dist/BadgeButton/BadgeButton.d.ts)