@charcuterie/ui 4.28.3 → 4.29.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 +105 -0
  2. package/dist/CatalogPicker/CatalogPicker.d.ts.map +1 -0
  3. package/dist/CatalogPicker/CatalogPicker.js +152 -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 +42 -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 +173 -0
  26. package/dist/CatalogPicker/catalogPickerView.d.ts.map +1 -0
  27. package/dist/CatalogPicker/catalogPickerView.js +235 -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 +3 -3
  34. package/src/CatalogPicker/CatalogPicker.mdx +157 -0
  35. package/src/CatalogPicker/CatalogPicker.stories.tsx +218 -0
  36. package/src/CatalogPicker/CatalogPicker.test.tsx +1352 -0
  37. package/src/CatalogPicker/CatalogPicker.tsx +376 -0
  38. package/src/CatalogPicker/CatalogPickerMark.tsx +89 -0
  39. package/src/CatalogPicker/CatalogPickerOption.tsx +138 -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 +346 -0
  45. package/src/CatalogPicker/catalogPickerView.ts +457 -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
@@ -1,5 +1,5 @@
1
1
  import { composeStories } from "@storybook/react"
2
- import { expect, waitFor } from "storybook/test"
2
+ import { expect } from "storybook/test"
3
3
  import { test } from "vitest"
4
4
 
5
5
  import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
@@ -7,15 +7,17 @@ import { mountStory } from "../mountStory.testHelpers.ts"
7
7
  import { expectAgentDrivable } from "../testing/index.ts"
8
8
  import * as stories from "./Field.stories.tsx"
9
9
 
10
+ /**
11
+ * The wiring a consumer relies on: ids, `htmlFor`, and where rest
12
+ * props land. What a person hears, the name, description, required,
13
+ * and invalid state, is `REQ-UI-016` to `REQ-UI-027` in
14
+ * `packages/docs/requirements/field.feature`.
15
+ */
10
16
  const {
11
17
  AdoptsChildId,
12
18
  AdoptsOverlayTriggerId,
13
- AllStates,
14
- AllVariants,
15
19
  Playground,
16
20
  ForwardsRestProps,
17
- Group,
18
- Nested,
19
21
  } = composeStories(stories)
20
22
 
