@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.
- package/README.md +7 -2
- package/docs/README.md +573 -0
- package/docs/building-an-app.md +231 -0
- package/docs/components/Accordion.md +106 -0
- package/docs/components/ActionMenu.md +63 -0
- package/docs/components/ActionTiles.md +233 -0
- package/docs/components/AdaptiveGrid.md +215 -0
- package/docs/components/Alert.md +99 -0
- package/docs/components/AnchorLink.md +23 -0
- package/docs/components/Avatar.md +153 -0
- package/docs/components/Badge.md +81 -0
- package/docs/components/BadgeButton.md +84 -0
- package/docs/components/Board.md +277 -0
- package/docs/components/Breadcrumbs.md +87 -0
- package/docs/components/Button.md +72 -0
- package/docs/components/ButtonLink.md +81 -0
- package/docs/components/Card.md +114 -0
- package/docs/components/CatalogPicker.md +250 -0
- package/docs/components/Chart.md +39 -0
- package/docs/components/Checkbox.md +197 -0
- package/docs/components/ColorPicker.md +99 -0
- package/docs/components/ColorSchemeSwitcher.md +92 -0
- package/docs/components/ColorSchemeToggle.md +98 -0
- package/docs/components/Combobox.md +175 -0
- package/docs/components/CommandPalette.md +120 -0
- package/docs/components/ComparisonChart.md +31 -0
- package/docs/components/CopyButton.md +112 -0
- package/docs/components/DataTable.md +170 -0
- package/docs/components/DatePicker.md +225 -0
- package/docs/components/Dialog.md +134 -0
- package/docs/components/DropRail.md +107 -0
- package/docs/components/EmptyState.md +65 -0
- package/docs/components/Field.md +215 -0
- package/docs/components/FieldGroup.md +45 -0
- package/docs/components/FileDropZone.md +98 -0
- package/docs/components/GroupedList.md +189 -0
- package/docs/components/Header.md +76 -0
- package/docs/components/HtmlEditor-html-editor.md +76 -0
- package/docs/components/HtmlView-html-editor.md +47 -0
- package/docs/components/HtmlView-html-view.md +47 -0
- package/docs/components/IconButton.md +52 -0
- package/docs/components/LaneTimeline.md +254 -0
- package/docs/components/Lightbox.md +101 -0
- package/docs/components/Listbox.md +109 -0
- package/docs/components/LiveStatusIndicator.md +60 -0
- package/docs/components/LogViewer.md +142 -0
- package/docs/components/Main.md +247 -0
- package/docs/components/MarkdownEditor.md +262 -0
- package/docs/components/MarkdownEditorCodeMirror-markdown-editor-codemirror.md +230 -0
- package/docs/components/MarkdownLine.md +187 -0
- package/docs/components/MarkdownView-markdown-editor-codemirror.md +235 -0
- package/docs/components/MediaTile.md +106 -0
- package/docs/components/Menu.md +209 -0
- package/docs/components/MetricCard.md +38 -0
- package/docs/components/Modal.md +89 -0
- package/docs/components/Nav.md +167 -0
- package/docs/components/NavBar.md +190 -0
- package/docs/components/Picker.md +132 -0
- package/docs/components/Popover.md +135 -0
- package/docs/components/PortraitTiles.md +169 -0
- package/docs/components/ProgressBar.md +70 -0
- package/docs/components/ProgressCard.md +65 -0
- package/docs/components/QueryBuilder.md +132 -0
- package/docs/components/RadioGroup.md +165 -0
- package/docs/components/Rail.md +79 -0
- package/docs/components/RangeSlider.md +144 -0
- package/docs/components/ReactRouterAdapter-react-router.md +27 -0
- package/docs/components/ReactRouterLink-react-router.md +23 -0
- package/docs/components/ReorderList.md +143 -0
- package/docs/components/RouterLinkProvider.md +33 -0
- package/docs/components/ScheduleBoard.md +41 -0
- package/docs/components/ScrollMemoryProvider.md +33 -0
- package/docs/components/SearchInput.md +46 -0
- package/docs/components/SegmentedControl.md +98 -0
- package/docs/components/Select.md +169 -0
- package/docs/components/Shell.md +162 -0
- package/docs/components/Skeleton.md +48 -0
- package/docs/components/Slider.md +128 -0
- package/docs/components/SortableTableHeader.md +84 -0
- package/docs/components/Spinner.md +50 -0
- package/docs/components/Stepper.md +121 -0
- package/docs/components/Swatch.md +79 -0
- package/docs/components/Switch.md +80 -0
- package/docs/components/TableColumns.md +29 -0
- package/docs/components/TableViewport.md +42 -0
- package/docs/components/Tabs.md +184 -0
- package/docs/components/TextLink.md +106 -0
- package/docs/components/TimecodeInput.md +222 -0
- package/docs/components/Toast.md +108 -0
- package/docs/components/ToastRegion.md +35 -0
- package/docs/components/Toolbar.md +118 -0
- package/docs/components/Tooltip.md +94 -0
- package/docs/components/UnstyledLink.md +21 -0
- package/docs/components/ValuePairs.md +30 -0
- package/docs/components/VirtualizedGrid.md +204 -0
- package/docs/components/VisuallyHidden.md +39 -0
- package/docs/components/WeekdayIndicator.md +39 -0
- package/docs/hooks/useAdaptiveColumns.md +111 -0
- package/docs/hooks/useCommandPalette.md +40 -0
- package/docs/hooks/useCommandPaletteHotkeys.md +33 -0
- package/docs/hooks/useDeploymentUpdate.md +39 -0
- package/docs/hooks/useLastPresentValue.md +23 -0
- package/docs/hooks/useListMotion.md +65 -0
- package/docs/hooks/useNavLayout.md +59 -0
- package/docs/hooks/usePresence.md +39 -0
- package/docs/hooks/useRouterLink.md +22 -0
- package/docs/hooks/useValueChangeMotion.md +28 -0
- package/package.json +7 -5
- package/skills/charcuterie/SKILL.md +17 -0
- package/skills/charcuterie/references/build-a-screen.md +6 -0
- package/skills/charcuterie/references/create-a-component.md +6 -0
- package/src/AdaptiveGrid/AdaptiveGrid.stories.tsx +1 -1
- package/src/Tabs/Tabs.stories.tsx +1 -1
- package/src/VirtualizedGrid/VirtualizedGrid.stories.tsx +65 -28
- package/src/VirtualizedGrid/VirtualizedGrid.test.tsx +29 -0
- package/src/shell.storyHelpers.tsx +3 -3
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# CatalogPicker
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { CatalogPicker } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
A picker over a large catalog — forty AI models from six providers, say — that you can
|
|
8
|
+
**browse by group** on a rail or **search across everything** at once.
|
|
9
|
+
|
|
10
|
+
## When to use it, and when not
|
|
11
|
+
|
|
12
|
+
| You have | Use |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| A short list, no typing needed | `Picker` |
|
|
15
|
+
| One flat list that wants a filter | `Combobox` |
|
|
16
|
+
| A long list that falls into groups people think in — providers, accounts, vendors — and whose rows look alike until you read the end | **`CatalogPicker`** |
|
|
17
|
+
|
|
18
|
+
`Picker` has no filter, and `Combobox` filters one flat list with no way to look at just
|
|
19
|
+
one part of it. A catalog of models named "Provider · Model · slug" is exactly where both
|
|
20
|
+
fall short: every row starts the same way, and finding one means reading all of them.
|
|
21
|
+
The rail answers "show me this provider's models", and the search answers "I know the
|
|
22
|
+
name" without making the person know the provider first.
|
|
23
|
+
|
|
24
|
+
## The shape
|
|
25
|
+
|
|
26
|
+
- **The trigger** shows the chosen item's mark and label, and is named
|
|
27
|
+
`"<label>: <chosen label>"`, as `Picker`'s is, then `", <group label>"` when the chosen
|
|
28
|
+
item's group has a label that is not blank — `"Agent: Lumen 4, Contoso"`. Query it as
|
|
29
|
+
`getByRole("button", { name: /^Agent: / })`.
|
|
30
|
+
- **The rail**, on the inline start: a **Favorites** star first (only when `favorites`
|
|
31
|
+
resolves to at least one item, a pinned one included), then one button per group, in
|
|
32
|
+
`groups` order. A group with no rows is left off. Each button's accessible name and tooltip is the group's
|
|
33
|
+
`label`.
|
|
34
|
+
- **The search field** at the top of the list, then **the list** for the current tab.
|
|
35
|
+
Each row shows the mark, the label, the optional `description`, a small star on a
|
|
36
|
+
favorite, and a check mark on the chosen row. The star and the check are drawn in CSS,
|
|
37
|
+
not typed, because a symbol character renders as nothing where the font lacks it.
|
|
38
|
+
- **Pinned rows** (`pinned: "start"` or `"end"`) appear at the top or bottom of every
|
|
39
|
+
tab and of the search results when they match — a "Default" that belongs to no group.
|
|
40
|
+
- **Ungrouped rows** — `groupId: null`, or a `groupId` that names no group — appear on
|
|
41
|
+
every tab, just after the pinned-start rows, and at the same place in search results.
|
|
42
|
+
No row is ever reachable only by search. Each row is listed once per view: a pinned or
|
|
43
|
+
ungrouped favorite is not listed a second time on the Favorites tab.
|
|
44
|
+
|
|
45
|
+
### One value, one row
|
|
46
|
+
|
|
47
|
+
Every item's `value` must be unique across the whole catalog, and every group's `id`
|
|
48
|
+
across `groups`. If one repeats, **the first one wins** — in the trigger, the list, the
|
|
49
|
+
check mark and Favorites alike — the later ones are dropped, and the picker logs a
|
|
50
|
+
`console.warn` naming them.
|
|
51
|
+
|
|
52
|
+
## Searching
|
|
53
|
+
|
|
54
|
+
Typing searches **every item**, whatever tab is current. The match is a case-insensitive
|
|
55
|
+
substring on the label, the description and the group's label, and **every word must
|
|
56
|
+
match**: `work lumen` finds the Lumen rows of the "Contoso (Work)" account and not the
|
|
57
|
+
others. Results sit under one heading per group, in rail order; favorites are found under
|
|
58
|
+
their group, not in a section of their own. While a query is live, no rail button is
|
|
59
|
+
pressed, because no one group is being shown.
|
|
60
|
+
|
|
61
|
+
This is not `CommandPalette`'s word-prefix match. A model's slug (`ct-lumen-4`) and a
|
|
62
|
+
version number (`4.5`) are things people type the middle of.
|
|
63
|
+
|
|
64
|
+
## Opening
|
|
65
|
+
|
|
66
|
+
Every open starts fresh: the query is empty, even when the picker is reopened while the
|
|
67
|
+
last panel is still fading out. The panel opens on **Favorites** when the chosen value is
|
|
68
|
+
a favorite or a row that every tab lists (pinned or ungrouped); otherwise on the **chosen
|
|
69
|
+
row's group**; otherwise on Favorites; otherwise on the first group. The chosen row is
|
|
70
|
+
highlighted and **centred** in the list — the rule a `Combobox` follows when it opens on
|
|
71
|
+
its chosen option. Focus goes to the search field.
|
|
72
|
+
|
|
73
|
+
Disabling an open picker closes it, and enabling it again leaves it closed.
|
|
74
|
+
|
|
75
|
+
## When the catalog changes while it is open
|
|
76
|
+
|
|
77
|
+
The highlight follows the row's `value`, not its position. If the catalog refreshes and
|
|
78
|
+
the rows move, the same row stays highlighted, so Enter chooses what the person saw. Only
|
|
79
|
+
when that row leaves the view, or becomes disabled, does the highlight move: to the
|
|
80
|
+
chosen row if the view shows it, even during a search, else the first enabled row. Each
|
|
81
|
+
row keeps its own button while a refresh leaves it in the same section, so a click already
|
|
82
|
+
pressed stays on its row. A refresh that moves the row to another section (for example, from
|
|
83
|
+
its group to the pinned rows) cancels that click instead; a click never lands on another row. If a refresh removes the rail
|
|
84
|
+
button that has focus, focus moves to the rail button that takes its place (or to the
|
|
85
|
+
search field), never to the page behind.
|
|
86
|
+
|
|
87
|
+
## Keyboard
|
|
88
|
+
|
|
89
|
+
| Where | Key | Does |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| Search | ArrowDown / ArrowUp | Move the highlight, skipping disabled rows |
|
|
92
|
+
| Search | Home / End | Move the caret, as in any text field (and in `Combobox`) |
|
|
93
|
+
| Search | Enter | Choose the highlighted row and close |
|
|
94
|
+
| Search | Escape | Clear the query; on an empty query, close |
|
|
95
|
+
| Search | Tab | To the clear button while it shows, else to the rail; with neither, focus stays |
|
|
96
|
+
| Search | Shift+Tab | To the rail, else to the clear button while it shows |
|
|
97
|
+
| Clear button | Tab / Shift+Tab | To the rail, or the search field with no rail / back to the search field |
|
|
98
|
+
| Clear button | Escape | Clear the query, back in the search field |
|
|
99
|
+
| Rail | ArrowDown / ArrowUp, Home / End | Move between groups (wraps) |
|
|
100
|
+
| Rail | Enter / Space | Show that group |
|
|
101
|
+
| Rail | Tab | Back to the search field |
|
|
102
|
+
| Rail | Shift+Tab | To the clear button while it shows, else the search field |
|
|
103
|
+
| Rail | Escape | As in the search field |
|
|
104
|
+
|
|
105
|
+
Closing with Enter or Escape returns focus to the trigger. The picker consumes every
|
|
106
|
+
Escape it handles, so inside a `Dialog` the first Escape clears, the next closes the
|
|
107
|
+
picker, and the dialog stays open. While an input method editor is composing a word, its
|
|
108
|
+
Enter, Escape and arrows belong to the editor, not the picker.
|
|
109
|
+
|
|
110
|
+
## The ARIA shape, and why the rail is not a `tablist`
|
|
111
|
+
|
|
112
|
+
The trigger opens a `role="dialog"` named by the trigger. The search field is a
|
|
113
|
+
`role="combobox"` that keeps focus and moves `aria-activedescendant` through a
|
|
114
|
+
`role="listbox"` — the `Combobox` contract — and search results are labelled
|
|
115
|
+
`role="group"`s inside that listbox.
|
|
116
|
+
|
|
117
|
+
The rail looks like tabs but is a vertical **`role="toolbar"` of `aria-pressed`
|
|
118
|
+
buttons**. A tablist has to have a selected tab, and while a search runs none of them is
|
|
119
|
+
true; and a tab controls a tab panel, while what the rail changes is a listbox that the
|
|
120
|
+
search field drives too. A toolbar of toggle buttons says what is true — switches that
|
|
121
|
+
change what the list shows — and brings the APG keyboard contract with it: one tab stop,
|
|
122
|
+
the arrows move, Enter and Space press.
|
|
123
|
+
|
|
124
|
+
A mouse click on a rail button does not take focus from the search field, so a person can
|
|
125
|
+
click a group and keep typing or arrowing.
|
|
126
|
+
|
|
127
|
+
### A row's name says its group
|
|
128
|
+
|
|
129
|
+
The mark beside a row is decorative, so the group is said in words, from its label. A row is named by its
|
|
130
|
+
label, then its description, then its group: `"Lumen 4 ct-lumen-4, Contoso"` and
|
|
131
|
+
`"Lumen 4 Work account, Contoso (Work)"`. Two accounts that both star "Opus" give Favorites
|
|
132
|
+
two rows that look the same and are named apart — `"Opus, Team One"` and
|
|
133
|
+
`"Opus, Team Two"` — and the trigger names the chosen one's group the same way. A row with no
|
|
134
|
+
group, a missing group, or a group whose label is blank has no suffix.
|
|
135
|
+
|
|
136
|
+
The name is an `aria-label`: the row's label and description, in the order the row shows
|
|
137
|
+
them, then the group's label. The mark beside them is decorative, whether it is the group's
|
|
138
|
+
badge or icon or the item's own. It is not a `VisuallyHidden` suffix: an `sr-only` span is
|
|
139
|
+
laid out as a block, so Chromium and Testing Library name the row `"Opus , Team Two"`, with
|
|
140
|
+
a space before the comma, and an exact query misses it.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
// Testing Library matches a string name whole.
|
|
144
|
+
getByRole("option", { name: "Opus, Team Two" })
|
|
145
|
+
getByRole("button", { name: "Agent: Opus, Team Two" })
|
|
146
|
+
|
|
147
|
+
// Playwright matches a substring unless told otherwise: "Opus, Team Two" would also find
|
|
148
|
+
// "Opus, Team Two Work".
|
|
149
|
+
page.getByRole("option", { exact: true, name: "Opus, Team Two" })
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The group usually tells same-label rows in differently labelled groups apart. It does not
|
|
153
|
+
make every name unique: two names collide whenever their whole text matches, and a label,
|
|
154
|
+
description, or group label can contain any text, commas included. A catalog that needs
|
|
155
|
+
unique names checks the whole names. Two groups both
|
|
156
|
+
labelled `"Work"` make two `"Opus, Work"` rows; `"Opus"` with the description `"Preview"`
|
|
157
|
+
reads the same as `"Opus Preview"` with none; and an ungrouped `"Opus, Team Two"` reads the
|
|
158
|
+
same as `"Opus"` in Team Two. The trigger does not say the description, so give such rows,
|
|
159
|
+
or their groups, distinct labels. A blank group label or description adds nothing to a name.
|
|
160
|
+
|
|
161
|
+
## Icons, badges and accent colors
|
|
162
|
+
|
|
163
|
+
Charcuterie ships no icons. Pass the app's own provider logos as `icon` on a group (or on
|
|
164
|
+
one item, to override its group's). A group without an icon gets an **initials badge**:
|
|
165
|
+
the first letter of its first two words, so "Tailspin Labs" is "TL".
|
|
166
|
+
|
|
167
|
+
`accentColor` (any CSS color) draws a **ring** around the mark. It is how two accounts of
|
|
168
|
+
one provider are told apart. It is never the fill behind text or the text itself, so a
|
|
169
|
+
consumer's color cannot fail the contrast gate.
|
|
170
|
+
|
|
171
|
+
## Sizes and narrow windows
|
|
172
|
+
|
|
173
|
+
`size` sets the trigger and every row in the panel, as a `Combobox`'s `itemSize` sets its
|
|
174
|
+
search field and its options; a short window steps the rows down on its own. The panel is
|
|
175
|
+
26rem wide and 28rem tall, capped to the space the window leaves, so on a 384px phone the
|
|
176
|
+
rail stays and the list narrows beside it.
|
|
177
|
+
|
|
178
|
+
## Not windowed
|
|
179
|
+
|
|
180
|
+
Every row of the current view renders. `Combobox` windows only above 100 rows and the
|
|
181
|
+
catalogs this was built for are 40 to 60. A catalog large enough to need windowing is a
|
|
182
|
+
change to this component, not a prop.
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { useState } from "react"
|
|
186
|
+
|
|
187
|
+
function TemplateChoice() {
|
|
188
|
+
const [template, setTemplate] = useState("weekly")
|
|
189
|
+
return <CatalogPicker
|
|
190
|
+
groups={[{ id: "shared", label: "Shared" }]}
|
|
191
|
+
items={[{ groupId: "shared", label: "Weekly report", value: "weekly" }]}
|
|
192
|
+
label="Template" onChange={setTemplate} value={template} />
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Published TypeScript API
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
const CatalogPicker: ({ className, clearIcon, emptyLabel, favorites, favoritesLabel, groups: givenGroups, isDisabled, items: givenItems, label, onChange, placeholder, placement, searchPlaceholder, size, value, ...buttonProps }: CatalogPickerProps) => ReactNode
|
|
200
|
+
|
|
201
|
+
type CatalogPickerProps = Omit<ComponentPropsWithRef<"button">, "children" | "disabled" | "onChange" | "value"> & {
|
|
202
|
+
/**
|
|
203
|
+
* The glyph inside the search field's clear button — the app's own,
|
|
204
|
+
* as for `SearchInput`. Without one there is no clear button, and
|
|
205
|
+
* Escape clears the query.
|
|
206
|
+
*/
|
|
207
|
+
clearIcon?: ReactNode;
|
|
208
|
+
/** The trigger. As in `Picker`, the outermost box this renders. */
|
|
209
|
+
className?: string;
|
|
210
|
+
/** Shown when a search matches nothing. Default "No matches". */
|
|
211
|
+
emptyLabel?: string;
|
|
212
|
+
/** Item values, in the order the Favorites tab lists them. No favorites, no Favorites tab. */
|
|
213
|
+
favorites?: readonly string[];
|
|
214
|
+
/** The Favorites tab's accessible name and tooltip. Default "Favorites". */
|
|
215
|
+
favoritesLabel?: string;
|
|
216
|
+
/**
|
|
217
|
+
* The rail, top to bottom (after Favorites). A group with no rows is
|
|
218
|
+
* left off. Each `id` must be unique: a repeated one is dropped (the
|
|
219
|
+
* first wins), with a console warning.
|
|
220
|
+
*/
|
|
221
|
+
groups: readonly CatalogPickerGroup[];
|
|
222
|
+
isDisabled?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Everything that can be chosen. A group's rows keep this order. Each
|
|
225
|
+
* `value` must be unique across the catalog: a repeated one is
|
|
226
|
+
* dropped (the first wins), with a console warning.
|
|
227
|
+
*/
|
|
228
|
+
items: readonly CatalogPickerItem[];
|
|
229
|
+
/**
|
|
230
|
+
* What the control is FOR — "Agent", "Model". Not the current value.
|
|
231
|
+
* The trigger is named `"<label>: <chosen label>"`, as in `Picker`,
|
|
232
|
+
* then `", <group label>"` when the chosen item's group has a label
|
|
233
|
+
* that is not blank; the
|
|
234
|
+
* search field and the list are named `label`.
|
|
235
|
+
*/
|
|
236
|
+
label: string;
|
|
237
|
+
onChange: (value: string) => void;
|
|
238
|
+
/** The trigger's text when nothing is chosen. */
|
|
239
|
+
placeholder?: string;
|
|
240
|
+
/** Where the panel opens against the trigger. Default `bottom-start`. */
|
|
241
|
+
placement?: Placement;
|
|
242
|
+
/** The search field's placeholder. Default "Search…". */
|
|
243
|
+
searchPlaceholder?: string;
|
|
244
|
+
/** The trigger's size, and the size of every row in the panel. Default `md`. */
|
|
245
|
+
size?: ControlSize;
|
|
246
|
+
value?: string;
|
|
247
|
+
};
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
[Full declarations](../../dist/CatalogPicker/CatalogPicker.d.ts)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Chart
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Chart } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Bar and line plots with a zero baseline, negative values, explicit missing samples, and an optional values table. The app owns the data and its meaning. Null means unavailable, never zero. Color is optional; mark titles, labels, and the table preserve the information without it.
|
|
8
|
+
|
|
9
|
+
TanStack Charts 0.18.0 is the primary renderer. Hover, tap, or focus the plot and use arrow keys, Home, and End to inspect values. Tooltips show every series for the selected label, including unavailable samples. Positive and negative contributions stack independently with `barLayout="stacked"`; grouped bars remain the default. `isAnimated={false}` disables motion, and changes to `prefers-reduced-motion` are honored while mounted.
|
|
10
|
+
|
|
11
|
+
Use `renderer="portable"` for the existing lightweight SVG fallback. Its static output and the optional semantic values table remain available. Neither renderer fetches data.
|
|
12
|
+
|
|
13
|
+
`@charcuterie/logic/charts` exports `createChartDefinition` and a standalone `renderChartSvg` with explicit image dimensions. `@charcuterie/logic/charts/preact` exports native `ChartPlot` without React or a compatibility layer. `@charcuterie/logic/core` keeps the dependency-free portable renderer for constrained consumers. Static consumers supply resolved colors rather than browser CSS variables.
|
|
14
|
+
|
|
15
|
+
TanStack remains alpha and is pinned exactly. Upgrades require the interaction and export checks recorded in the decision and evaluation.
|
|
16
|
+
|
|
17
|
+
Provide a title and label every series. Use the values table when the reader needs the exact numbers as text.
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
<Chart title="Jobs completed" labels={["Mon", "Tue"]}
|
|
21
|
+
series={[{ id: "done", label: "Completed", values: [4, 7] }]} />
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Published TypeScript API
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const Chart: ({ className, isTableVisible, renderer, isAnimated, ...options }: ChartProps) => ReactNode
|
|
28
|
+
|
|
29
|
+
type ChartProps = ChartOptions & {
|
|
30
|
+
className?: string;
|
|
31
|
+
/** A text table exposes every value without relying on color, hover, or SVG. */
|
|
32
|
+
isTableVisible?: boolean;
|
|
33
|
+
/** The portable renderer is an explicit fallback for constrained environments. */
|
|
34
|
+
renderer?: "tanstack" | "portable";
|
|
35
|
+
isAnimated?: boolean;
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
[Full declarations](../../dist/Chart/Chart.d.ts)
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Checkbox
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Checkbox } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
A single boolean, on or off, that owns nothing but itself.
|
|
8
|
+
|
|
9
|
+
This is the primitive mux-magic's `BooleanField` hand-rolled because the library had no
|
|
10
|
+
checkbox to reach for. Its box was `bg-slate-700 border-slate-500 accent-blue-500` — three
|
|
11
|
+
palette colours with no light mode, the exact M6 defect the token layer exists to delete.
|
|
12
|
+
Here the box is `bg-surface-sunken`, its border `border-border-strong`, and the fill
|
|
13
|
+
`bg-intent-accent-solid`, so one control reads correctly in `daylight`, `midnight`, and on
|
|
14
|
+
the kiosk with no per-app override. `BooleanField` becomes a thin wrapper that binds this
|
|
15
|
+
to a `CommandField`.
|
|
16
|
+
|
|
17
|
+
## The `<label>` wraps the control
|
|
18
|
+
|
|
19
|
+
A checkbox reads to the **left** of its text, which is why it is not a `Field`. `Field`
|
|
20
|
+
stacks label above control in a `flex-col` — right for a text input, wrong for a boolean —
|
|
21
|
+
and stacking every checkbox in a step card (`isRecursive`, `isDryRun`, …) would double the
|
|
22
|
+
card's height for no gain.
|
|
23
|
+
|
|
24
|
+
Wrapping is also the one label association that needs no `for` at all: the control is a
|
|
25
|
+
descendant of its `<label>`, so there is no id to mint, clone, and get wrong. That is the
|
|
26
|
+
whole defect [`Field`](Field.md) exists to prevent, avoided here by
|
|
27
|
+
construction rather than by wiring.
|
|
28
|
+
|
|
29
|
+
## The `<input>` is the store
|
|
30
|
+
|
|
31
|
+
`defaultChecked`, not `checked`. The DOM owns a checkbox's state natively, so there is no
|
|
32
|
+
second copy to keep in step and no controlled round-trip — reading the value back is the
|
|
33
|
+
`<input>`'s job, and `onChange` reports each change to a consumer that wants to persist it.
|
|
34
|
+
`isChecked` seeds the first paint and nothing after.
|
|
35
|
+
|
|
36
|
+
This is the same refusal `SegmentedControl` makes about `selectedValue`: a controlled prop
|
|
37
|
+
is the thing this library does not have, because a control that cannot hold its own state
|
|
38
|
+
is a control every consumer has to hold it for.
|
|
39
|
+
|
|
40
|
+
## Three ways a box can be inactive
|
|
41
|
+
|
|
42
|
+
`isDisabled` and `isReadOnly` are different states, and the box shows all three:
|
|
43
|
+
|
|
44
|
+
- **Enabled** — the accent intent, a crisp `border-strong` edge.
|
|
45
|
+
- **Disabled** — the same box turned down with `opacity-60`. It dims rather than fading a
|
|
46
|
+
token because the scale has no step between `border-default` and `border-strong`, so a
|
|
47
|
+
muted outline was either invisible or indistinguishable from enabled.
|
|
48
|
+
- **Read-only** — full contrast, because the whole point is that the value stays legible,
|
|
49
|
+
but in the **neutral** intent with a softer edge: an informational value you may read
|
|
50
|
+
here and change elsewhere, not an actionable accent. It announces `aria-readonly`, and
|
|
51
|
+
the toggle is blocked on both pointer and `Space`.
|
|
52
|
+
|
|
53
|
+
## A group of boxes needs `value`
|
|
54
|
+
|
|
55
|
+
`value` is the `<input>`'s `value` attribute: **which member of a group** this box is, as
|
|
56
|
+
opposed to whether it is ticked. A lone boolean should omit it.
|
|
57
|
+
|
|
58
|
+
A group needs it, because a group is read back with one query over its container rather
|
|
59
|
+
than by keeping a callback's worth of state per box:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const chosen = [...group.querySelectorAll<HTMLInputElement>("input[type=checkbox]")]
|
|
63
|
+
.filter((input) => input.checked)
|
|
64
|
+
.map((input) => input.value)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Without a `value` every box in the group answers the UA default `"on"`, so that read
|
|
68
|
+
returns N copies of one meaningless string. This is why queuepilot's library and ratings
|
|
69
|
+
pickers were still hand-rolling a raw `<input type="checkbox">` instead of using this
|
|
70
|
+
component — the component was correct and simply could not express the case.
|
|
71
|
+
|
|
72
|
+
It is passed straight through and is otherwise inert: it is **not** the checked state and
|
|
73
|
+
does not become one. `isChecked` still seeds the box, `onChange` still reports a boolean.
|
|
74
|
+
|
|
75
|
+
## A hint follows the box
|
|
76
|
+
|
|
77
|
+
`description` is standing help bound with `aria-describedby`, so a screen reader reads it
|
|
78
|
+
**with** the control rather than announcing it from nowhere — the same slot, the same words
|
|
79
|
+
and the same announcement order as [`Field`](Field.md)'s.
|
|
80
|
+
|
|
81
|
+
`Field` has had one since it shipped and this component had none, which is a gap you only
|
|
82
|
+
feel in a mixed box: a hint after a checkbox had to be the app's own paragraph while the
|
|
83
|
+
hint after the `Field` two rows down came from the library, and the two disagreed about how
|
|
84
|
+
big a hint is. One control's help looking unlike its neighbour's, in the same editor.
|
|
85
|
+
|
|
86
|
+
The hint renders **outside** the `<label>`, which is the only place it can go. A `<label>`'s
|
|
87
|
+
text content *is* the control's accessible name, so a hint inside it would be announced
|
|
88
|
+
twice — once inside the name, once again as the description — and a pointer press on a
|
|
89
|
+
sentence of explanation would toggle the box. So the `<label>` is no longer the outermost
|
|
90
|
+
element this component renders: a `<div>` holds the row and the hint, and `className` moves
|
|
91
|
+
out to it, because `className` is the outermost box a component renders and that rule does
|
|
92
|
+
not bend for this one.
|
|
93
|
+
|
|
94
|
+
Two smaller decisions inside it:
|
|
95
|
+
|
|
96
|
+
- **`opacity-60` stays on the `<label>`** and does not reach the hint. axe exempts a
|
|
97
|
+
disabled control and its own label from the colour-contrast rule and exempts nothing else,
|
|
98
|
+
so dimming the hint with the box measures **3.77:1** on `midnight` against a 4.5
|
|
99
|
+
threshold. A hint nobody can read is worse than a hint that does not dim, and a turned-off
|
|
100
|
+
box is exactly when that sentence gets read.
|
|
101
|
+
- **There is no `error` to go with it.** `Field` derives `aria-invalid` from its error, and a
|
|
102
|
+
lone boolean is almost never the invalid thing — a *group* of them is, and a group's error
|
|
103
|
+
belongs on the `FieldGroup` around it, described rather than asserted.
|
|
104
|
+
|
|
105
|
+
## Checkbox or `Switch`
|
|
106
|
+
|
|
107
|
+
Same state kind, different meaning. A checkbox is a value you **submit** — "delete
|
|
108
|
+
originals", "I agree" — and a [`Switch`](Switch.md) is a setting that
|
|
109
|
+
**takes effect the moment it is flipped**. A screen reader announces
|
|
110
|
+
"checked/unchecked" for one and "on/off" for the other, which is the line to hold when
|
|
111
|
+
choosing between them.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { useState } from "react"
|
|
115
|
+
|
|
116
|
+
function ArchiveFilter() {
|
|
117
|
+
const [isChecked, setIsChecked] = useState(false)
|
|
118
|
+
return <Checkbox isChecked={isChecked} label="Include archived" onChange={setIsChecked} />
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Published TypeScript API
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const Checkbox: ({ className, description, id, isChecked, isDisabled, isReadOnly, label, onChange, size, value, }: CheckboxProps) => ReactNode
|
|
126
|
+
|
|
127
|
+
type CheckboxProps = {
|
|
128
|
+
className?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Standing help under the box — units, a consequence, a warning
|
|
131
|
+
* about what ticking it does. Same slot, same words and same
|
|
132
|
+
* announcement order as `Field`'s: bound with `aria-describedby`,
|
|
133
|
+
* so a screen reader reads it **with** the control rather than
|
|
134
|
+
* announcing it from nowhere.
|
|
135
|
+
*
|
|
136
|
+
* It renders **outside** the `<label>` on purpose. A `<label>`'s
|
|
137
|
+
* text content *is* the control's accessible name, so a hint put
|
|
138
|
+
* inside it would be read twice — once as part of the name, once as
|
|
139
|
+
* the description — and a pointer press anywhere on the hint would
|
|
140
|
+
* toggle the box.
|
|
141
|
+
*/
|
|
142
|
+
description?: ReactNode;
|
|
143
|
+
/**
|
|
144
|
+
* The caller's own id, when it has one — a stable target for an
|
|
145
|
+
* autofill hint or a deep link. Left to React's `useId` on the
|
|
146
|
+
* `<input>` otherwise, which is enough for the wrapping `<label>`.
|
|
147
|
+
*/
|
|
148
|
+
id?: string;
|
|
149
|
+
/**
|
|
150
|
+
* **Initial** only. The `<input>` is the store from then on — the
|
|
151
|
+
* DOM owns a checkbox's checkedness, and a controlled `checked`
|
|
152
|
+
* prop is the thing this library refuses to have
|
|
153
|
+
* (`SegmentedControl` says the same about `selectedValue`).
|
|
154
|
+
*/
|
|
155
|
+
isChecked?: boolean;
|
|
156
|
+
isDisabled?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Shows the value at full contrast but refuses to change it — a
|
|
159
|
+
* setting you may read here and edit elsewhere. Distinct from
|
|
160
|
+
* `isDisabled`, which dims: a read-only box is not turned down,
|
|
161
|
+
* because the whole point is that you can still read it. Announced
|
|
162
|
+
* as `aria-readonly`, and the toggle is blocked on both pointer and
|
|
163
|
+
* `Space`.
|
|
164
|
+
*/
|
|
165
|
+
isReadOnly?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* The visible text beside the box, and the checkbox's accessible
|
|
168
|
+
* name — the `<label>` wraps the control, so there is no `for` to
|
|
169
|
+
* get wrong. A box with no label is a control a screen reader
|
|
170
|
+
* cannot announce, which is why this is required.
|
|
171
|
+
*/
|
|
172
|
+
label: ReactNode;
|
|
173
|
+
onChange?: (isChecked: boolean) => void;
|
|
174
|
+
size?: ControlSize;
|
|
175
|
+
/**
|
|
176
|
+
* The `<input>`'s `value` attribute — which member of a group this
|
|
177
|
+
* box IS, as opposed to whether it is ticked.
|
|
178
|
+
*
|
|
179
|
+
* A lone boolean does not need this. A GROUP does: the browser
|
|
180
|
+
* submits `name=value` for each ticked box in a form, and, more
|
|
181
|
+
* relevantly here, a group is normally read back with one query —
|
|
182
|
+
* `[...root.querySelectorAll("input")].filter(i => i.checked)
|
|
183
|
+
* .map(i => i.value)`. Without a `value` every box in the group
|
|
184
|
+
* reports the string `"on"` and the read is useless, which is why
|
|
185
|
+
* queuepilot's library and ratings pickers were still hand-rolling
|
|
186
|
+
* a raw `<input type="checkbox">` rather than adopting this
|
|
187
|
+
* component.
|
|
188
|
+
*
|
|
189
|
+
* Passed straight through and otherwise inert. It is NOT the
|
|
190
|
+
* checked state and does not become one: `isChecked` still seeds
|
|
191
|
+
* the box, and `onChange` still reports a boolean.
|
|
192
|
+
*/
|
|
193
|
+
value?: string;
|
|
194
|
+
};
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
[Full declarations](../../dist/Checkbox/Checkbox.d.ts)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# ColorPicker
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { ColorPicker } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
A named color from the app's list, or a color of the person's own. The presets are a
|
|
8
|
+
searchable `Combobox`, each row a `Swatch` and its name; an optional **Custom color…** row
|
|
9
|
+
opens a panel with the browser's color wheel and a hex field.
|
|
10
|
+
|
|
11
|
+
## When to use it, and when not
|
|
12
|
+
|
|
13
|
+
| You have | Use |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| A palette the **app** owns, maybe plus colors a person makes up | `ColorPicker` |
|
|
16
|
+
| A choice from the library's ten `categorical` hues | A row of `Swatch` buttons over `--color-categorical-<n>-solid`, as Docket's `CategoricalPicker` does |
|
|
17
|
+
| A color that arrived from the world and is only shown | `Swatch` |
|
|
18
|
+
|
|
19
|
+
The presets are data, so the result is a `Swatch`-class color, not a token: it does not
|
|
20
|
+
re-theme and the library cannot contrast-check it. That is why `getColorError` exists. The
|
|
21
|
+
app knows where the color is drawn and what it has to clear; the component only shows the
|
|
22
|
+
app's sentence and refuses to apply.
|
|
23
|
+
|
|
24
|
+
## Typing narrows the list
|
|
25
|
+
|
|
26
|
+
A palette worth offering is long, and siblings may all want a different pink. Typing a name
|
|
27
|
+
narrows the rows to that family; typing a hex code finds its preset. The **Custom color…**
|
|
28
|
+
row is always listed, whatever the search says, and a valid code in the search opens the
|
|
29
|
+
custom panel on that code.
|
|
30
|
+
|
|
31
|
+
## The custom panel
|
|
32
|
+
|
|
33
|
+
The browser's `<input type="color">` is allowed here and only here. It is the custom
|
|
34
|
+
**mode**, inside a panel this component owns — never the whole picker. The wheel, the
|
|
35
|
+
eyedropper, and the sliders are worth keeping, and the presets are what the native control
|
|
36
|
+
alone could never offer.
|
|
37
|
+
|
|
38
|
+
Nothing is applied while a person drags the wheel. The panel holds a draft: **Use color** or
|
|
39
|
+
Enter applies it, and Escape or **Cancel** drops it. A custom color answers `#RRGGBB` in
|
|
40
|
+
upper case, so the app stores one spelling for one color.
|
|
41
|
+
|
|
42
|
+
## The trigger says the name, or the code
|
|
43
|
+
|
|
44
|
+
`"Color: Hot Pink"` for a preset and `"Color: #C2185B"` for a custom color. The visible text
|
|
45
|
+
is in the accessible name (WCAG 2.5.3), as with `Picker`. Query it as:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
getByRole("button", { name: /^Color: / })
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Inside a `Field`
|
|
52
|
+
|
|
53
|
+
`Field` clones its `id` and `aria-describedby` onto the trigger button, and the trigger
|
|
54
|
+
stretches to the container with the swatch and name at the start and the chevron at the end.
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { useState } from "react"
|
|
58
|
+
|
|
59
|
+
function AccentPicker() {
|
|
60
|
+
const [colour, setColour] = useState("#1565c0")
|
|
61
|
+
return <ColorPicker label="Accent" value={colour} onChange={setColour}
|
|
62
|
+
presets={[{ name: "Blue", value: "#1565c0" }]} />
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Published TypeScript API
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const ColorPicker: ({ className, getColorError, isCustomAllowed, isDisabled, label, onChange, placeholder, presets, searchPlaceholder, size, value, ...buttonProps }: ColorPickerProps) => ReactNode
|
|
70
|
+
|
|
71
|
+
type ColorPickerProps = Omit<ComponentPropsWithRef<"button">, "color" | "disabled" | "onChange" | "value"> & {
|
|
72
|
+
/**
|
|
73
|
+
* Shown under a custom draft when the app refuses it, and the reason
|
|
74
|
+
* **Use color** stays disabled. Answer `null` to accept. It is asked
|
|
75
|
+
* of custom colors only: the presets are the app's own list, so it
|
|
76
|
+
* already vetted them.
|
|
77
|
+
*/
|
|
78
|
+
getColorError?: (hex: string) => null | string;
|
|
79
|
+
/** Adds the "Custom color…" row and the custom panel it opens. */
|
|
80
|
+
isCustomAllowed?: boolean;
|
|
81
|
+
isDisabled?: boolean;
|
|
82
|
+
/** What the color is FOR — "Second's color". Not the current value. */
|
|
83
|
+
label: string;
|
|
84
|
+
/**
|
|
85
|
+
* A preset answers its own `value`, as written. A custom color
|
|
86
|
+
* answers `#RRGGBB` in upper case.
|
|
87
|
+
*/
|
|
88
|
+
onChange: (hex: string) => void;
|
|
89
|
+
/** Read by the trigger when there is no value yet. */
|
|
90
|
+
placeholder?: string;
|
|
91
|
+
presets: readonly ColorPreset[];
|
|
92
|
+
/** The search field's hint. */
|
|
93
|
+
searchPlaceholder?: string;
|
|
94
|
+
size?: ControlSize;
|
|
95
|
+
value?: string;
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
[Full declarations](../../dist/ColorPicker/ColorPicker.d.ts)
|