@charcuterie/ui 4.28.4 → 4.30.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 (49) hide show
  1. package/dist/CatalogPicker/CatalogPicker.d.ts +110 -0
  2. package/dist/CatalogPicker/CatalogPicker.d.ts.map +1 -0
  3. package/dist/CatalogPicker/CatalogPicker.js +155 -0
  4. package/dist/CatalogPicker/CatalogPicker.js.map +1 -0
  5. package/dist/CatalogPicker/CatalogPickerMark.d.ts +29 -0
  6. package/dist/CatalogPicker/CatalogPickerMark.d.ts.map +1 -0
  7. package/dist/CatalogPicker/CatalogPickerMark.js +35 -0
  8. package/dist/CatalogPicker/CatalogPickerMark.js.map +1 -0
  9. package/dist/CatalogPicker/CatalogPickerOption.d.ts +40 -0
  10. package/dist/CatalogPicker/CatalogPickerOption.d.ts.map +1 -0
  11. package/dist/CatalogPicker/CatalogPickerOption.js +43 -0
  12. package/dist/CatalogPicker/CatalogPickerOption.js.map +1 -0
  13. package/dist/CatalogPicker/CatalogPickerPanel.d.ts +60 -0
  14. package/dist/CatalogPicker/CatalogPickerPanel.d.ts.map +1 -0
  15. package/dist/CatalogPicker/CatalogPickerPanel.js +409 -0
  16. package/dist/CatalogPicker/CatalogPickerPanel.js.map +1 -0
  17. package/dist/CatalogPicker/CatalogPickerRail.d.ts +50 -0
  18. package/dist/CatalogPicker/CatalogPickerRail.d.ts.map +1 -0
  19. package/dist/CatalogPicker/CatalogPickerRail.js +114 -0
  20. package/dist/CatalogPicker/CatalogPickerRail.js.map +1 -0
  21. package/dist/CatalogPicker/catalogPickerDrawings.d.ts +10 -0
  22. package/dist/CatalogPicker/catalogPickerDrawings.d.ts.map +1 -0
  23. package/dist/CatalogPicker/catalogPickerDrawings.js +29 -0
  24. package/dist/CatalogPicker/catalogPickerDrawings.js.map +1 -0
  25. package/dist/CatalogPicker/catalogPickerView.d.ts +185 -0
  26. package/dist/CatalogPicker/catalogPickerView.d.ts.map +1 -0
  27. package/dist/CatalogPicker/catalogPickerView.js +245 -0
  28. package/dist/CatalogPicker/catalogPickerView.js.map +1 -0
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/CatalogPicker/CatalogPicker.mdx +192 -0
  35. package/src/CatalogPicker/CatalogPicker.stories.tsx +218 -0
  36. package/src/CatalogPicker/CatalogPicker.test.tsx +1592 -0
  37. package/src/CatalogPicker/CatalogPicker.tsx +387 -0
  38. package/src/CatalogPicker/CatalogPickerMark.tsx +89 -0
  39. package/src/CatalogPicker/CatalogPickerOption.tsx +151 -0
  40. package/src/CatalogPicker/CatalogPickerPanel.tsx +780 -0
  41. package/src/CatalogPicker/CatalogPickerRail.tsx +214 -0
  42. package/src/CatalogPicker/catalogPicker.storyHelpers.tsx +276 -0
  43. package/src/CatalogPicker/catalogPickerDrawings.tsx +51 -0
  44. package/src/CatalogPicker/catalogPickerView.test.ts +365 -0
  45. package/src/CatalogPicker/catalogPickerView.ts +476 -0
  46. package/src/Dialog/Dialog.test.tsx +20 -289
  47. package/src/Field/Field.test.tsx +11 -405
  48. package/src/index.ts +6 -0
  49. package/src/sourceRules.test.ts +5 -1