21
23
  test("a control's own id is adopted, not overwritten", async () => {
@@ -77,26 +79,6 @@ test("an overlay trigger keeps the id the label points at", async () => {
77
79
  await expectNoAxeViolations(canvasElement)
78
80
  })
79
81
 
80
- test("the label names the control it points at", async () => {
81
- const { canvas, canvasElement } =
82
- await mountStory(Playground)
83
-
84
- // The whole point of the component in one query: the control is
85
- // findable by the *label's* text, which is only true if `htmlFor`
86
- // and the control's `id` agree. mux-magic's `FieldLabel` does
87
- // render a `htmlFor` — 8 of its 16 call sites just never render
88
- // that id on anything, so the pair agrees in one file and not in
89
- // the other, and this query gets nothing.
90
- const control = expectAgentDrivable(canvas, {
91
- name: "Output directory",
92
- role: "textbox",
93
- })
94
-
95
- await expect(control).toHaveAttribute("id")
96
-
97
- await expectNoAxeViolations(canvasElement)
98
- })
99
-
100
82
  /**
101
83
  * Pins a string coupling that lives in two files.
102
84
  *
@@ -132,323 +114,6 @@ test("the label carries a derivable id for non-labelable controls", async () =>
132
114
  await expect(label).toHaveAttribute("for", controlId)
133
115
  })
134
116
 
135
- test("a description is announced with the control", async () => {
136
- const { canvas } = await mountStory(Playground)
137
-
138
- const control = expectAgentDrivable(canvas, {
139
- name: "Output directory",
140
- role: "textbox",
141
- })
142
-
143
- const describedBy = control.getAttribute(
144
- "aria-describedby",
145
- )
146
-
147
- await expect(describedBy).not.toBeNull()
148
-
149
- await expect(
150
- document.getElementById(describedBy ?? ""),
151
- ).toHaveTextContent("Where finished rips are moved.")
152
- })
153
-
154
- test("the slot takes a Picker as readily as an input", async () => {
155
- const { canvas, canvasElement } =
156
- await mountStory(AllVariants)
157
-
158
- // A `Picker` is a `<button>` trigger whose accessible name carries
159
- // the current value, and it is named by the same cloned `id`. The
160
- // slot does not know what it is holding, which is the contract —
161
- // this cell held a native `Select` until that component was
162
- // deprecated.
163
- expectAgentDrivable(canvas, {
164
- name: "Rip profile: Lossless",
165
- role: "button",
166
- })
167
-
168
- await expectNoAxeViolations(canvasElement)
169
- })
170
-
171
- test("`required` is spelled twice, on purpose", async () => {
172
- const { canvas } = await mountStory(AllVariants)
173
-
174
- const control = expectAgentDrivable(canvas, {
175
- name: "Disc label",
176
- role: "textbox",
177
- })
178
-
179
- // `required` is the constraint the browser validates;
180
- // `aria-required` is the one it announces on a control the browser
181
- // does not validate. They are not redundant, and a component that
182
- // sets only the first is silent on a composite widget.
183
- await expect(control).toBeRequired()
184
-
185
- await expect(control).toHaveAttribute(
186
- "aria-required",
187
- "true",
188
- )
189
- })
190
-
191
- test("an error is the only source of invalidity", async () => {
192
- const { canvas, canvasElement } =
193
- await mountStory(AllStates)
194
-
195
- // Valid: nothing claims otherwise.
196
- await expect(
197
- expectAgentDrivable(canvas, {
198
- name: "Bay name",
199
- role: "textbox",
200
- }),
201
- ).not.toHaveAttribute("aria-invalid")
202
-
203
- const invalid = expectAgentDrivable(canvas, {
204
- name: "Scratch path",
205
- role: "textbox",
206
- })
207
-
208
- await expect(invalid).toHaveAttribute(
209
- "aria-invalid",
210
- "true",
211
- )
212
-
213
- await expect(
214
- document.getElementById(
215
- invalid.getAttribute("aria-describedby") ?? "",
216
- ),
217
- ).toHaveTextContent("That path is not writable.")
218
-
219
- await expectNoAxeViolations(canvasElement)
220
- })
221
-
222
- /**
223
- * The nesting defect, and the reason `SlotProps` exists.
224
- *
225
- * `Field` clones onto its one child. With a `Tooltip` in between, the
226
- * child is the **`Tooltip` element**, so `id`, `aria-describedby`,
227
- * `aria-invalid` and `required` were handed to a component that
228
- * declares none of them. `cloneElement` does not care, TypeScript
229
- * never sees it, and the render is pixel-identical — the only
230
- * symptom is a `<label htmlFor>` pointing at an id that is nowhere in
231
- * the document, which is exactly the unnamed textbox this component
232
- * exists to prevent.
233
- *
234
- * The query below is the proof: finding the control **by the label's
235
- * text** is only possible if the `id` reached the `<input>` at the
236
- * bottom of the chain.
237
- */
238
- test("a slot forwards what an outer slot gave it", async () => {
239
- const { canvas, canvasElement } = await mountStory(Nested)
240
-
241
- const control = expectAgentDrivable(canvas, {
242
- name: "Rename pattern",
243
- role: "textbox",
244
- })
245
-
246
- await expect(control).toBeRequired()
247
-
248
- await expect(control).toHaveAttribute(
249
- "aria-required",
250
- "true",
251
- )
252
-
253
- await expect(
254
- document.getElementById(
255
- control.getAttribute("aria-describedby") ?? "",
256
- ),
257
- ).toHaveTextContent("Applied to every title.")
258
-
259
- await expectNoAxeViolations(canvasElement)
260
- })
261
-
262
- /**
263
- * The same drop in reverse — and the half that nearly shipped
264
- * untested.
265
- *
266
- * The first draft of the test above closed with an `aria-invalid`
267
- * assertion on the inner control of the *other* cell and called that
268
- * the reverse case. It is not: `Field` writes `aria-invalid` itself,
269
- * from its own `error` prop, so that assertion holds whether or not a
270
- * single thing arrived from the `Tooltip` above it. Reverting
271
- * `Field`'s half of the fix left the whole file green.
272
- *
273
- * What a `Tooltip` hands down is not one attribute, it is a working
274
- * component: `getReferenceProps()`'s hover, focus and dismiss
275
- * handlers, `refs.setReference`, and an `aria-describedby` naming the
276
- * tip. All of it lands on the `Field` **element**, and `Field` has to
277
- * pass every bit of it through to the control at the bottom or the
278
- * tip is a floating node with no trigger, no anchor and nobody
279
- * pointed at it — mux-magic's `FieldTooltip` defect 1, reproduced by
280
- * a library that shipped the fix for it.
281
- *
282
- * So the assertion is the tip *opening from the inner control's own
283
- * focus* and then being named by it, which needs the handlers, the
284
- * ref and the attribute to have all three arrived.
285
- */
286
- test("a slot forwards what an outer slot gave it, in the other order", async () => {
287
- const { body, canvas } = await mountStory(Nested)
288
-
289
- const control = expectAgentDrivable(canvas, {
290
- name: "Archive path",
291
- role: "textbox",
292
- })
293
-
294
- // Focus on the control, not on the `Field` — `Field` renders a
295
- // `<div>`, which cannot take focus, so a tip that opens here can
296
- // only have been wired to the `<input>`.
297
- control.focus()
298
-
299
- // The tip portals to the body now; the `aria-describedby` link still
300
- // resolves across the boundary, asserted below.
301
- await waitFor(() => {
302
- expect(body.getByRole("tooltip")).toHaveTextContent(
303
- "Where finished rips are moved.",
304
- )
305
- })
306
-
307
- const [tipId, errorId] = (
308
- control.getAttribute("aria-describedby") ?? ""
309
- ).split(" ")
310
-
311
- // Outer first, which here is the tip: the merge order is
312
- // structural — whoever wrapped whom — and the author of the nesting
313
- // is the one who chose it.
314
- await expect(
315
- document.getElementById(tipId ?? ""),
316
- ).toHaveTextContent("Where finished rips are moved.")
317
-
318
- await expect(
319
- document.getElementById(errorId ?? ""),
320
- ).toHaveTextContent("Not writable.")
321
- })
322
-
323
- /**
324
- * `aria-describedby` is the one slot prop that is a **list**, so the
325
- * merge is not last-write-wins. A `Field` names its description and
326
- * its error; a `Tooltip` names its tip. A plain spread keeps one and
327
- * loses the other — the same silent drop by a shorter route.
328
- *
329
- * Outer first: the field's own explanation before the supplementary
330
- * tip.
331
- */
332
- test("a tip is described alongside the field's own text, not instead of it", async () => {
333
- const { body, canvas } = await mountStory(Nested)
334
-
335
- const control = expectAgentDrivable(canvas, {
336
- name: "Rename pattern",
337
- role: "textbox",
338
- })
339
-
340
- control.focus()
341
-
342
- // `useFocus` is what opens it — the line mux-magic's hand-rolled
343
- // tip is missing, and the reason this is testable without a
344
- // pointer at all.
345
- await waitFor(() => {
346
- expect(body.getByRole("tooltip")).toHaveTextContent(
347
- "A JavaScript regular expression.",
348
- )
349
- })
350
-
351
- const [descriptionId, tipId] = (
352
- control.getAttribute("aria-describedby") ?? ""
353
- ).split(" ")
354
-
355
- await expect(
356
- document.getElementById(descriptionId ?? ""),
357
- ).toHaveTextContent("Applied to every title.")
358
-
359
- await expect(
360
- document.getElementById(tipId ?? ""),
361
- ).toHaveTextContent("A JavaScript regular expression.")
362
- })
363
-
364
- /**
365
- * Order inside `aria-describedby` is behaviour, not formatting. A
366
- * screen reader reads the list in sequence, and "absolute paths only
367
- * — that path is not writable" is a different sentence from its
368
- * reverse. Nothing but the order of one array enforces it.
369
- */
370
- test("description is described before error", async () => {
371
- const { canvas } = await mountStory(AllStates)
372
-
373
- const control = expectAgentDrivable(canvas, {
374
- name: "Archive path",
375
- role: "textbox",
376
- })
377
-
378
- const [descriptionId, errorId] = (
379
- control.getAttribute("aria-describedby") ?? ""
380
- ).split(" ")
381
-
382
- await expect(
383
- document.getElementById(descriptionId ?? ""),
384
- ).toHaveTextContent("Absolute paths only.")
385
-
386
- await expect(
387
- document.getElementById(errorId ?? ""),
388
- ).toHaveTextContent("That path is not writable.")
389
- })
390
-
391
- /**
392
- * `Field` cannot go here and the failure is quiet: an `id` names one
393
- * element and a `<label htmlFor>` points at one, so a label over three
394
- * inputs names one of them and leaves the other two anonymous. Six of
395
- * mux-magic's sixteen field components are in exactly that state.
396
- *
397
- * `<fieldset>` + `<legend>` is the platform's answer, and it is the
398
- * one place in this library where the element is right — the content
399
- * really is a form-control grouping.
400
- */
401
- test("a group is named by its legend, and its controls keep their own names", async () => {
402
- const { canvas, canvasElement } = await mountStory(Group)
403
-
404
- const group = expectAgentDrivable(canvas, {
405
- // "Rename pattern", not "Rename pattern *" — the asterisk is
406
- // `aria-hidden`, so it is decoration and stays out of the name.
407
- name: "Rename pattern",
408
- role: "group",
409
- })
410
-
411
- // Every control inside is still individually findable. A group
412
- // that swallows its members' names is the same defect one level up.
413
- for (const name of ["Pattern", "Flags", "Sample"]) {
414
- expectAgentDrivable(canvas, { name, role: "textbox" })
415
- }
416
-
417
- await expect(
418
- document.getElementById(
419
- group.getAttribute("aria-describedby") ?? "",
420
- ),
421
- ).toHaveTextContent("Applied to every title in the disc.")
422
-
423
- await expectNoAxeViolations(canvasElement)
424
- })
425
-
426
- /**
427
- * `aria-invalid` has no group form — it belongs on the control that
428
- * is actually invalid, and a `FieldGroup` does not know which one
429
- * that is. So the error is *described*, not *asserted*, and the
430
- * alternative — cloning `aria-invalid` onto every child — would mark
431
- * the valid ones invalid.
432
- */
433
- test("a group describes its error rather than asserting invalidity", async () => {
434
- const { canvas } = await mountStory(Group)
435
-
436
- const group = expectAgentDrivable(canvas, {
437
- name: "Chapter split",
438
- role: "group",
439
- })
440
-
441
- await expect(group).not.toHaveAttribute("aria-invalid")
442
-
443
- await expect(
444
- document.getElementById(
445
- group.getAttribute("aria-describedby") ?? "",
446
- ),
447
- ).toHaveTextContent(
448
- "A pattern needs at least one capture group.",
449
- )
450
- })
451
-
452
117
  /**
453
118
  * The gap this closes, stated as the two things that were impossible.
454
119
  *
@@ -497,49 +162,6 @@ test("a rest prop reaches the control, not the box around it", async () => {
497
162
  await expectNoAxeViolations(canvasElement)
498
163
  })
499
164
 
500
- /**
501
- * `aria-describedby` is a **list**, and opening the type is what makes
502
- * a caller able to write one at all. A plain spread would keep one
503
- * side and drop the other — the same silent drop `mergeSlotProps`
504
- * exists to prevent between two nested slots, arriving by a shorter
505
- * route now that the outer writer can be the author.
506
- *
507
- * Order is behaviour, not formatting: what the caller passed is the
508
- * outer declaration and reads first, then the field's own description,
509
- * then its error.
510
- */
511
- test("a caller's aria-describedby composes with the description and the error", async () => {
512
- const { canvas } = await mountStory(ForwardsRestProps)
513
-
514
- const control = expectAgentDrivable(canvas, {
515
- name: "Scratch path",
516
- role: "textbox",
517
- })
518
-
519
- const [policyId, descriptionId, errorId] = (
520
- control.getAttribute("aria-describedby") ?? ""
521
- ).split(" ")
522
-
523
- await expect(
524
- document.getElementById(policyId ?? ""),
525
- ).toHaveTextContent("Cleared between runs.")
526
-
527
- await expect(
528
- document.getElementById(descriptionId ?? ""),
529
- ).toHaveTextContent("Absolute paths only.")
530
-
531
- await expect(
532
- document.getElementById(errorId ?? ""),
533
- ).toHaveTextContent("That path is not writable.")
534
-
535
- // The error is still the only source of invalidity, and a caller's
536
- // own description did not disturb it.
537
- await expect(control).toHaveAttribute(
538
- "aria-invalid",
539
- "true",
540
- )
541
- })
542
-
543
165
  /**
544
166
  * The other reading of the same rule. `FieldGroup` renders its
545
167
  * children as-is, so the only element it owns is the `<fieldset>` and
@@ -550,10 +172,8 @@ test("a caller's aria-describedby composes with the description and the error",
550
172
  * This is the case queuepilot's `#dyn-lineup` needed and could not
551
173
  * have: an `id` on the group's own element.
552
174
  */
553
- test("a rest prop reaches the fieldset, and the fieldset disables what is inside it", async () => {
554
- const { canvas, canvasElement } = await mountStory(
555
- ForwardsRestProps,
556
- )
175
+ test("a rest prop reaches the fieldset", async () => {
176
+ const { canvas } = await mountStory(ForwardsRestProps)
557
177
 
558
178
  const group = expectAgentDrivable(canvas, {
559
179
  name: "Playback",
@@ -567,20 +187,6 @@ test("a rest prop reaches the fieldset, and the fieldset disables what is inside
567
187
 
568
188
  await expect(group.tagName).toBe("FIELDSET")
569
189
 
570
- // The `<legend>` still names the group, and the group's own
571
- // description still reaches it, so the rest props did not overwrite
572
- // the wiring they were spread beside.
573
- await expect(
574
- document.getElementById(
575
- group.getAttribute("aria-describedby") ?? "",
576
- ),
577
- ).toHaveTextContent(
578
- "The whole group is turned off by the element itself.",
579
- )
580
-
581
- await expect(
582
- canvasElement.querySelector("input[type='number']"),
583
- ).toBeDisabled()
584
-
585
- await expectNoAxeViolations(canvasElement)
190
+ // The description and the disabled controls inside are
191
+ // `REQ-UI-027` in `packages/docs/requirements/field.feature`.
586
192
  })
package/src/index.ts CHANGED
@@ -117,6 +117,12 @@ export type {
117
117
  } from "./Card/Card.tsx"
118
118
  export { Card } from "./Card/Card.tsx"
119
119
  export type { CardAccentEdge } from "./Card/cardAccentEdge.ts"
120
+ export type {
121
+ CatalogPickerGroup,
122
+ CatalogPickerItem,
123
+ CatalogPickerProps,
124
+ } from "./CatalogPicker/CatalogPicker.tsx"
125
+ export { CatalogPicker } from "./CatalogPicker/CatalogPicker.tsx"
120
126
  export type { ChartProps } from "./Chart/Chart.tsx"
121
127
  export { Chart } from "./Chart/Chart.tsx"
122
128
  export type { CheckboxProps } from "./Checkbox/Checkbox.tsx"
@@ -629,7 +629,11 @@ test("the barrel is the only place components are re-exported", async () => {
629
629
  // CommandPalette composes Modal and SearchInput into the launcher.
630
630
  // ColorPicker composes Combobox and Swatch with a custom-color panel;
631
631
  // `ColorPickerCustomPanel.tsx` is its member.
632
- expect(componentNames.length).toBe(80)
632
+ // CatalogPicker browses a large catalog by group on a rail, or
633
+ // searches all of it; `CatalogPickerPanel.tsx`, `CatalogPickerRail.tsx`,
634
+ // `CatalogPickerOption.tsx`, `CatalogPickerMark.tsx`,
635
+ // `catalogPickerView.ts` and `catalogPickerDrawings.tsx` are its members.
636
+ expect(componentNames.length).toBe(81)
633
637
 
634
638
  for (const name of componentNames) {
635
639
  expect(barrel).toContain(`export { ${name} }`)