@charcuterie/ui 4.29.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/dist/CatalogPicker/CatalogPicker.d.ts +7 -2
- package/dist/CatalogPicker/CatalogPicker.d.ts.map +1 -1
- package/dist/CatalogPicker/CatalogPicker.js +6 -3
- package/dist/CatalogPicker/CatalogPicker.js.map +1 -1
- package/dist/CatalogPicker/CatalogPickerOption.d.ts +1 -1
- package/dist/CatalogPicker/CatalogPickerOption.d.ts.map +1 -1
- package/dist/CatalogPicker/CatalogPickerOption.js +5 -4
- package/dist/CatalogPicker/CatalogPickerOption.js.map +1 -1
- package/dist/CatalogPicker/catalogPickerView.d.ts +13 -1
- package/dist/CatalogPicker/catalogPickerView.d.ts.map +1 -1
- package/dist/CatalogPicker/catalogPickerView.js +10 -0
- package/dist/CatalogPicker/catalogPickerView.js.map +1 -1
- 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/CatalogPicker/CatalogPicker.mdx +36 -1
- package/src/CatalogPicker/CatalogPicker.test.tsx +264 -24
- package/src/CatalogPicker/CatalogPicker.tsx +14 -3
- package/src/CatalogPicker/CatalogPickerOption.tsx +19 -6
- package/src/CatalogPicker/catalogPickerView.test.ts +19 -0
- package/src/CatalogPicker/catalogPickerView.ts +20 -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,65 @@
|
|
|
1
|
+
# EmptyState
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { EmptyState } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
**Six repos, eleven-plus copies** — plex-channels alone has five `li.empty`s and castkit
|
|
8
|
+
six `.idle`s. Every copy is a bare string in a `<div>`, so "no results", "not started yet",
|
|
9
|
+
and "the socket died" all look identical and none of them is findable by role.
|
|
10
|
+
|
|
11
|
+
Designed fresh rather than ported: the two repos that had a real `EmptyState` with typed
|
|
12
|
+
variants were bambuddy and spoolbuddy, which are upstream projects rather than Kevin's
|
|
13
|
+
code, so that evidence was withdrawn from the plan.
|
|
14
|
+
|
|
15
|
+
## Why there is no `variant`
|
|
16
|
+
|
|
17
|
+
"Empty" and "failed" differ in wording and in whether there is a retry button — both props
|
|
18
|
+
already. A `variant="error"` that only changes a colour invites callers to encode the
|
|
19
|
+
meaning in the colour alone, which is the one thing a colour cannot carry.
|
|
20
|
+
|
|
21
|
+
## The heading is the handle
|
|
22
|
+
|
|
23
|
+
`headingLevel` is the caller's, because only the caller knows what this sits under. A real
|
|
24
|
+
heading makes `getByRole("heading", { name: "No discs queued" })` work, where `getByText`
|
|
25
|
+
against eleven copies of "Nothing here" does not.
|
|
26
|
+
|
|
27
|
+
The `md` size gains air past `--cq-md`, so the same component is tight in a 15rem sidebar
|
|
28
|
+
and generous filling a dashboard — decided by the panel, not the window.
|
|
29
|
+
|
|
30
|
+
## Example from the stories
|
|
31
|
+
|
|
32
|
+
See the full [story example](../../src/EmptyState/EmptyState.stories.tsx).
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
<EmptyState heading="No discs queued" />
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Published TypeScript API
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const EmptyState: ({ action, className, description, heading, headingLevel, icon, size, ...divProps }: EmptyStateProps) => ReactNode
|
|
42
|
+
|
|
43
|
+
type EmptyStateProps = Omit<ComponentPropsWithRef<"div">, "children"> & {
|
|
44
|
+
/** Buttons, usually. Rendered under the description. */
|
|
45
|
+
action?: ReactNode;
|
|
46
|
+
description?: ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* A real heading element, and the level is the caller's because
|
|
49
|
+
* only the caller knows what it sits under. Getting this wrong
|
|
50
|
+
* breaks a screen reader's document outline, which is how the
|
|
51
|
+
* fleet's `<h2>`-with-a-`<button>`-inside pattern happened.
|
|
52
|
+
*
|
|
53
|
+
* The full `2–6` range because the cap is a guess about document
|
|
54
|
+
* structure the consumer knows better than we do — an empty state
|
|
55
|
+
* nested inside an already-deep section needs `5` or `6`, and
|
|
56
|
+
* `` `h${headingLevel}` `` never cared about the upper bound.
|
|
57
|
+
*/
|
|
58
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
59
|
+
heading: string;
|
|
60
|
+
icon?: ReactNode;
|
|
61
|
+
size?: EmptyStateSize;
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
[Full declarations](../../dist/EmptyState/EmptyState.d.ts)
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# Field
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Field } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Use Field to give one input a label, description, and validation error. Use FieldGroup for controls that share a legend.
|
|
8
|
+
|
|
9
|
+
Sixteen files in the fleet spell a label, a control, and a hint, and no two spell the
|
|
10
|
+
wiring the same way.
|
|
11
|
+
|
|
12
|
+
An earlier version of this page said mux-magic's `FieldLabel` renders a `<label>` with
|
|
13
|
+
**no `htmlFor`**. That is false, and worth correcting rather than quietly deleting: it
|
|
14
|
+
renders ``htmlFor={`${stepId}-${field.name}`}``, and has since it was written. The defect
|
|
15
|
+
is at the *other* end of the pair — **8 of its 16 call sites never render that id on
|
|
16
|
+
anything**. Measured on `mux-magic@master`, the eight that do are `BooleanField`,
|
|
17
|
+
`ChapterSplitsField`, `EnumField`, `NumberField`, `NumberWithLookupField`, `PathField`,
|
|
18
|
+
`StringArrayField` and `StringField`. Of the rest, `RegexWithFlagsField` mints its own
|
|
19
|
+
`patternId` / `flagsId` / `sampleId` and `SubtitleRulesField` spells
|
|
20
|
+
``${step.command}-hasDefaultRules`` where the label says ``${step.id}-…``.
|
|
21
|
+
|
|
22
|
+
The outcome is the same unnamed textbox by a worse route: a `<label>` pointing at an id
|
|
23
|
+
that is nowhere in the document reads as correct in the label's own file, and is only
|
|
24
|
+
wrong in the *other* file. Half of them are broken and nothing says which half. That is
|
|
25
|
+
the argument for a component rather than a convention — here the id is minted and consumed
|
|
26
|
+
in one place and cannot be spelled twice.
|
|
27
|
+
|
|
28
|
+
`Field` is also how a `Picker` (or `Button`, or an app's own control) sits next to
|
|
29
|
+
its label **without butting against the last word**. Those controls are
|
|
30
|
+
flush — no outer margin — on purpose. The stacked `gap-1.5` here is the
|
|
31
|
+
gutter. An inline label + trigger is a row with `gap-*`, not a margin
|
|
32
|
+
on the control. See Picker.
|
|
33
|
+
|
|
34
|
+
## The control is a slot
|
|
35
|
+
|
|
36
|
+
Cloned, not wrapped — the same contract as `Popover`'s trigger. An `<input>`, a
|
|
37
|
+
`<textarea>`, a `Picker`, or an app's own control all go in the same hole, and the `id`,
|
|
38
|
+
`aria-describedby`, `aria-invalid` and `required` are injected onto whatever arrives.
|
|
39
|
+
|
|
40
|
+
## A slot is a pass-through
|
|
41
|
+
|
|
42
|
+
Which is a rule this component needed and did not have. `Field` and `Tooltip` both clone
|
|
43
|
+
onto their single child, so the obvious thing to write —
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
— handed `id`, `aria-describedby`, `aria-invalid` and `required` to the **`Tooltip`
|
|
48
|
+
component**, which declares none of them. `cloneElement` does not care. React drops all
|
|
49
|
+
four without a warning, TypeScript never sees it (`Children.only` returns a `ReactElement`
|
|
50
|
+
whose props are `any`), every test still passed, and the render was pixel-identical. The
|
|
51
|
+
only symptom was a `<label htmlFor>` pointing at an id nowhere in the document — the exact
|
|
52
|
+
defect above, reproduced by the component built to prevent it, and this time by the
|
|
53
|
+
library rather than by a consumer.
|
|
54
|
+
|
|
55
|
+
**Silent prop-dropping is the worst version of this**, so anything a slot receives from
|
|
56
|
+
above is forwarded to the child it clones onto, and a chain of slots behaves like the one
|
|
57
|
+
control at the bottom of it. `aria-describedby` — the one prop that is a *list* — is
|
|
58
|
+
merged rather than overwritten, outer first.
|
|
59
|
+
|
|
60
|
+
It works in both orders, and the second is not symmetrical: a `Tooltip` around a `Field`
|
|
61
|
+
hands down not one attribute but a working component — floating-ui's hover, focus and
|
|
62
|
+
dismiss handlers and `refs.setReference`. Those reach the control too, or the tip is a
|
|
63
|
+
floating node with no trigger and no anchor.
|
|
64
|
+
|
|
65
|
+
## Where a prop lands
|
|
66
|
+
|
|
67
|
+
`FieldProps` and `FieldGroupProps` were **closed** types until 2026-08-21: the only prop a
|
|
68
|
+
caller could legally pass was `className`. That is the sharpest argument for opening them —
|
|
69
|
+
a component whose whole purpose is *configured by props, not a borrowed class* accepted only
|
|
70
|
+
the escape hatch that rule exists to close, so it forced the very thing the rule forbids.
|
|
71
|
+
queuepilot paid for it twice in one modal: a `FieldGroup` that gave up the `id` its
|
|
72
|
+
screenshot suite drives by, and a box beside it that stayed a hand-rolled `<fieldset>`
|
|
73
|
+
because it needed `hidden`.
|
|
74
|
+
|
|
75
|
+
The rule that opens them is one sentence — **a component's props land on the element it
|
|
76
|
+
owns** — and it reads differently in each component because they own different elements:
|
|
77
|
+
|
|
78
|
+
| | `Field` | `FieldGroup` |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| Renders | `<div>` around a **cloned** child | a `<fieldset>` around children rendered as-is |
|
|
81
|
+
| Rest props land on | the **control** | the **`<fieldset>`** |
|
|
82
|
+
| `className` lands on | the `<div>` | the `<fieldset>` |
|
|
83
|
+
| So you can pass | `name`, `placeholder`, `autoFocus`, `aria-*`, `ref` | `id`, `hidden`, `ref`, and `disabled` / `form` / `name` |
|
|
84
|
+
|
|
85
|
+
`Field`'s destination is not a new one, it is the existing one finally declared: the runtime
|
|
86
|
+
already spread everything it received into the clone, and `id` has named the control since
|
|
87
|
+
the component shipped. Routing the rest to the `<div>` would have moved that `id`, silently,
|
|
88
|
+
in every consumer.
|
|
89
|
+
|
|
90
|
+
It also could not have been done safely. A slot is a pass-through and **cannot tell who
|
|
91
|
+
wrote a prop** — a `Tooltip` above hands down `getReferenceProps()`, and the author types on
|
|
92
|
+
the same object. Holding the author's props back at the `<div>` needs a closed runtime
|
|
93
|
+
allow-list, and an allow-list is `FieldTooltip`'s silent drop rebuilt inside the fix for it:
|
|
94
|
+
the first slot that writes an `aria-expanded` breaks, and nothing says so.
|
|
95
|
+
|
|
96
|
+
So a caller who wants a handle on the **box** — an `id` for a screenshot, a `hidden` that
|
|
97
|
+
takes the label with it — wants `FieldGroup`. It wraps rather than clones, so its props have
|
|
98
|
+
nowhere else to go.
|
|
99
|
+
|
|
100
|
+
`disabled` on a `<fieldset>` is worth knowing before reaching for it: the platform disables
|
|
101
|
+
every control inside the element, not just the box. That is usually what a caller means, and
|
|
102
|
+
it is something a `<div>`-based group could not have offered at all.
|
|
103
|
+
|
|
104
|
+
## Several controls are a `FieldGroup`, not a `Field`
|
|
105
|
+
|
|
106
|
+
`Field` mints one id and clones it onto one child. An `id` names one element and a
|
|
107
|
+
`<label htmlFor>` points at one, so the moment there are two controls the label names one
|
|
108
|
+
of them and leaves the rest anonymous. Six of mux-magic's sixteen field components are in
|
|
109
|
+
that position — `RegexWithFlagsField` (pattern, flags, sample, and a checkbox),
|
|
110
|
+
`NumberWithLookupField`, `LanguageCodeField`, `LanguageCodesField`, `SubtitleTypesField`
|
|
111
|
+
and `RenameRegexField`.
|
|
112
|
+
|
|
113
|
+
`FieldGroup` renders `<fieldset>` + `<legend>` and does **not** clone. This is the one
|
|
114
|
+
place in the library where `<fieldset>` is right: `AccordionSection` rejected it for its
|
|
115
|
+
panel precisely because that element means *form-control grouping*, and here the content
|
|
116
|
+
really is one. `<legend>` names the group natively, so no `role="group"` and no
|
|
117
|
+
`aria-labelledby`.
|
|
118
|
+
|
|
119
|
+
What a group cannot carry is `aria-invalid`, which has no group form — it belongs on the
|
|
120
|
+
control that is actually invalid, and a `FieldGroup` does not know which one that is. So
|
|
121
|
+
`error` here is **described, not asserted**: it joins the `<fieldset>`'s
|
|
122
|
+
`aria-describedby`. Cloning `aria-invalid` onto every child would mark the valid ones
|
|
123
|
+
invalid. A control that is itself invalid says so in its own `Field`.
|
|
124
|
+
|
|
125
|
+
## `createLinkedIds` is *not* here, and that is the finding
|
|
126
|
+
|
|
127
|
+
The plan expected `useLinkedIds` to do this wiring. It does not fit, for the same reason it
|
|
128
|
+
did not fit `Tabs`: that kind exists for a **dynamic** pairing, where the registration
|
|
129
|
+
multiset is what stops an `aria-describedby` naming a node React has already removed.
|
|
130
|
+
|
|
131
|
+
A field renders its own description and its own error, so it knows *at render* which exist.
|
|
132
|
+
The ids come from one `useUniqueId` and a conditional join, and they cannot get out of step
|
|
133
|
+
at all.
|
|
134
|
+
|
|
135
|
+
That leaves `createLinkedIds` with **no consumer in this package across twenty-five
|
|
136
|
+
components**. It is the one state kind the component layer has never needed, and saying so
|
|
137
|
+
is more useful than manufacturing a use for it.
|
|
138
|
+
|
|
139
|
+
## One source of invalidity
|
|
140
|
+
|
|
141
|
+
There is no `isInvalid` prop. `error` being present *is* the invalidity:
|
|
142
|
+
|
|
143
|
+
| `error` | `aria-invalid` | `aria-describedby` |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| absent | not set | description only, if any |
|
|
146
|
+
| present | `"true"` | description then error |
|
|
147
|
+
|
|
148
|
+
Two props for one fact is how a control ends up `aria-invalid="true"` with nothing saying
|
|
149
|
+
why — which is what `RegexWithFlagsField` does in mux-magic today.
|
|
150
|
+
|
|
151
|
+
## The error is *described*, not announced
|
|
152
|
+
|
|
153
|
+
No `role="alert"` and no live region, deliberately. An error bound through
|
|
154
|
+
`aria-describedby` is read when the control takes focus — which is when the user can act on
|
|
155
|
+
it. A live region on the same text announces it a second time, from nowhere, while the caret
|
|
156
|
+
is somewhere else.
|
|
157
|
+
|
|
158
|
+
A form that fails on submit should say so **once, at the top**, with the `Alert` this
|
|
159
|
+
library already ships. Then the user tabs into the field and hears the specific reason.
|
|
160
|
+
`ToastRegion` draws the same line for the same reason.
|
|
161
|
+
|
|
162
|
+
## Order is behaviour
|
|
163
|
+
|
|
164
|
+
`aria-describedby` is read in sequence, so description comes before error:
|
|
165
|
+
|
|
166
|
+
> "Absolute paths only. That path is not writable."
|
|
167
|
+
|
|
168
|
+
reads correctly; its reverse does not. Nothing enforces this but the order of one array in
|
|
169
|
+
the component, which is why that array is not built from an object.
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
<Field label="Project name" isRequired><input name="project" /></Field>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Published TypeScript API
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
const Field: ({ children, className, description, error, isRequired, label, ...receivedSlotProps }: FieldProps) => ReactNode
|
|
179
|
+
|
|
180
|
+
type FieldProps = ForwardedControlProps & SlotProps & {
|
|
181
|
+
/**
|
|
182
|
+
* The control. **Cloned, not wrapped** — the same slot contract
|
|
183
|
+
* as `Popover`'s trigger, so a `Field` can go around an `<input>`,
|
|
184
|
+
* a `<textarea>`, a `Picker`, or an app's own control without
|
|
185
|
+
* changing that control's layout.
|
|
186
|
+
*/
|
|
187
|
+
children: ReactElement;
|
|
188
|
+
/**
|
|
189
|
+
* The `<div>` around the label, the control and the messages —
|
|
190
|
+
* the one prop that does **not** reach the control.
|
|
191
|
+
*/
|
|
192
|
+
className?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Standing help — units, a format, a warning about what the value
|
|
195
|
+
* does. Announced with the control, before any error.
|
|
196
|
+
*/
|
|
197
|
+
description?: ReactNode;
|
|
198
|
+
/**
|
|
199
|
+
* Present means invalid. There is no separate `isInvalid`, because
|
|
200
|
+
* two sources for one fact is how a control ends up
|
|
201
|
+
* `aria-invalid="true"` with nothing saying why — which is what
|
|
202
|
+
* `RegexWithFlagsField` does in mux-magic today.
|
|
203
|
+
*/
|
|
204
|
+
error?: ReactNode;
|
|
205
|
+
isRequired?: boolean;
|
|
206
|
+
label: ReactNode;
|
|
207
|
+
/**
|
|
208
|
+
* Merged onto the control's own, never replacing it — the wiring
|
|
209
|
+
* rule `mergeSlotWiring` states for every slot.
|
|
210
|
+
*/
|
|
211
|
+
ref?: Ref<HTMLElement>;
|
|
212
|
+
};
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
[Full declarations](../../dist/Field/Field.d.ts)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# FieldGroup
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { FieldGroup } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Group related controls under a single legend. Use `Field` to associate one control with its label, description, and error. Each child still needs its own accessible name.
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { Checkbox } from "@charcuterie/ui"
|
|
11
|
+
|
|
12
|
+
<FieldGroup label="Notifications">
|
|
13
|
+
<Checkbox label="Activity alerts" />
|
|
14
|
+
<Checkbox label="Weekly summary" />
|
|
15
|
+
</FieldGroup>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Published TypeScript API
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const FieldGroup: ({ children, className, description, error, isRequired, label, ...receivedFieldsetProps }: FieldGroupProps) => ReactNode
|
|
22
|
+
|
|
23
|
+
type FieldGroupProps = ComponentPropsWithRef<"fieldset"> & {
|
|
24
|
+
/**
|
|
25
|
+
* The controls. **Rendered as-is, not cloned** — that is the whole
|
|
26
|
+
* difference from `Field`, and it is why this is a separate
|
|
27
|
+
* component rather than a boolean on that one.
|
|
28
|
+
*/
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* The `<fieldset>`, which is also the outermost element this
|
|
32
|
+
* component renders — so `className` is not the exception here that
|
|
33
|
+
* it is on `Field`.
|
|
34
|
+
*/
|
|
35
|
+
className?: string;
|
|
36
|
+
/** Standing help for the group as a whole. */
|
|
37
|
+
description?: ReactNode;
|
|
38
|
+
/** Present means the group is invalid. */
|
|
39
|
+
error?: ReactNode;
|
|
40
|
+
isRequired?: boolean;
|
|
41
|
+
label: ReactNode;
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
[Full declarations](../../dist/Field/FieldGroup.d.ts)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# FileDropZone
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { FileDropZone } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The one drag target in the fleet is gallery-downloader's, and it **gets the hard part
|
|
8
|
+
right** — credit where it is due, and the fix is reproduced here.
|
|
9
|
+
|
|
10
|
+
## Dragging is pointer-only, so the zone is a label around an input
|
|
11
|
+
|
|
12
|
+
There is **no keyboard gesture for drag-and-drop.** WCAG 2.5.7 (AA since 2.2) requires a
|
|
13
|
+
single-pointer alternative for any dragging movement, and the honest one has existed since
|
|
14
|
+
1995: a real `<input type="file">`.
|
|
15
|
+
|
|
16
|
+
So this component is a `<label>` wrapping a visually-hidden input:
|
|
17
|
+
|
|
18
|
+
- the whole zone is the label's click target
|
|
19
|
+
- Tab reaches the input; Space and Enter open the picker
|
|
20
|
+
- the drop handlers are an **enhancement** on a control that already works without them
|
|
21
|
+
|
|
22
|
+
That ordering is the entire design. Building the drop zone first and bolting on an "or
|
|
23
|
+
browse" link is how the fleet's version ended up with an `alert()` as its error channel and
|
|
24
|
+
no keyboard path at all.
|
|
25
|
+
|
|
26
|
+
`sr-only` rather than `display: none` — the clip-rect technique keeps the element focusable,
|
|
27
|
+
which is the whole point of it being there.
|
|
28
|
+
|
|
29
|
+
## The `dragDepth` counter, kept
|
|
30
|
+
|
|
31
|
+
`dragenter` and `dragleave` fire once per **element** the pointer crosses, not once per
|
|
32
|
+
zone. A plain boolean turns the highlight off halfway across the zone and it strobes:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
let dragDepth = 0
|
|
36
|
+
|
|
37
|
+
function handlePageDragEnter() { dragDepth++; if (dragDepth === 1) …on() }
|
|
38
|
+
function handlePageDragLeave() { dragDepth--; if (dragDepth === 0) …off() }
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
That is gallery-downloader's, and it is correct. It lives in a ref here rather than in state,
|
|
42
|
+
because nothing renders from the depth itself — only from whether it is above zero — and a
|
|
43
|
+
re-render per crossed child during a drag is exactly the jank this avoids.
|
|
44
|
+
|
|
45
|
+
## `dragover` must be prevented, and the reason is a footgun
|
|
46
|
+
|
|
47
|
+
A browser's default for `dragover` is **reject the drop**. Not preventing it means `drop`
|
|
48
|
+
never fires — nothing errors, the cursor shows a "no entry" sign, and the zone looks like it
|
|
49
|
+
has a broken handler when it in fact has no handler running at all.
|
|
50
|
+
|
|
51
|
+
## It reports text as well as files
|
|
52
|
+
|
|
53
|
+
Dragging a **link** gives you `text/plain` and an empty `files` list. A zone that only reads
|
|
54
|
+
`.files` silently ignores the single most common thing a user drags into a downloader — and
|
|
55
|
+
gallery-downloader's page is built entirely around `dataTransfer.getData("text")`, never
|
|
56
|
+
looking at `.files` at all.
|
|
57
|
+
|
|
58
|
+
`onDropText` is here rather than being someone's follow-up for exactly that reason: the one
|
|
59
|
+
consumer this component has wants the text path, not the file path.
|
|
60
|
+
|
|
61
|
+
## The input is cleared after every pick
|
|
62
|
+
|
|
63
|
+
A file input keeps its value, so choosing the *same* file twice is not a change and the
|
|
64
|
+
handler never runs. It reads as "it ignored me", and it is the oldest bug in this control.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
function UploadArea({ queueUploads }: { queueUploads: (files: File[]) => void }) {
|
|
68
|
+
return <FileDropZone label="Upload project images" accept="image/*" onDropFiles={queueUploads} />
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Published TypeScript API
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const FileDropZone: ({ accept, className, description, isDisabled, isMultiple, label, onDropFiles, onDropText, }: FileDropZoneProps) => ReactNode
|
|
76
|
+
|
|
77
|
+
type FileDropZoneProps = {
|
|
78
|
+
/** An `accept` list, passed straight to the input. */
|
|
79
|
+
accept?: string;
|
|
80
|
+
className?: string;
|
|
81
|
+
/** Secondary line — the formats taken, a size cap. */
|
|
82
|
+
description?: ReactNode;
|
|
83
|
+
isDisabled?: boolean;
|
|
84
|
+
isMultiple?: boolean;
|
|
85
|
+
/** The control's accessible name, and its visible prompt. */
|
|
86
|
+
label: string;
|
|
87
|
+
onDropFiles: (files: File[]) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Dropped text, when there is any. A browser hands over a dragged
|
|
90
|
+
* link as `text/plain` and no files at all, which is what
|
|
91
|
+
* gallery-downloader's page is built entirely around — it takes
|
|
92
|
+
* `dataTransfer.getData("text")` and never looks at `.files`.
|
|
93
|
+
*/
|
|
94
|
+
onDropText?: (text: string) => void;
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
[Full declarations](../../dist/FileDropZone/FileDropZone.d.ts)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# GroupedList
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { GroupedList } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
An always-open list whose rows sit under group headings. Each row is a label, an optional
|
|
8
|
+
muted description, optional badges, optional richer content, an optional figure beside the
|
|
9
|
+
text, and optional trailing actions. A row can also be the target itself, muted, or
|
|
10
|
+
highlighted.
|
|
11
|
+
|
|
12
|
+
Three apps drew this shape by hand: castkit's page picker (pages under the screen that shows
|
|
13
|
+
them), tally-marks' cards (cards under the team that earns them) and whereabouts' nested
|
|
14
|
+
holdings (things under the place that holds them). The library owns the **shape**. The app
|
|
15
|
+
owns the **data**: the grouping, the search and the filters stay in the app, and a
|
|
16
|
+
`SearchInput` above the list is still the way to narrow it.
|
|
17
|
+
|
|
18
|
+
## A group is a named list, not a landmark
|
|
19
|
+
|
|
20
|
+
The group heading labels the `<ul>` through `aria-labelledby`. A screen reader announces
|
|
21
|
+
"Screens, list, 3 items", and `getByRole("list", { name: "Screens" })` finds the group.
|
|
22
|
+
|
|
23
|
+
There is no `<section>`. A named `<section>` is a `region` landmark, and one screen of pages
|
|
24
|
+
is a dozen groups — the "landmark region proliferation" the APG warns about. `Accordion`'s
|
|
25
|
+
panels are a `group` for the same reason.
|
|
26
|
+
|
|
27
|
+
The heading level is `headingLevel`, `3` by default. A list under a page's `<h2>` needs `3`.
|
|
28
|
+
|
|
29
|
+
## An empty group is not drawn
|
|
30
|
+
|
|
31
|
+
A heading over nothing reads as a bug once a search narrows the list, so the component skips
|
|
32
|
+
a group with no items. When **every** group is empty it draws `emptyState` — usually an
|
|
33
|
+
`EmptyState` whose wording says why.
|
|
34
|
+
|
|
35
|
+
## Long text
|
|
36
|
+
|
|
37
|
+
A long label or description clips to one line. The full text becomes a `title` tooltip only
|
|
38
|
+
while it is clipped, measured the same way `Badge` measures. Pass `isTextTruncated={false}`
|
|
39
|
+
to wrap it instead.
|
|
40
|
+
|
|
41
|
+
## Narrow View
|
|
42
|
+
|
|
43
|
+
The row is a wrapping flex line. The text column asks for 12rem and grows into the rest, so
|
|
44
|
+
the actions sit at the inline end in a wide list and drop under the text in a narrow one.
|
|
45
|
+
There is no container query and no media query: the content decides.
|
|
46
|
+
|
|
47
|
+
## Sticky headings
|
|
48
|
+
|
|
49
|
+
`isHeadingSticky` pins each group's heading to the top of the nearest scrolling ancestor while
|
|
50
|
+
that group's rows scroll under it, and the next group's heading pushes it away. Use it for a
|
|
51
|
+
list inside a scrolling pane, where the heading is the only thing that says which screen or
|
|
52
|
+
team a row belongs to once the row scrolls out of sight. It is off by default.
|
|
53
|
+
|
|
54
|
+
A stuck heading needs an opaque background, or the rows show through it. The component cannot
|
|
55
|
+
know which surface it sits on — a page is `surface-base`, a settings pane is
|
|
56
|
+
`surface-raised` — so the host says so with a custom property:
|
|
57
|
+
|
|
58
|
+
| Property | Default | Set it to |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| `--charcuterie-grouped-list-heading-surface` | `var(--color-surface-base)` | The background of the pane the list sits on. |
|
|
61
|
+
| `--charcuterie-grouped-list-heading-offset` | `0px` | The height of anything already stuck to the top of the same scroll container, such as a sticky `Header`. |
|
|
62
|
+
|
|
63
|
+
Set either one on any ancestor of the list. The names are exported as
|
|
64
|
+
`GROUPED_LIST_HEADING_SURFACE_PROPERTY` and `GROUPED_LIST_HEADING_OFFSET_PROPERTY` for a host
|
|
65
|
+
that sets them through a `style` object.
|
|
66
|
+
|
|
67
|
+
```css
|
|
68
|
+
.settings-panel {
|
|
69
|
+
--charcuterie-grouped-list-heading-surface: var(--color-surface-raised);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## A row can be the target
|
|
74
|
+
|
|
75
|
+
Give an item `onSelect` and the whole row becomes one native `<button>` — "open this card"
|
|
76
|
+
for a list whose primary action is the row itself. `selectLabel` names it (it defaults to
|
|
77
|
+
`label`); name the verb, as with any repeated action: `selectLabel="Edit Water the ferns"`.
|
|
78
|
+
|
|
79
|
+
- **Every state is drawn.** Hover tints the row and rings its edge (only on devices that
|
|
80
|
+
hover, so a tap does not leave a row lit). A press sinks the row slightly, with motion only
|
|
81
|
+
when the user has not asked the OS for less. Keyboard focus draws the focus ring inside the
|
|
82
|
+
row's edge, where the list's rounded corners cannot clip it, and one ring-width in from it,
|
|
83
|
+
so a highlighted row that has focus shows both rings.
|
|
84
|
+
- **The actions stay their own targets.** The button is drawn under the row's text and the
|
|
85
|
+
text lets the pointer through to it; `actions` sit above it. Pressing "Delete" never opens
|
|
86
|
+
the row, and Tab reaches the row, then its actions, then the next row.
|
|
87
|
+
- **Nothing is nested in the button.** It is empty and named by `aria-label`, so `badges`,
|
|
88
|
+
`content` and `aside` must not hold controls — a control belongs in `actions`.
|
|
89
|
+
|
|
90
|
+
`aside` is a figure that belongs **beside** the text — a payout, a total. It asks for at
|
|
91
|
+
least 11rem next to the text column's 12rem, so it sits between the text and the actions in a
|
|
92
|
+
wide list and drops under the text in a narrow one.
|
|
93
|
+
|
|
94
|
+
## Muted and highlighted rows
|
|
95
|
+
|
|
96
|
+
- `isMuted` recedes a row that exists but is switched off: a sunken surface and a quieter
|
|
97
|
+
label. It stays fully operable, and it is a surface and a text role rather than an opacity,
|
|
98
|
+
because a faded row would drop below the AA contrast floor and only a disabled control may.
|
|
99
|
+
Say why in a badge as well ("off").
|
|
100
|
+
- `isHighlighted` rings the row and pulses the ring twice — "this one just changed", after a
|
|
101
|
+
scan or a save. `highlightIntent` picks the colour (`accent` by default). The ring stays
|
|
102
|
+
while the flag does, so the app decides how long it lasts, usually with a timer. **To pulse
|
|
103
|
+
an already-highlighted row again, change its `highlightKey`**, not its `key`. Rows enter,
|
|
104
|
+
leave, and slide by key, so a new `key` would make the row leave while a copy of it
|
|
105
|
+
entered; a new `highlightKey` restarts only the ring's pulse. Under `prefers-reduced-motion` and on ePaper the ring
|
|
106
|
+
does not pulse; it is simply there. The pulse lives in `@charcuterie/ui/styles.css`, which
|
|
107
|
+
every app already imports.
|
|
108
|
+
|
|
109
|
+
## Name a repeated action after its row
|
|
110
|
+
|
|
111
|
+
Ten rows of "Open" are ten buttons an agent cannot tell apart. Give each one a name that
|
|
112
|
+
includes its row — `aria-label="Open Lobby"`.
|
|
113
|
+
|
|
114
|
+
## Not collapsible
|
|
115
|
+
|
|
116
|
+
A group you can close is `Accordion`. `GroupedList` is for a list short enough to read whole
|
|
117
|
+
and long enough to want headings.
|
|
118
|
+
|
|
119
|
+
## Example from the stories
|
|
120
|
+
|
|
121
|
+
See the full [story example](../../src/GroupedList/GroupedList.stories.tsx).
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<GroupedList
|
|
125
|
+
groups={[
|
|
126
|
+
{
|
|
127
|
+
heading: "Label only",
|
|
128
|
+
items: [
|
|
129
|
+
{ key: "alpha", label: "Alpha" },
|
|
130
|
+
{ key: "beta", label: "Beta" },
|
|
131
|
+
],
|
|
132
|
+
key: "plain",
|
|
133
|
+
},
|
|
134
|
+
]}
|
|
135
|
+
size="sm"
|
|
136
|
+
/>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Published TypeScript API
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
const GroupedList: ({ className, emptyState, groups, headingLevel, isHeadingSticky, isTextTruncated, size, }: GroupedListProps) => ReactNode
|
|
143
|
+
|
|
144
|
+
type GroupedListProps = {
|
|
145
|
+
className?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Rendered in place of the groups when **no group has an item** —
|
|
148
|
+
* usually an `EmptyState` whose wording says why (nothing yet, or
|
|
149
|
+
* nothing matches the search). Nothing renders without one.
|
|
150
|
+
*/
|
|
151
|
+
emptyState?: ReactNode;
|
|
152
|
+
groups: readonly GroupedListGroup[];
|
|
153
|
+
/**
|
|
154
|
+
* The level every group heading sits at. A list under a page's
|
|
155
|
+
* `<h2>` needs `3`, which is the default, and getting it wrong is
|
|
156
|
+
* a document-outline break no gate here can see.
|
|
157
|
+
*/
|
|
158
|
+
headingLevel?: GroupedListHeadingLevel;
|
|
159
|
+
/**
|
|
160
|
+
* `true` pins each group's heading to the top of the nearest
|
|
161
|
+
* scrolling ancestor while that group's rows scroll under it, and
|
|
162
|
+
* the next group's heading pushes it away. For a list inside a
|
|
163
|
+
* scrolling pane, where the heading is the only thing that says
|
|
164
|
+
* which screen or team a row belongs to once it scrolls out of
|
|
165
|
+
* sight. `false` (the default) scrolls the heading with its rows.
|
|
166
|
+
*
|
|
167
|
+
* A stuck heading needs an opaque background or the rows show
|
|
168
|
+
* through it, and no one surface fits every host — a page is
|
|
169
|
+
* `surface-base`, a settings pane is `surface-raised`. So the
|
|
170
|
+
* background is read from `--charcuterie-grouped-list-heading-surface`,
|
|
171
|
+
* which falls back to `--color-surface-base`. Set it on any
|
|
172
|
+
* ancestor to match the surface the list sits on. Under a sticky
|
|
173
|
+
* page `Header`, set `--charcuterie-grouped-list-heading-offset`
|
|
174
|
+
* to the header's height so the headings stop below it.
|
|
175
|
+
*/
|
|
176
|
+
isHeadingSticky?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* `true` (the default) clips a long label or description to one
|
|
179
|
+
* line, with the full text as a tooltip while it is clipped.
|
|
180
|
+
* `false` wraps it anywhere instead — for a list whose rows are
|
|
181
|
+
* read rather than scanned.
|
|
182
|
+
*/
|
|
183
|
+
isTextTruncated?: boolean;
|
|
184
|
+
/** `sm` for a settings pane or a sidebar; `md` for a page. */
|
|
185
|
+
size?: GroupedListSize;
|
|
186
|
+
};
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
[Full declarations](../../dist/GroupedList/GroupedList.d.ts)
|