@@ -0,0 +1,192 @@
1
+ import { Canvas, Meta } from "@storybook/addon-docs/blocks"
2
+
3
+ import * as CatalogPickerStories from "./CatalogPicker.stories.tsx"
4
+
5
+ <Meta of={CatalogPickerStories} />
6
+
7
+ # CatalogPicker
8
+
9
+ A picker over a large catalog — forty AI models from six providers, say — that you can
10
+ **browse by group** on a rail or **search across everything** at once.
11
+
12
+ <Canvas of={CatalogPickerStories.Playground} />
13
+
14
+ ## When to use it, and when not
15
+
16
+ | You have | Use |
17
+ | --- | --- |
18
+ | A short list, no typing needed | `Picker` |
19
+ | One flat list that wants a filter | `Combobox` |
20
+ | A long list that falls into groups people think in — providers, accounts, vendors — and whose rows look alike until you read the end | **`CatalogPicker`** |
21
+
22
+ `Picker` has no filter, and `Combobox` filters one flat list with no way to look at just
23
+ one part of it. A catalog of models named "Provider · Model · slug" is exactly where both
24
+ fall short: every row starts the same way, and finding one means reading all of them.
25
+ The rail answers "show me this provider's models", and the search answers "I know the
26
+ name" without making the person know the provider first.
27
+
28
+ ## The shape
29
+
30
+ - **The trigger** shows the chosen item's mark and label, and is named
31
+ `"<label>: <chosen label>"`, as `Picker`'s is, then `", <group label>"` when the chosen
32
+ item's group has a label that is not blank — `"Agent: Lumen 4, Contoso"`. Query it as
33
+ `getByRole("button", { name: /^Agent: / })`.
34
+ - **The rail**, on the inline start: a **Favorites** star first (only when `favorites`
35
+ resolves to at least one item, a pinned one included), then one button per group, in
36
+ `groups` order. A group with no rows is left off. Each button's accessible name and tooltip is the group's
37
+ `label`.
38
+ - **The search field** at the top of the list, then **the list** for the current tab.
39
+ Each row shows the mark, the label, the optional `description`, a small star on a
40
+ favorite, and a check mark on the chosen row. The star and the check are drawn in CSS,
41
+ not typed, because a symbol character renders as nothing where the font lacks it.
42
+ - **Pinned rows** (`pinned: "start"` or `"end"`) appear at the top or bottom of every
43
+ tab and of the search results when they match — a "Default" that belongs to no group.
44
+ - **Ungrouped rows** — `groupId: null`, or a `groupId` that names no group — appear on
45
+ every tab, just after the pinned-start rows, and at the same place in search results.
46
+ No row is ever reachable only by search. Each row is listed once per view: a pinned or
47
+ ungrouped favorite is not listed a second time on the Favorites tab.
48
+
49
+ ### One value, one row
50
+
51
+ Every item's `value` must be unique across the whole catalog, and every group's `id`
52
+ across `groups`. If one repeats, **the first one wins** — in the trigger, the list, the
53
+ check mark and Favorites alike — the later ones are dropped, and the picker logs a
54
+ `console.warn` naming them.
55
+
56
+ ## Searching
57
+
58
+ Typing searches **every item**, whatever tab is current. The match is a case-insensitive
59
+ substring on the label, the description and the group's label, and **every word must
60
+ match**: `work lumen` finds the Lumen rows of the "Contoso (Work)" account and not the
61
+ others. Results sit under one heading per group, in rail order; favorites are found under
62
+ their group, not in a section of their own. While a query is live, no rail button is
63
+ pressed, because no one group is being shown.
64
+
65
+ This is not `CommandPalette`'s word-prefix match. A model's slug (`ct-lumen-4`) and a
66
+ version number (`4.5`) are things people type the middle of.
67
+
68
+ <Canvas of={CatalogPickerStories.AllStates} />
69
+
70
+ ## Opening
71
+
72
+ Every open starts fresh: the query is empty, even when the picker is reopened while the
73
+ last panel is still fading out. The panel opens on **Favorites** when the chosen value is
74
+ a favorite or a row that every tab lists (pinned or ungrouped); otherwise on the **chosen
75
+ row's group**; otherwise on Favorites; otherwise on the first group. The chosen row is
76
+ highlighted and **centred** in the list — the rule a `Combobox` follows when it opens on
77
+ its chosen option. Focus goes to the search field.
78
+
79
+ Disabling an open picker closes it, and enabling it again leaves it closed.
80
+
81
+ ## When the catalog changes while it is open
82
+
83
+ The highlight follows the row's `value`, not its position. If the catalog refreshes and
84
+ the rows move, the same row stays highlighted, so Enter chooses what the person saw. Only
85
+ when that row leaves the view, or becomes disabled, does the highlight move: to the
86
+ chosen row if the view shows it, even during a search, else the first enabled row. Each
87
+ row keeps its own button while a refresh leaves it in the same section, so a click already
88
+ pressed stays on its row. A refresh that moves the row to another section (for example, from
89
+ its group to the pinned rows) cancels that click instead; a click never lands on another row. If a refresh removes the rail
90
+ button that has focus, focus moves to the rail button that takes its place (or to the
91
+ search field), never to the page behind.
92
+
93
+ ## Keyboard
94
+
95
+ | Where | Key | Does |
96
+ | --- | --- | --- |
97
+ | Search | ArrowDown / ArrowUp | Move the highlight, skipping disabled rows |
98
+ | Search | Home / End | Move the caret, as in any text field (and in `Combobox`) |
99
+ | Search | Enter | Choose the highlighted row and close |
100
+ | Search | Escape | Clear the query; on an empty query, close |
101
+ | Search | Tab | To the clear button while it shows, else to the rail; with neither, focus stays |
102
+ | Search | Shift+Tab | To the rail, else to the clear button while it shows |
103
+ | Clear button | Tab / Shift+Tab | To the rail, or the search field with no rail / back to the search field |
104
+ | Clear button | Escape | Clear the query, back in the search field |
105
+ | Rail | ArrowDown / ArrowUp, Home / End | Move between groups (wraps) |
106
+ | Rail | Enter / Space | Show that group |
107
+ | Rail | Tab | Back to the search field |
108
+ | Rail | Shift+Tab | To the clear button while it shows, else the search field |
109
+ | Rail | Escape | As in the search field |
110
+
111
+ Closing with Enter or Escape returns focus to the trigger. The picker consumes every
112
+ Escape it handles, so inside a `Dialog` the first Escape clears, the next closes the
113
+ picker, and the dialog stays open. While an input method editor is composing a word, its
114
+ Enter, Escape and arrows belong to the editor, not the picker.
115
+
116
+ <Canvas of={CatalogPickerStories.Interactive} />
117
+
118
+ ## The ARIA shape, and why the rail is not a `tablist`
119
+
120
+ The trigger opens a `role="dialog"` named by the trigger. The search field is a
121
+ `role="combobox"` that keeps focus and moves `aria-activedescendant` through a
122
+ `role="listbox"` — the `Combobox` contract — and search results are labelled
123
+ `role="group"`s inside that listbox.
124
+
125
+ The rail looks like tabs but is a vertical **`role="toolbar"` of `aria-pressed`
126
+ buttons**. A tablist has to have a selected tab, and while a search runs none of them is
127
+ true; and a tab controls a tab panel, while what the rail changes is a listbox that the
128
+ search field drives too. A toolbar of toggle buttons says what is true — switches that
129
+ change what the list shows — and brings the APG keyboard contract with it: one tab stop,
130
+ the arrows move, Enter and Space press.
131
+
132
+ A mouse click on a rail button does not take focus from the search field, so a person can
133
+ click a group and keep typing or arrowing.
134
+
135
+ ### A row's name says its group
136
+
137
+ The mark beside a row is decorative, so the group is said in words, from its label. A row is named by its
138
+ label, then its description, then its group: `"Lumen 4 ct-lumen-4, Contoso"` and
139
+ `"Lumen 4 Work account, Contoso (Work)"`. Two accounts that both star "Opus" give Favorites
140
+ two rows that look the same and are named apart — `"Opus, Team One"` and
141
+ `"Opus, Team Two"` — and the trigger names the chosen one's group the same way. A row with no
142
+ group, a missing group, or a group whose label is blank has no suffix.
143
+
144
+ The name is an `aria-label`: the row's label and description, in the order the row shows
145
+ them, then the group's label. The mark beside them is decorative, whether it is the group's
146
+ badge or icon or the item's own. It is not a `VisuallyHidden` suffix: an `sr-only` span is
147
+ laid out as a block, so Chromium and Testing Library name the row `"Opus , Team Two"`, with
148
+ a space before the comma, and an exact query misses it.
149
+
150
+ ```ts
151
+ // Testing Library matches a string name whole.
152
+ getByRole("option", { name: "Opus, Team Two" })
153
+ getByRole("button", { name: "Agent: Opus, Team Two" })
154
+
155
+ // Playwright matches a substring unless told otherwise: "Opus, Team Two" would also find
156
+ // "Opus, Team Two Work".
157
+ page.getByRole("option", { exact: true, name: "Opus, Team Two" })
158
+ ```
159
+
160
+ The group usually tells same-label rows in differently labelled groups apart. It does not
161
+ make every name unique: two names collide whenever their whole text matches, and a label,
162
+ description, or group label can contain any text, commas included. A catalog that needs
163
+ unique names checks the whole names. Two groups both
164
+ labelled `"Work"` make two `"Opus, Work"` rows; `"Opus"` with the description `"Preview"`
165
+ reads the same as `"Opus Preview"` with none; and an ungrouped `"Opus, Team Two"` reads the
166
+ same as `"Opus"` in Team Two. The trigger does not say the description, so give such rows,
167
+ or their groups, distinct labels. A blank group label or description adds nothing to a name.
168
+
169
+ ## Icons, badges and accent colors
170
+
171
+ Charcuterie ships no icons. Pass the app's own provider logos as `icon` on a group (or on
172
+ one item, to override its group's). A group without an icon gets an **initials badge**:
173
+ the first letter of its first two words, so "Tailspin Labs" is "TL".
174
+
175
+ `accentColor` (any CSS color) draws a **ring** around the mark. It is how two accounts of
176
+ one provider are told apart. It is never the fill behind text or the text itself, so a
177
+ consumer's color cannot fail the contrast gate.
178
+
179
+ ## Sizes and narrow windows
180
+
181
+ `size` sets the trigger and every row in the panel, as a `Combobox`'s `itemSize` sets its
182
+ search field and its options; a short window steps the rows down on its own. The panel is
183
+ 26rem wide and 28rem tall, capped to the space the window leaves, so on a 384px phone the
184
+ rail stays and the list narrows beside it.
185
+
186
+ <Canvas of={CatalogPickerStories.Responsive} />
187
+
188
+ ## Not windowed
189
+
190
+ Every row of the current view renders. `Combobox` windows only above 100 rows and the
191
+ catalogs this was built for are 40 to 60. A catalog large enough to need windowing is a
192
+ change to this component, not a prop.
@@ -0,0 +1,218 @@
1
+ import { playgroundParameters } from "@charcuterie/storybook-config/story-parameters"
2
+ import type { Meta, StoryObj } from "@storybook/react"
3
+
4
+ import {
5
+ controlSizeArgType,
6
+ placementArgType,
7
+ } from "../argTypes.storyHelpers.ts"
8
+ import {
9
+ ContainerBoard,
10
+ StoryCell,
11
+ StoryGrid,
12
+ StoryRow,
13
+ StorySection,
14
+ } from "../board.storyHelpers.tsx"
15
+ import { Field } from "../Field/Field.tsx"
16
+ import { CatalogPicker } from "./CatalogPicker.tsx"
17
+ import {
18
+ CATALOG_FAVORITES,
19
+ CATALOG_GROUPS,
20
+ CATALOG_ITEMS,
21
+ CatalogPickerHarness,
22
+ ClearIcon,
23
+ InlineCatalogPanel,
24
+ } from "./catalogPicker.storyHelpers.tsx"
25
+
26
+ const meta = {
27
+ title: "Components/Controls/CatalogPicker",
28
+ component: CatalogPicker,
29
+ parameters: { layout: "padded" },
30
+ argTypes: {
31
+ placement: placementArgType,
32
+ size: controlSizeArgType,
33
+ },
34
+ args: {
35
+ clearIcon: <ClearIcon />,
36
+ favorites: CATALOG_FAVORITES,
37
+ groups: CATALOG_GROUPS,
38
+ items: CATALOG_ITEMS,
39
+ label: "Agent",
40
+ onChange: () => undefined,
41
+ searchPlaceholder: "Search models…",
42
+ value: "contoso/ct-lumen-4",
43
+ },
44
+ } satisfies Meta<typeof CatalogPicker>
45
+
46
+ export default meta
47
+
48
+ type Story = StoryObj<typeof meta>
49
+
50
+ /**
51
+ * Forty-odd invented models across six groups, with four favorites
52
+ * and a pinned "Default". Open it, browse a group on the rail, or type
53
+ * to search all of them at once.
54
+ */
55
+ export const Playground: Story = {
56
+ parameters: playgroundParameters,
57
+ render: (args) => (
58
+ <CatalogPickerHarness
59
+ favorites={args.favorites}
60
+ groups={args.groups}
61
+ initialValue={args.value}
62
+ isDisabled={args.isDisabled}
63
+ items={args.items}
64
+ label={args.label}
65
+ placeholder={args.placeholder}
66
+ size={args.size}
67
+ />
68
+ ),
69
+ }
70
+
71
+ /**
72
+ * The trigger at each size, with an icon, with an initials badge, with
73
+ * the accent ring of a second account, and with nothing chosen.
74
+ */
75
+ export const AllVariants: Story = {
76
+ render: () => (
77
+ <StoryGrid columns={3}>
78
+ {(["sm", "md", "lg"] as const).map((size) => (
79
+ <StoryCell key={size} label={`size="${size}"`}>
80
+ <CatalogPickerHarness
81
+ initialValue="northwind/nw-swift-3"
82
+ label={`Agent ${size} icon`}
83
+ size={size}
84
+ />
85
+ <CatalogPickerHarness
86
+ initialValue="tailspin/ts-glide-2"
87
+ label={`Agent ${size} badge`}
88
+ size={size}
89
+ />
90
+ <CatalogPickerHarness
91
+ initialValue="contoso-work/ct-lumen-4"
92
+ label={`Agent ${size} accent`}
93
+ size={size}
94
+ />
95
+ <CatalogPickerHarness
96
+ label={`Agent ${size} empty`}
97
+ placeholder="Choose an agent…"
98
+ size={size}
99
+ />
100
+ </StoryCell>
101
+ ))}
102
+ </StoryGrid>
103
+ ),
104
+ }
105
+
106
+ /**
107
+ * The panel drawn in place, so every state sits on one board: the
108
+ * Favorites tab, a group tab with a disabled row, a search across
109
+ * every group, and a search with no matches. The disabled trigger is
110
+ * last.
111
+ */
112
+ export const AllStates: Story = {
113
+ render: () => (
114
+ <div className="flex flex-col gap-8">
115
+ <StoryRow>
116
+ <StorySection title="Favorites, with the chosen row">
117
+ <InlineCatalogPanel
118
+ label="Favorites panel"
119
+ value="contoso/ct-lumen-4"
120
+ />
121
+ </StorySection>
122
+
123
+ <StorySection title="A group, with a disabled row">
124
+ <InlineCatalogPanel
125
+ label="Group panel"
126
+ value="fabrikam/fb-loom-7"
127
+ />
128
+ </StorySection>
129
+
130
+ <StorySection title="Searching every group">
131
+ <InlineCatalogPanel
132
+ defaultQuery="lumen"
133
+ label="Search panel"
134
+ value="contoso/ct-lumen-4"
135
+ />
136
+ </StorySection>
137
+
138
+ <StorySection title="No matches">
139
+ <InlineCatalogPanel
140
+ defaultQuery="zzz"
141
+ label="Empty panel"
142
+ />
143
+ </StorySection>
144
+ </StoryRow>
145
+
146
+ <StorySection title="Disabled">
147
+ <StoryRow>
148
+ <CatalogPickerHarness
149
+ initialValue="contoso/ct-lumen-4"
150
+ isDisabled
151
+ label="Disabled agent"
152
+ />
153
+ </StoryRow>
154
+ </StorySection>
155
+ </div>
156
+ ),
157
+ }
158
+
159
+ /**
160
+ * Inside a `Field` the trigger stretches to its container, the value
161
+ * at the inline start and the chevron at the inline end; a name wider
162
+ * than the container ends in an ellipsis. The panel is sized against
163
+ * the window, not the container: it caps to the viewport, rail and
164
+ * all, on a 384px phone.
165
+ */
166
+ export const Responsive: Story = {
167
+ render: () => (
168
+ <ContainerBoard>
169
+ {(width) => (
170
+ <div className="flex flex-col gap-4">
171
+ <Field label={`Agent at ${width}`}>
172
+ <CatalogPickerHarness
173
+ initialValue="northwind/nw-swift-3"
174
+ label={`Agent at ${width}`}
175
+ />
176
+ </Field>
177
+ <Field label={`Long agent at ${width}`}>
178
+ <CatalogPickerHarness
179
+ initialValue="tailspin/ts-tailwind-research-preview-with-a-very-long-name"
180
+ label={`Long agent at ${width}`}
181
+ />
182
+ </Field>
183
+ </div>
184
+ )}
185
+ </ContainerBoard>
186
+ ),
187
+ }
188
+
189
+ /**
190
+ * The complete keyboard path. Open with Enter or Space; type to search
191
+ * every group; ArrowUp and ArrowDown move the highlight, Home and End
192
+ * jump; Enter chooses and closes. Tab moves to the rail, where the
193
+ * arrows move between groups and Enter shows one; Tab goes back to the
194
+ * search field. Escape clears a query, then closes and returns focus
195
+ * to the trigger.
196
+ */
197
+ export const Interactive: Story = {
198
+ render: () => (
199
+ <CatalogPickerHarness
200
+ initialValue="northwind/nw-harbor-4"
201
+ label="Agent"
202
+ />
203
+ ),
204
+ }
205
+
206
+ /**
207
+ * No favorites: the rail starts at the first group, and opening lands
208
+ * on the chosen row's group.
209
+ */
210
+ export const WithoutFavorites: Story = {
211
+ render: () => (
212
+ <CatalogPickerHarness
213
+ favorites={[]}
214
+ initialValue="litware/lw-margin-2"
215
+ label="Agent without favorites"
216
+ />
217
+ ),
218
+ }