@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,109 @@
|
|
|
1
|
+
# Listbox
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Listbox } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The single-select **fancy** dropdown — the rich-option sibling of the native
|
|
8
|
+
[`Select`](Select.md), not a replacement for it. `Select` keeps
|
|
9
|
+
type-ahead, Home/End, the mobile wheel picker, form submission, `:invalid` and autofill;
|
|
10
|
+
`Listbox` is for the cases `<option>` cannot render — a leading icon, two lines, a trailing
|
|
11
|
+
badge ([decision](https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-08-03-listbox-and-combobox-are-siblings-of-select.md)).
|
|
12
|
+
|
|
13
|
+
## A listbox is not a menu
|
|
14
|
+
|
|
15
|
+
An `option` **is** something you are choosing; a `menuitem` **does** something. So a
|
|
16
|
+
`Listbox` carries `aria-selected`, it type-aheads (the APG requires it of a listbox and
|
|
17
|
+
`Menu` deliberately omits it), and a screen reader announces "listbox, selected, 2 of 4".
|
|
18
|
+
That is the distinction `Menu` documents from the other side.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Two kinds of state, composed
|
|
23
|
+
|
|
24
|
+
`useRovingFocus` owns which option is tabbable — exactly one, so Tab enters and leaves the
|
|
25
|
+
group once and the arrow keys move within it — and `useSinglePicker` owns which option is
|
|
26
|
+
chosen. They are the same two kinds `Tabs` composes, and they never disturb each other:
|
|
27
|
+
arrowing moves focus without selecting, Enter selects the focused option. A disabled option
|
|
28
|
+
joins the choice but not the focus group, so the arrow keys and type-ahead skip it.
|
|
29
|
+
|
|
30
|
+
## Rich options, and `textValue`
|
|
31
|
+
|
|
32
|
+
The options take a `ReactNode` label — two lines, a flag, an intent-coloured confidence
|
|
33
|
+
badge. When the label is rich, `textValue` is required: it is the type-ahead target and the
|
|
34
|
+
name a screen reader reads, so a picture of a value is still a value you can find by typing.
|
|
35
|
+
|
|
36
|
+
## Portalled, and a plain button opens it
|
|
37
|
+
|
|
38
|
+
The panel portals to `document.body`. The trigger stays a native **button** that gains
|
|
39
|
+
`aria-haspopup="listbox"`, `aria-expanded`, and `aria-controls` — the button-opens-listbox
|
|
40
|
+
pattern, not a `combobox` (that is `Combobox`, where focus stays in a text input). So there
|
|
41
|
+
is no `heading` prop; the button names the widget. The panel height is clamped to the
|
|
42
|
+
viewport by floating-ui's `size` middleware and scrolls within it.
|
|
43
|
+
|
|
44
|
+
## An option is the size of the control that opened it
|
|
45
|
+
|
|
46
|
+
`itemSize` takes the same `sm` / `md` / `lg` a `Button` takes, from the same
|
|
47
|
+
density-aware `--control-height-*` tokens. It **defaults to `md`** — 2.25rem, the height a
|
|
48
|
+
default `Button` and a `Select` already take — so a picker's options measure the same as
|
|
49
|
+
its trigger.
|
|
50
|
+
|
|
51
|
+
That default is a fix, not a preference. The rows were a hardcoded `px-2 py-1.5 text-sm`
|
|
52
|
+
that no control in the library shares, so an option was visibly the smaller thing inside
|
|
53
|
+
its own panel; the owner's report was *"the button is huge, but the options don't match
|
|
54
|
+
it"*.
|
|
55
|
+
|
|
56
|
+
`lg` is the fat one: 2.75rem, the 44px WCAG 2.5.5 target, for a list that is aimed at
|
|
57
|
+
rather than scanned. `sm` is what this component rendered before, kept for a genuinely
|
|
58
|
+
dense list.
|
|
59
|
+
|
|
60
|
+
The floor is a **minimum**, not a fixed height (`min-h-`, where a `Button` uses `h-`) — the
|
|
61
|
+
rich option below, with a flag and a trailing `Badge`, still grows past it.
|
|
62
|
+
|
|
63
|
+
A window shorter than 40rem steps each size down one step on its own, and one shorter than
|
|
64
|
+
30rem takes them to `sm`.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { Button } from "@charcuterie/ui"
|
|
68
|
+
import { useVisibility } from "@charcuterie/logic"
|
|
69
|
+
|
|
70
|
+
function FormatChoice({ choose }: { choose: (key: string) => void }) {
|
|
71
|
+
const { isVisible, show, hide } = useVisibility()
|
|
72
|
+
return <Listbox isVisible={isVisible} onDismiss={hide} onSelect={choose}
|
|
73
|
+
options={[{ label: "Summary", value: "summary" }]}
|
|
74
|
+
trigger={<Button onClick={show}>Report format</Button>} />
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Published TypeScript API
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const Listbox: ({ className, isVisible, itemSize: requestedItemSize, onDismiss, onSelect, options, placement, selectedValue, trigger, }: ListboxProps) => ReactNode
|
|
82
|
+
|
|
83
|
+
type ListboxProps = {
|
|
84
|
+
className?: string;
|
|
85
|
+
isVisible: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* How tall each option is, from the same density-aware tokens a
|
|
88
|
+
* `Button` reads — so a `md` option is exactly as tall as the `md`
|
|
89
|
+
* trigger that opened it. `lg` is the fat one: 2.75rem at
|
|
90
|
+
* `comfortable` density, and a bigger target to aim at.
|
|
91
|
+
*
|
|
92
|
+
* A short window steps it back down on its own
|
|
93
|
+
* (`usePanelItemSize`), so a `lg` list is never the reason the last
|
|
94
|
+
* option is off-screen.
|
|
95
|
+
*/
|
|
96
|
+
itemSize?: ControlSize;
|
|
97
|
+
/** Outside press and Escape both land here. */
|
|
98
|
+
onDismiss: () => void;
|
|
99
|
+
onSelect: (value: string) => void;
|
|
100
|
+
options: readonly ListboxItem[];
|
|
101
|
+
placement?: Placement;
|
|
102
|
+
/** The initial seed. The live selection is the listbox's after that. */
|
|
103
|
+
selectedValue?: string;
|
|
104
|
+
/** The control the listbox hangs off. **Cloned, not wrapped.** */
|
|
105
|
+
trigger: ReactElement;
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
[Full declarations](../../dist/Listbox/Listbox.d.ts)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# LiveStatusIndicator
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { LiveStatusIndicator } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Four repos, four implementations, and **it is the thing users read most** — a wall-mounted
|
|
8
|
+
panel showing stale data under a green dot is worse than one showing nothing.
|
|
9
|
+
|
|
10
|
+
## The distinction all four repos lose
|
|
11
|
+
|
|
12
|
+
`connecting` and `reconnecting` are different states and they are collapsed everywhere
|
|
13
|
+
today. A user who has seen data wants "lost it, getting it back" (amber, moving), not the
|
|
14
|
+
cold-start spinner they already sat through (blue), and not a dead link (red). That is why
|
|
15
|
+
`connectionTransitions` is one of only two machines `@charcuterie/logic` ships rather than
|
|
16
|
+
something each app defines.
|
|
17
|
+
|
|
18
|
+
Wording and colour both come from exhaustive switches over that machine, so adding a fifth
|
|
19
|
+
state stops this package compiling instead of rendering a grey dot.
|
|
20
|
+
|
|
21
|
+
## Accessibility contract
|
|
22
|
+
|
|
23
|
+
- `role="status"` + `aria-live="polite"`, so a transition is announced without interrupting
|
|
24
|
+
what the user is doing. `assertive` would cut off the sentence in progress, and the dot is
|
|
25
|
+
not going anywhere.
|
|
26
|
+
- `aria-label` as well, because a `status` region takes no accessible name from its content
|
|
27
|
+
— that is what makes `getByRole("status", { name: "Connected" })` resolve.
|
|
28
|
+
- Only `connecting` and `reconnecting` animate. A dot that pulses forever is the fleet's
|
|
29
|
+
current "is it alive?" problem in a new costume.
|
|
30
|
+
- `data-status` is the stable handle for a Playwright assertion — it survives translation,
|
|
31
|
+
where the visible wording does not.
|
|
32
|
+
|
|
33
|
+
## Example from the stories
|
|
34
|
+
|
|
35
|
+
See the full [story example](../../src/LiveStatusIndicator/LiveStatusIndicator.stories.tsx).
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
<LiveStatusIndicator
|
|
39
|
+
status="connected"
|
|
40
|
+
size="sm"
|
|
41
|
+
/>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Published TypeScript API
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const LiveStatusIndicator: ({ className, detail, isLabelVisible, label, size, status, ...spanProps }: LiveStatusIndicatorProps) => ReactNode
|
|
48
|
+
|
|
49
|
+
type LiveStatusIndicatorProps = Omit<ComponentPropsWithRef<"span">, "children"> & {
|
|
50
|
+
/** Extra context, announced after the label. "3 of 4 bays." */
|
|
51
|
+
detail?: string;
|
|
52
|
+
isLabelVisible?: boolean;
|
|
53
|
+
/** Overrides the machine's own wording. Rarely wanted. */
|
|
54
|
+
label?: string;
|
|
55
|
+
size?: LiveStatusIndicatorSize;
|
|
56
|
+
status: ConnectionStatus;
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
[Full declarations](../../dist/LiveStatusIndicator/LiveStatusIndicator.d.ts)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# LogViewer
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { LogViewer } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Three repos render a scrolling log pane — mux-magic's `JobLogsDisclosure` and `StepLogs`,
|
|
8
|
+
rip-deck's `LogModal` — and between them they have four defects this component exists not to
|
|
9
|
+
have. The fifth below is not theirs: it is defect 1 coming back through the front door, in
|
|
10
|
+
this component, found by the first app to consume it.
|
|
11
|
+
|
|
12
|
+
## 1. The auto-scroll that follows nothing
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const pane = paneRef.current
|
|
17
|
+
if (pane) pane.scrollTop = pane.scrollHeight
|
|
18
|
+
}, []) // ← empty deps
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
That is mux-magic's, and it runs **once**, on mount, when the pane is empty and
|
|
22
|
+
`scrollHeight` *is* `clientHeight`. Every line after it arrives below the fold.
|
|
23
|
+
|
|
24
|
+
It reads as correct, it is the shape everyone writes, and the log simply never follows.
|
|
25
|
+
|
|
26
|
+
## 2. Following that cannot be escaped
|
|
27
|
+
|
|
28
|
+
The naive fix — scroll to the bottom on every render — is worse: a user scrolling back to
|
|
29
|
+
read the line that mentioned an error is yanked to the end twice a second.
|
|
30
|
+
|
|
31
|
+
Following has to be **pinned to the user's own position**. It turns off the moment they
|
|
32
|
+
scroll away and back on when they return to the bottom, and there is a **Jump to latest**
|
|
33
|
+
button for when they do not want to scroll all that way.
|
|
34
|
+
|
|
35
|
+
The pin test allows a few pixels of slack, because a fractional device pixel ratio means
|
|
36
|
+
`scrollTop + clientHeight` never lands exactly on `scrollHeight`. An equality test here
|
|
37
|
+
un-pins the pane on a 125% display and on nothing else.
|
|
38
|
+
|
|
39
|
+
## 3. `data-log-id`
|
|
40
|
+
|
|
41
|
+
mux-magic's pane carries one. It is a `data-testid` under a different name — a handle only
|
|
42
|
+
the test suite can see — and `sourceRules.test.ts` bans the **practice**, not the spelling.
|
|
43
|
+
The pane here is found by its `label`, which is the query Playwright makes.
|
|
44
|
+
|
|
45
|
+
## 4. Announcing an hour of build output
|
|
46
|
+
|
|
47
|
+
`role="log"` is the correct role and `aria-live` is **off** unless asked for. A live log
|
|
48
|
+
emitting a line every 300 ms is a screen reader that cannot be interrupted and a user who
|
|
49
|
+
cannot read anything else on the page.
|
|
50
|
+
|
|
51
|
+
The accessible answer for a long-running job is a `LiveStatusIndicator` announcing *state*
|
|
52
|
+
and a log that is there to be read when wanted. `isAnnounced` exists for the short case: a
|
|
53
|
+
five-line result panel where the lines **are** the outcome.
|
|
54
|
+
|
|
55
|
+
## 5. A pane measured before it has a box
|
|
56
|
+
|
|
57
|
+
Defect 1 again, and the fix for it cannot see this one. `AccordionSection` renders its panel
|
|
58
|
+
with `hidden` rather than unmounting it, deliberately — an unmounted panel loses a scroll
|
|
59
|
+
position, a partially typed form, and any subscription its content opened, and the fleet's
|
|
60
|
+
log panes are exactly that. A `hidden` subtree has **no layout**, so the mount effect reads
|
|
61
|
+
`scrollHeight 0` and writes `scrollTop = 0`. Measured in mux-magic on a 60-line pane:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
while collapsed : scrollTop 0 scrollHeight 0 clientHeight 0
|
|
65
|
+
after expanding : scrollTop 0 scrollHeight 976 clientHeight 254
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Neither `isFollowing` nor `lines` changes when the section is opened, so the effect never
|
|
69
|
+
runs again and the log opens on its **first** line. That is this component's own `}, [])`
|
|
70
|
+
bug, rebuilt out of two components whose individual decisions are both right, and invisible
|
|
71
|
+
to both of their test suites — `LogViewer`'s mounted visible, `Accordion`'s holding content
|
|
72
|
+
that never measures itself. mux-magic hit it as a consumer and worked around it downstream,
|
|
73
|
+
in a `DisclosedLogViewer` that withheld the pane until the section had been opened once.
|
|
74
|
+
That workaround is now deletable.
|
|
75
|
+
|
|
76
|
+
A `ResizeObserver` on the pane, live only while following, is the fix. Not an
|
|
77
|
+
`IntersectionObserver`: that answers "is it on screen", which is a different question with
|
|
78
|
+
two wrong answers here — a pane below the fold on a long page is not intersecting and has
|
|
79
|
+
perfectly good layout, and scrolling the page later would re-fire for no reason.
|
|
80
|
+
`ResizeObserver` answers "does it have a box, and is that box still the same size", which is
|
|
81
|
+
the precondition the measurement actually needs; per spec it does not fire at `observe()`
|
|
82
|
+
time for an element that is not being rendered, so **gaining a box is the first callback**.
|
|
83
|
+
|
|
84
|
+
It pays for itself twice: a window resize re-wraps the lines and changes what is at the
|
|
85
|
+
bottom, and a following pane belongs at the new bottom.
|
|
86
|
+
|
|
87
|
+
## Not every boolean is a state kind
|
|
88
|
+
|
|
89
|
+
`isFollowing` is `useState`, not `useVisibility`, and this is the first component in the
|
|
90
|
+
library to say so out loud.
|
|
91
|
+
|
|
92
|
+
The kinds in `@charcuterie/logic` earn their keep when state is **registered** (members join
|
|
93
|
+
a group), **composed** (focus and selection disagreeing), or **shared** (a trigger and a
|
|
94
|
+
panel at opposite ends of a tree). None of that is true here: one component reads one
|
|
95
|
+
boolean it wrote itself.
|
|
96
|
+
|
|
97
|
+
Reaching for `useVisibility` because it is also a boolean would make `isVisible` mean "is
|
|
98
|
+
following", which is how a state layer stops meaning anything.
|
|
99
|
+
|
|
100
|
+
## `maxLines`, not virtualization
|
|
101
|
+
|
|
102
|
+
The plan floated an optional `@tanstack/react-virtual` peer. Dropping the oldest lines is
|
|
103
|
+
what actually bounds the DOM, costs no dependency, and is what every one of these panes
|
|
104
|
+
wanted anyway — nobody scrolls back through an hour of sector reads.
|
|
105
|
+
|
|
106
|
+
Virtualization stays unbuilt until a consumer produces a log where 500 lines is not enough,
|
|
107
|
+
which is the same rule that kept a bare `Listbox` out of `Select`.
|
|
108
|
+
|
|
109
|
+
## Example from the stories
|
|
110
|
+
|
|
111
|
+
See the full [story example](../../src/LogViewer/LogViewer.stories.tsx).
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
<LogViewer label="Bay 6 rip log" lines={[]} />
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Published TypeScript API
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const LogViewer: ({ className, isAnnounced, label, lines, maxLines, }: LogViewerProps) => ReactNode
|
|
121
|
+
|
|
122
|
+
type LogViewerProps = {
|
|
123
|
+
className?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Announce new lines to a screen reader. **Off by default**, and
|
|
126
|
+
* that is a considered choice rather than an oversight — see
|
|
127
|
+
* below.
|
|
128
|
+
*/
|
|
129
|
+
isAnnounced?: boolean;
|
|
130
|
+
/** The pane's accessible name. Required. */
|
|
131
|
+
label: string;
|
|
132
|
+
lines: LogLine[];
|
|
133
|
+
/**
|
|
134
|
+
* Oldest lines past this are dropped from the DOM. A rip in
|
|
135
|
+
* progress emits a line every few hundred milliseconds for an
|
|
136
|
+
* hour, and the browser keeps every node.
|
|
137
|
+
*/
|
|
138
|
+
maxLines?: number;
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
[Full declarations](../../dist/LogViewer/LogViewer.d.ts)
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Main
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Main } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The `<main>` landmark and the content column. **Its width is the crux of the whole shell.**
|
|
8
|
+
|
|
9
|
+
The owner's complaint, verbatim:
|
|
10
|
+
|
|
11
|
+
> "All these apps seem to be really narrow with a very large max-width. By that I mean 1
|
|
12
|
+
> column, but waaaaaaay too wide. In almost all cases, what I really want is something like
|
|
13
|
+
> Rip-Deck where the app has a narrower main column but the wrapping grids are all
|
|
14
|
+
> full-width in most of these apps only when you have too many items."
|
|
15
|
+
|
|
16
|
+
## The width is a value, not a constant
|
|
17
|
+
|
|
18
|
+
The cap is the least standardized number in the fleet: `max-w-5xl` (board-games, sibling-app),
|
|
19
|
+
`max-w-6xl` *and* `max-w-3xl` mixed inside one app (mux-magic), `max-w-7xl`
|
|
20
|
+
(gallery-downloader, spoolbuddy), `max-w-[90rem]` (mail-sifter), `80rem` (points-market), a
|
|
21
|
+
raw `1400px` in plain CSS (plex-channels), a JS-computed one (rip-deck), and none at all in
|
|
22
|
+
three more.
|
|
23
|
+
|
|
24
|
+
`contentWidth` accepts three shapes, and the third is why this is a value rather than a
|
|
25
|
+
constant:
|
|
26
|
+
|
|
27
|
+
| Shape | Example | For |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| A `screen.*` step | `contentWidth="lg"` | The ordinary page. `lg` (64rem) is the default. |
|
|
30
|
+
| `"full"` | `contentWidth="full"` | A wall of tiles that genuinely wants the window. |
|
|
31
|
+
| A `rem` literal | ``contentWidth={`${rem}rem`}`` | A cap computed at runtime. |
|
|
32
|
+
|
|
33
|
+
**`max-w-*` is not used and must not be.** Tailwind v4 owns `--container-*` for that scale
|
|
34
|
+
at *different* sizes than our `screen.*`, which is the collision that renamed the
|
|
35
|
+
container-query scale to `--cq-*`. The cap is an inline `max-inline-size` reading
|
|
36
|
+
`var(--screen-*)`, so it stays a token instead of becoming a literal.
|
|
37
|
+
|
|
38
|
+
## How it composes with the adaptive-columns hook
|
|
39
|
+
|
|
40
|
+
rip-deck's `useLayoutColumns` — lifted into this library separately — decides a column count
|
|
41
|
+
from the viewport, then folds it into a page cap with `contentMaxWidthRem(columns)`: one
|
|
42
|
+
column → 56rem, two → 72rem, three → 106rem. It returns a **number of rem**, which is
|
|
43
|
+
exactly the third shape above:
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
The seam is one prop and no import in either direction: this package does not depend on a
|
|
48
|
+
layout hook to lay out a page, and the hook does not know a `Shell` exists. The value goes
|
|
49
|
+
on **`Shell`** rather than on `Main` so the header's cap stays in step with the column's as
|
|
50
|
+
the count changes — which is the same reason the two share one `contentWidth` at all.
|
|
51
|
+
|
|
52
|
+
## `@container` is on the column, not on `<main>`
|
|
53
|
+
|
|
54
|
+
A grid inside the content column answers to **the column's** width. A poster grid beside an
|
|
55
|
+
open rail and the same grid full-bleed are the pair a media query cannot tell apart, and
|
|
56
|
+
getting that wrong at intermediate widths is what the fleet's grids do today.
|
|
57
|
+
|
|
58
|
+
The container is declared on the capped inner column rather than on `<main>` deliberately.
|
|
59
|
+
`<main>` is as wide as its grid track — 1184px beside an open rail on a 1440px window —
|
|
60
|
+
while the column inside it is capped at `contentWidth`. A container on `<main>` measures a
|
|
61
|
+
width the content never has: a grid would go three-up at `--cq-xl` while sitting in 976px
|
|
62
|
+
of space.
|
|
63
|
+
|
|
64
|
+
**`container-type: inline-size` implies `contain: layout style inline-size`**, and both
|
|
65
|
+
halves have consequences:
|
|
66
|
+
|
|
67
|
+
- **The element may not be sized by its own contents.** Here that is wanted — the column
|
|
68
|
+
has a definite inline size from its parent, so wide content can no longer widen it, which
|
|
69
|
+
is half of why the page does not scroll sideways.
|
|
70
|
+
- **`contain: layout` makes it a containing block for `position: fixed` descendants.** An
|
|
71
|
+
app rendering fixed chrome *inside* `Main` gets it positioned against the column rather
|
|
72
|
+
than the viewport. Every overlay in this library portals to `document.body` and is
|
|
73
|
+
unaffected; an app's own fixed chrome belongs in `Shell`, beside `Main`.
|
|
74
|
+
|
|
75
|
+
## Two kinds of overflow, two different answers
|
|
76
|
+
|
|
77
|
+
`wrap-anywhere` on the column handles content that *can* wrap and does not — a filesystem
|
|
78
|
+
path, a hash, a URL, none of which contain a break opportunity.
|
|
79
|
+
|
|
80
|
+
**`anywhere`, not `break-word`.** Both break the long word onto the next line, so the two are
|
|
81
|
+
indistinguishable in a screenshot. Only `anywhere` also shrinks the element's **min-content
|
|
82
|
+
size**, which is what a flex or grid item's automatic minimum resolves against — and
|
|
83
|
+
therefore what decides whether the string can force its own column wider. Under
|
|
84
|
+
`break-word` the ink wraps while the intrinsic contribution stays the full token length, so
|
|
85
|
+
the page can still scroll sideways with **no overflowing element box anywhere in the tree**
|
|
86
|
+
for a `getBoundingClientRect()` assertion to catch. That is why the gate asserts
|
|
87
|
+
`document.documentElement.scrollWidth`, and why `Main.test.tsx` pins the computed value.
|
|
88
|
+
|
|
89
|
+
That is the cheap half of the horizontal-scroll fix; the other halves are `minmax(0, 1fr)`
|
|
90
|
+
and `overflow-x: clip` on `Shell`, plus `overflow-x: hidden` here for anything absolutely
|
|
91
|
+
positioned **inside** the scrollport — the next section says why that one cannot be left to
|
|
92
|
+
the frame.
|
|
93
|
+
|
|
94
|
+
A `<table>` is the one thing neither can save. Table columns have min-content widths that no
|
|
95
|
+
`overflow-wrap` reaches, so a wide table goes in a scroll container:
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
<section
|
|
99
|
+
aria-label="Transfer log, scrollable"
|
|
100
|
+
className="charcuterie-scrollbar overflow-x-auto rounded-lg border border-border-subtle"
|
|
101
|
+
>
|
|
102
|
+
<table>…</table>
|
|
103
|
+
</section>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Because that container scrolls, the columns off screen have to be reachable **without a
|
|
107
|
+
mouse** — axe's `scrollable-region-focusable`, which is WCAG 2.1.1. There are two ways to
|
|
108
|
+
satisfy it and the choice is not a matter of taste:
|
|
109
|
+
|
|
110
|
+
1. **The content contains something focusable.** A row that ends in a link is enough:
|
|
111
|
+
tabbing to it scrolls the container into view. This is the case above and the one the
|
|
112
|
+
`Responsive` story ships, because a log row with no way into the record is a poor table
|
|
113
|
+
anyway.
|
|
114
|
+
2. **`tabIndex={0}` on the container.** The answer for a table of pure text, and the one
|
|
115
|
+
most guidance quotes. Note that Biome's `noNoninteractiveTabindex` rejects it on a
|
|
116
|
+
non-interactive element and its **unsafe fix removes the attribute before a suppression
|
|
117
|
+
is evaluated** — so `yarn lint` will silently turn a compliant table into a
|
|
118
|
+
keyboard-trap. Prefer (1) where the data allows it.
|
|
119
|
+
|
|
120
|
+
`aria-label` on the container is worth it either way: it turns the scroller into a named
|
|
121
|
+
region, so the table is announced as a thing rather than as loose content.
|
|
122
|
+
|
|
123
|
+
## `relative`, and the second scrollbar
|
|
124
|
+
|
|
125
|
+
`<main>` is the page's only vertical scrollport, so the document itself must never scroll.
|
|
126
|
+
An absolutely positioned descendant breaks that unless `<main>` is its **containing block**.
|
|
127
|
+
With `position: static` the nearest positioned ancestor is `Shell`, which sits *outside* the
|
|
128
|
+
scrollport: the box resolves against the frame, `<main>`'s `overflow-y` has no authority over
|
|
129
|
+
it, and its static position — a couple of thousand pixels down a long document — lands as
|
|
130
|
+
scrollable overflow on `documentElement`. The page grows to reach it, and the reader gets a
|
|
131
|
+
**second scrollbar** beside the one `<main>` already has.
|
|
132
|
+
|
|
133
|
+
The box does not have to be exotic, which is what makes this hard to spot. Tailwind's
|
|
134
|
+
`sr-only` is `position: absolute`, so one visually hidden `(opens in a new tab)` span in a
|
|
135
|
+
document footer is enough. Measured on Folio at 1440x900 before this: `<main>` 835px tall,
|
|
136
|
+
`document.documentElement.scrollHeight` 2085 — the span's offset, exactly. Nothing on the
|
|
137
|
+
page looked wrong; there were simply two scrollbars.
|
|
138
|
+
|
|
139
|
+
`overflow-x: hidden` comes with the `relative` and is not decoration. Moving every
|
|
140
|
+
absolutely positioned descendant's containing block from `Shell` to `<main>` also moves what
|
|
141
|
+
clips them sideways, so `Shell`'s `overflow-x: clip` no longer reaches them — a drawer parked
|
|
142
|
+
at `translateX(110%)` **inside** `Main` would draw a horizontal scrollbar on the scrollport
|
|
143
|
+
instead of being clipped. `hidden` rather than `clip` because this element already scrolls on
|
|
144
|
+
the other axis: `clip` beside an `auto` computes to `hidden` anyway, so writing `hidden` is
|
|
145
|
+
writing what the browser will use.
|
|
146
|
+
|
|
147
|
+
An app's own parked chrome still belongs in `Shell`, beside `Main` rather than in it. That is
|
|
148
|
+
what `Shell`'s clip is for, and it is the arrangement `Shell.stories.tsx` demonstrates.
|
|
149
|
+
|
|
150
|
+
## `tabIndex={-1}`
|
|
151
|
+
|
|
152
|
+
`<main>` accepts focus so `Shell`'s skip link moves **focus** and not merely the scroll
|
|
153
|
+
position. Without it, Safari and Firefox scroll to `<main>` and leave the next Tab back up
|
|
154
|
+
in the header — which looks exactly like a skip link that works.
|
|
155
|
+
|
|
156
|
+
## The reader's place, kept
|
|
157
|
+
|
|
158
|
+
`Shell` gives this element the page's only vertical scrollport, so the header and the rails
|
|
159
|
+
stay put while the content moves. That is what `Shell.test.tsx` asserts, and this is what it
|
|
160
|
+
costs.
|
|
161
|
+
|
|
162
|
+
**The browser will not put the offset back.** A browser remembers the **document scroller's**
|
|
163
|
+
position per history entry, and `<main>` is not the document scroller. It also restores
|
|
164
|
+
nothing at all across a same-document `pushState` navigation, which is every link press in a
|
|
165
|
+
single-page app. So Back lands at the top of a list the reader had scrolled half-way down,
|
|
166
|
+
`history.scrollRestoration` has no bearing on it, and there is no browser setting that
|
|
167
|
+
changes it. The owner, on Docket:
|
|
168
|
+
|
|
169
|
+
> "If I scroll, click on an item, then go back, it resets me to the top. […] It should
|
|
170
|
+
> remember where the scroll position was previously. Isn't this handled by Chrome already?"
|
|
171
|
+
|
|
172
|
+
**There is no prop for it.** The history entry arrives on a context, and
|
|
173
|
+
`ReactRouterAdapter` puts it at the app root beside the link seam:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
import { ReactRouterAdapter } from "@charcuterie/ui/react-router"
|
|
177
|
+
|
|
178
|
+
<BrowserRouter>
|
|
179
|
+
<ReactRouterAdapter>
|
|
180
|
+
<Routes>…</Routes>
|
|
181
|
+
</ReactRouterAdapter>
|
|
182
|
+
</BrowserRouter>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
It was a prop for one release — `scrollKey` — and that release is the argument against a
|
|
186
|
+
prop. One app wired it and the other three carried on losing the reader's place with the
|
|
187
|
+
library sitting right there supporting it. Render no provider and nothing is remembered,
|
|
188
|
+
which is right for an app with no history to remember.
|
|
189
|
+
|
|
190
|
+
An app on another router wires `ScrollMemoryProvider` itself, with any value that identifies
|
|
191
|
+
the history **entry** rather than the URL:
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
<ScrollMemoryProvider entry={{ key: historyKey, path: location }}>
|
|
195
|
+
<App />
|
|
196
|
+
</ScrollMemoryProvider>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### A filter is not a navigation
|
|
200
|
+
|
|
201
|
+
A filter chip, an expanded group and a selected tab each write a search param, and
|
|
202
|
+
`setSearchParams` **navigates** — so each one mints a history entry the memory has never
|
|
203
|
+
seen. Read as "unseen ⇒ start at the top", pressing a filter throws the reader to the top of
|
|
204
|
+
the list they were reading. That shipped, and it is why an entry remembers its **path**:
|
|
205
|
+
|
|
206
|
+
| The entry | What happens |
|
|
207
|
+
| --- | --- |
|
|
208
|
+
| One we have seen | Its remembered offset. Back and Forward land where you left them. |
|
|
209
|
+
| New, **same** path | Nothing. The scrollport is left exactly where the reader put it. |
|
|
210
|
+
| New, **different** path | The top, which is what a browser does for a new document. |
|
|
211
|
+
|
|
212
|
+
### It has to wait for the content
|
|
213
|
+
|
|
214
|
+
A one-shot `scrollTop = offset` does **nothing** on a real page. The commit that changes the
|
|
215
|
+
route draws a skeleton, the rows land a fetch later, and an offset written against an empty
|
|
216
|
+
scrollport is clamped to `0` by the browser. Every check a one-shot restore could make still
|
|
217
|
+
passes — the offset was remembered, the write happened — and the reader is looking at the top
|
|
218
|
+
of the list.
|
|
219
|
+
|
|
220
|
+
So the restore re-applies through a `ResizeObserver` on the scrollport and on its content
|
|
221
|
+
column, and stops at the first of three things:
|
|
222
|
+
|
|
223
|
+
1. **The offset lands.** Anything past that would only fight the reader.
|
|
224
|
+
2. **The reader scrolls.** Any `wheel`, `touchstart`, `keydown` or `pointerdown` on the
|
|
225
|
+
scrollport ends it, because a page that jumps out from under somebody who has already
|
|
226
|
+
started reading is a worse bug than the one being fixed.
|
|
227
|
+
3. **Three seconds pass.** A page that slow has been read from the top already.
|
|
228
|
+
|
|
229
|
+
The offsets live in memory, not in `sessionStorage`. A history key survives a reload; the DOM
|
|
230
|
+
it described does not, and a pixel offset from before the reload points at a different row.
|
|
231
|
+
Restoring a stale number is worse than restoring nothing, because it looks deliberate.
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
<Main><h1>Projects</h1><p>No projects yet.</p></Main>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Published TypeScript API
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
const Main: ({ children, className, contentWidth, id, ref, ...mainProps }: MainProps) => ReactNode
|
|
241
|
+
|
|
242
|
+
type MainProps = ComponentPropsWithRef<"main"> & {
|
|
243
|
+
contentWidth?: ContentWidth;
|
|
244
|
+
};
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
[Full declarations](../../dist/Main/Main.d.ts)
|