@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,167 @@
|
|
|
1
|
+
# Nav
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Nav } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The app's destinations. A header row, a side rail, a collapsed rail, a strip along the foot
|
|
8
|
+
of a phone, or a panel behind one control — the same list, drawn where it fits.
|
|
9
|
+
|
|
10
|
+
> **This replaces [`NavBar`](NavBar.md)**, which shipped the
|
|
11
|
+
> header row on its own and is deprecated as of this release. `bar` is `Nav`'s default
|
|
12
|
+
> layout and behaves identically, down to the measured whole-row fold — see *`bar` folds
|
|
13
|
+
> whole* below.
|
|
14
|
+
|
|
15
|
+
## What was actually missing
|
|
16
|
+
|
|
17
|
+
`Shell` / `Header` / `Rail` / `Main` shipped the page frame on 2026-08-10 and left **the
|
|
18
|
+
rail empty**. Twelve UI repos, and exactly two have a `<nav>` at all: Docket hand-rolled a
|
|
19
|
+
row of `NavLink`s with the collapse rule in its own stylesheet, Folio hand-rolled another,
|
|
20
|
+
and the other ten have no destinations anywhere.
|
|
21
|
+
|
|
22
|
+
The two that exist already disagree. Docket *wraps* below its breakpoint, so its header
|
|
23
|
+
stands three lines tall on a phone — which is not a decision anybody made, it is what
|
|
24
|
+
`flex-wrap` does when nobody writes the other rule.
|
|
25
|
+
|
|
26
|
+
## Every item is a real link
|
|
27
|
+
|
|
28
|
+
`<a href>`, through the injected `RouterLinkProvider` — the same seam `TextLink` and
|
|
29
|
+
`ButtonLink` take, so an app injects its router once and every destination in the library
|
|
30
|
+
routes.
|
|
31
|
+
|
|
32
|
+
Not a `<button onClick={navigate}>`. That is what mux-magic and QueuePilot do today, it is
|
|
33
|
+
**identical in a screenshot**, and it loses middle-click, ctrl-click, "open in a new tab",
|
|
34
|
+
the status bar preview, and "copy link address". See
|
|
35
|
+
[buttons are actions, links are navigation](../building-an-app.md#2-wire-the-router).
|
|
36
|
+
|
|
37
|
+
An `isExternal` item is the exception the seam already knows: a plain anchor,
|
|
38
|
+
`target="_blank"`, `rel="noopener noreferrer"`. Pushing `https://…` onto a router's history
|
|
39
|
+
navigates the SPA to a route that does not exist.
|
|
40
|
+
|
|
41
|
+
## `icon`, and `NavRailItem`
|
|
42
|
+
|
|
43
|
+
`NavItem` keeps `icon` optional, because a `bar` never takes the label away — Docket's nine
|
|
44
|
+
destinations are words, and inventing nine glyphs to satisfy a type would be worse than the
|
|
45
|
+
problem.
|
|
46
|
+
|
|
47
|
+
A rail is the other case. `railIcons` is one `--control-height-lg` square and shows nothing
|
|
48
|
+
else, so an item with no glyph is a blank square that still navigates, and there is no visual
|
|
49
|
+
defect to notice because the row reads as padding. **Annotate a rail's array as
|
|
50
|
+
`NavRailItem[]`** — the same shape with `icon` made required — and the type checker catches
|
|
51
|
+
it before somebody drags a window narrow.
|
|
52
|
+
|
|
53
|
+
`items` is deliberately **not** discriminated on `layout`. The main call site passes
|
|
54
|
+
`layout={navLayout.layout}` straight from `useNavLayout`, which is a variable and not a
|
|
55
|
+
literal, so a union that split the item type by layout would force a `switch` at the one
|
|
56
|
+
place this component exists to make short.
|
|
57
|
+
|
|
58
|
+
The library still ships no icons — lucide (ISC) is the fleet recommendation, and a glyph in
|
|
59
|
+
a default renders as nothing where the font lacks it.
|
|
60
|
+
|
|
61
|
+
## `bar` folds whole, and it is measured
|
|
62
|
+
|
|
63
|
+
There is no `collapseAt` and no media query on this axis. The bar reads the width its links
|
|
64
|
+
actually have and folds when their sum stops fitting, so a longer label, a tenth destination,
|
|
65
|
+
a `data-density="kiosk"` or a reader at 175% browser zoom each move the fold on their own.
|
|
66
|
+
mux-magic collapses at a hardcoded `480px` and plex-channels at `760px`, and neither number
|
|
67
|
+
has a reason.
|
|
68
|
+
|
|
69
|
+
It folds **whole** rather than progressively, unlike `Toolbar`. `Toolbar`'s items are ranked;
|
|
70
|
+
a nav's order is the shape of the product — Docket's reads as the pipeline, Triage → Backlog
|
|
71
|
+
→ Phases → Board → Archives — and half of that behind a button is a rule no reader can learn.
|
|
72
|
+
|
|
73
|
+
⚠️ **A `bar` must not be sized by its own contents.** It measures its own box to decide what
|
|
74
|
+
to draw in it, so a container that shrink-wraps makes the answer its own input: put it in a
|
|
75
|
+
`minmax(0, 1fr)` grid track or a `flex-1 min-w-0` row.
|
|
76
|
+
|
|
77
|
+
## The current destination is announced
|
|
78
|
+
|
|
79
|
+
`aria-current="page"`, and a background. One without the other is WCAG 1.4.1, and a
|
|
80
|
+
`font-weight` swap alone is exactly that failure.
|
|
81
|
+
|
|
82
|
+
Matching is two rules:
|
|
83
|
+
|
|
84
|
+
1. An exact path wins — `/board` on `/board`.
|
|
85
|
+
2. Otherwise the **longest path-segment prefix** wins. `/board` matches `/board/inProgress`
|
|
86
|
+
and does **not** match `/boardgames`, because `games` is not a new segment. Longest, so
|
|
87
|
+
an app with `/settings` and `/settings/labels` marks the deeper one.
|
|
88
|
+
|
|
89
|
+
The root is exempt from rule 2: `/` prefixes every path in the app, so a permissive root
|
|
90
|
+
would mark Home current on every screen and the state would carry no information.
|
|
91
|
+
|
|
92
|
+
Query and fragment are stripped first. A destination and a filtered view of it are the same
|
|
93
|
+
place — `/board?lane=todo` is still Board, which is the case that breaks first in a real app.
|
|
94
|
+
|
|
95
|
+
**And exactly one item is current.** `getIsCurrentHref` answers for a single link, so a nav
|
|
96
|
+
holding both `/settings` and `/settings/labels` gets `true` twice while the reader is on the
|
|
97
|
+
deeper one — which is what `NavBar` shipped. `resolveActiveKey` is the whole-list answer and
|
|
98
|
+
takes the **deepest** match, by path rather than by array position, so the product's own
|
|
99
|
+
order never decides which destination lights up.
|
|
100
|
+
|
|
101
|
+
Both are exported, so an app can assert its own table without mounting anything.
|
|
102
|
+
|
|
103
|
+
## Three widths, one rule — `useNavLayout`
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
const nav = useNavLayout({ storageKey: "queuepilot-nav" })
|
|
107
|
+
|
|
108
|
+
// nav.layout: "rail" | "railIcons" | "menu"
|
|
109
|
+
// nav.isCollapsed, nav.mode, nav.setMode, nav.toggle
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
| Width | `layout` | What the app renders |
|
|
113
|
+
| --- | --- | --- |
|
|
114
|
+
| `>= 64rem` | `rail` | a `Rail` holding a `Nav` |
|
|
115
|
+
| `>= 48rem` | `railIcons` | the same `Rail`, narrower |
|
|
116
|
+
| below | `menu` | a trigger in the `Header` |
|
|
117
|
+
|
|
118
|
+
`toggle()` overrides the width and the choice is remembered under `storageKey`. The
|
|
119
|
+
override does **not** reach the narrow state — `expanded` on a 390px screen is a 212px rail
|
|
120
|
+
beside 178px of content — and the remembered value is kept rather than cleared, so rotating
|
|
121
|
+
a tablet back to landscape restores the rail the reader asked for.
|
|
122
|
+
|
|
123
|
+
**Why the app still places it.** The placement genuinely differs and the rule does not. The
|
|
124
|
+
`menu` state puts a control in the header, which is a different corner of `Shell`'s grid
|
|
125
|
+
from a side rail, and no amount of restyling moves an element across a grid. So the library
|
|
126
|
+
owns *which* state is right, at what width, with what override, remembered where; the app
|
|
127
|
+
owns two `if`s.
|
|
128
|
+
|
|
129
|
+
## The narrow panel is a `Popover`, not a `Menu`
|
|
130
|
+
|
|
131
|
+
`Menu`'s items are `onSelect` callbacks on `<button>`s. That is right for what a menu
|
|
132
|
+
usually holds — undo, redo, a scheme cycle — and wrong for a destination, for every reason
|
|
133
|
+
in *Every item is a real link* above.
|
|
134
|
+
|
|
135
|
+
So `layout="menu"` is a `Popover`: anchored, dismissable, portalled to the body, and
|
|
136
|
+
`modal={false}` so the caret is not trapped. It is a disclosure, not a dialog somebody has
|
|
137
|
+
to answer. Escape and an outside press both close it.
|
|
138
|
+
|
|
139
|
+
Give the trigger a real name. A bare hamburger is a glyph, and a glyph is not a name — the
|
|
140
|
+
reason `IconButton` requires `label`.
|
|
141
|
+
|
|
142
|
+
## When to use which layout
|
|
143
|
+
|
|
144
|
+
| Layout | For |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `bar` | three to six destinations, and a grid that wants every pixel — ai-usage, folio, mux-magic, sibling-app. Folds itself; needs no `useNavLayout`. |
|
|
147
|
+
| `rail` / `railIcons` | seven or more, or a pipeline you read down — Docket, mail-sifter, QueuePilot |
|
|
148
|
+
| `bottom` | three or four you switch between constantly, in the Narrow View only |
|
|
149
|
+
| `menu` | the Narrow View of a `rail` app |
|
|
150
|
+
|
|
151
|
+
`bottom` is deliberately not the default narrow answer. It costs a permanent strip of the
|
|
152
|
+
screen, and it earns that only when the destinations are few and the switching is constant.
|
|
153
|
+
An app you settle into for an evening wants the panel.
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
<Nav activeHref="/projects" label="Main" items={[{ href: "/projects", key: "projects", label: "Projects" }]} />
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Published TypeScript API
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const Nav: (props: NavProps) => ReactNode
|
|
163
|
+
|
|
164
|
+
type NavProps = NavMenuProps | NavPlacedProps;
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
[Full declarations](../../dist/Nav/Nav.d.ts)
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# NavBar
|
|
2
|
+
|
|
3
|
+
> **Deprecated.** Use `Nav` with `layout="bar"` — which is `Nav`'s default, so `<Nav activeHref={…} items={…} label="Main" />` is the whole migration. **Removed in the next major.**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { NavBar } from "@charcuterie/ui"
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
> ## ⚠️ Deprecated — use [`Nav`](Nav.md)
|
|
10
|
+
>
|
|
11
|
+
> **Removed in the next major.** `NavBar` is now a thin adapter over `Nav` and keeps every
|
|
12
|
+
> behaviour documented on this page, so nothing breaks today.
|
|
13
|
+
>
|
|
14
|
+
> ```tsx
|
|
15
|
+
> // Before
|
|
16
|
+
> <NavBar currentHref={pathname} items={DESTINATIONS} label="Main" />
|
|
17
|
+
>
|
|
18
|
+
> // After — `bar` is Nav's default layout
|
|
19
|
+
> <Nav activeHref={pathname} items={DESTINATIONS} label="Main" />
|
|
20
|
+
> ```
|
|
21
|
+
>
|
|
22
|
+
> `currentHref` is `activeHref`. Every other prop keeps its name.
|
|
23
|
+
>
|
|
24
|
+
> **Two items can no longer both be current.** This component asked the question once per
|
|
25
|
+
> item, so a bar holding `/settings` and `/settings/labels` marked *both* while the reader was
|
|
26
|
+
> on the deeper one — against the decision record below, which says a nav with two current
|
|
27
|
+
> items has stopped saying anything. `Nav` takes the deepest match.
|
|
28
|
+
>
|
|
29
|
+
> **Why it went away:** it answered half the question. A horizontal row that folds is one
|
|
30
|
+
> shape an app's destinations take; a labelled side rail, a collapsed icon rail and a
|
|
31
|
+
> Narrow-View bottom strip are the others, and this component could not become any of them —
|
|
32
|
+
> so an app that wanted a rail was back to hand-rolling, which is the state it was built to
|
|
33
|
+
> end.
|
|
34
|
+
|
|
35
|
+
The app's destinations as real links, in one line — folding into a single menu button,
|
|
36
|
+
**whole**, when that line does not fit.
|
|
37
|
+
|
|
38
|
+
## It folds whole, and that is the decision
|
|
39
|
+
|
|
40
|
+
`Toolbar` collapses **progressively**: items drop off the end one at a time, because its
|
|
41
|
+
items are ranked — the two things you do to a running job matter more than the two you do
|
|
42
|
+
to the deck.
|
|
43
|
+
|
|
44
|
+
A nav is not ranked. Its order is the shape of the product. Docket's reads as the pipeline
|
|
45
|
+
work moves along — Triage → Backlog → Phases → Lanes → Board → Archives — and a
|
|
46
|
+
half-collapsed bar splits that shape across two places with no rule a reader can learn.
|
|
47
|
+
"Some of the app is up here and the rest is behind a button" is worse than either whole
|
|
48
|
+
answer.
|
|
49
|
+
|
|
50
|
+
So the bar shows **every** destination or **none**, and the menu is the complete list in
|
|
51
|
+
the product's own order.
|
|
52
|
+
|
|
53
|
+
## Why this is not a folded `Toolbar`
|
|
54
|
+
|
|
55
|
+
`Toolbar` already solves collapse-into-an-overflow, and this component **reuses its
|
|
56
|
+
measurement** — `useToolbarOverflow`, the same tape measure — rather than growing a second
|
|
57
|
+
one.
|
|
58
|
+
|
|
59
|
+
What it cannot reuse is the rendering. A `ToolbarAction` is `{ label, onSelect }`, and a
|
|
60
|
+
collapsed one becomes a `MenuItem`, which is also `{ label, onSelect }`. A nav folded into
|
|
61
|
+
one is a row of `<button>`s:
|
|
62
|
+
|
|
63
|
+
| | `<button onClick={navigate}>` | `<a href>` |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| Middle-click, ctrl-click | nothing | opens a tab |
|
|
66
|
+
| "Open link in new tab" | absent from the menu | there |
|
|
67
|
+
| "Copy link address" | absent | there |
|
|
68
|
+
| Status bar on hover | blank | the destination |
|
|
69
|
+
| Visited styling, the back button's idea of history | none | the platform's |
|
|
70
|
+
|
|
71
|
+
`BuildingAnApp.mdx` names `<button onClick={navigate}>` as the fleet's most common
|
|
72
|
+
navigation defect. A collapse mechanism that introduced it below a certain width would be
|
|
73
|
+
that defect on a timer — and it screenshots identically, which is how it would survive
|
|
74
|
+
review.
|
|
75
|
+
|
|
76
|
+
The panel is a `Popover` (`role="dialog"`) rather than a `Menu` for the same reason:
|
|
77
|
+
`role="menu"` permits only the `menuitem` family, and a `menuitem` is something you **do**,
|
|
78
|
+
not somewhere you **go**.
|
|
79
|
+
|
|
80
|
+
## Measured, not breakpointed
|
|
81
|
+
|
|
82
|
+
There is no `collapseAt` prop and no media query. The bar reads the width its links
|
|
83
|
+
actually have and folds when their sum stops fitting — so a longer label, a tenth
|
|
84
|
+
destination, `data-density="kiosk"`, or a reader at 175% browser zoom each move the fold on
|
|
85
|
+
their own.
|
|
86
|
+
|
|
87
|
+
mux-magic collapses at a hardcoded `480px` and plex-channels at `760px`. Neither number has
|
|
88
|
+
a reason, and both are wrong the first time anything about the content changes.
|
|
89
|
+
|
|
90
|
+
## ⚠️ The bar must not be sized by its own contents
|
|
91
|
+
|
|
92
|
+
It measures its own box to decide what to draw in it, so a container that shrink-wraps
|
|
93
|
+
makes the answer its own input: fewer links → a narrower box → fewer links.
|
|
94
|
+
|
|
95
|
+
The root carries `min-w-0 flex-1`, which is the whole fix inside a flex row. A grid track is
|
|
96
|
+
the caller's to declare:
|
|
97
|
+
|
|
98
|
+
```css
|
|
99
|
+
grid-template-columns: auto minmax(0, 1fr) auto; /* brand, nav, actions */
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`auto` on that middle track is the bug — it floors at the nav's min-content width, which is
|
|
103
|
+
the sum of every link.
|
|
104
|
+
|
|
105
|
+
## Which destination is current
|
|
106
|
+
|
|
107
|
+
The library is router-agnostic (see `RouterLinkProvider`), so it cannot ask a router which
|
|
108
|
+
link is active. The app hands it one string:
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
`getIsCurrentHref` decides the rest, and it is exported so an app can ask the same question
|
|
113
|
+
elsewhere:
|
|
114
|
+
|
|
115
|
+
- **A parent path is current for its children.** `/tasks` is current on `/tasks/41`,
|
|
116
|
+
because a nav item names a section and a section does not stop being the one you are in
|
|
117
|
+
when you open something inside it. The match is on whole segments, so `/task` is not
|
|
118
|
+
current for `/tasks`.
|
|
119
|
+
- **`/` is exact.** react-router's `<NavLink to="/">` is active on *every* route unless the
|
|
120
|
+
caller remembers `end`, which is the footgun behind every "why is Home always
|
|
121
|
+
highlighted" bug. There is no prop to change it here: a nav with two current items has
|
|
122
|
+
stopped saying anything.
|
|
123
|
+
- **The query string and the fragment are not part of the answer.**
|
|
124
|
+
`/backlog?focus=search` is still the Backlog.
|
|
125
|
+
|
|
126
|
+
The current destination gets `aria-current="page"` as well as the fill, because a highlight
|
|
127
|
+
is invisible to a screen reader and to anyone who cannot separate the two surfaces.
|
|
128
|
+
|
|
129
|
+
## Mounted exactly once
|
|
130
|
+
|
|
131
|
+
A destination is in the bar or in the panel, never both.
|
|
132
|
+
|
|
133
|
+
The fleet's habit is to render the whole nav twice and hide one copy with `hidden md:flex`
|
|
134
|
+
— mux-magic's `PageHeader` across two ~55-line blocks, mail-sifter's `TriageQueue` again.
|
|
135
|
+
Every link is then in the DOM at every width, so an agent driving the page finds two of
|
|
136
|
+
each and cannot tell which one a human can see, the two copies drift, and every test has to
|
|
137
|
+
be defensively scoped.
|
|
138
|
+
|
|
139
|
+
## A fold control belongs at an edge
|
|
140
|
+
|
|
141
|
+
`menuAlign="end"` puts the trigger beside the header's own actions rather than leaving it
|
|
142
|
+
hugging the wordmark with the whole track empty after it. It reaches **only** the folded
|
|
143
|
+
row, which holds exactly one item — so where the links sit when the bar is whole is not a
|
|
144
|
+
prop, and cannot be made inconsistent with the rest of the header.
|
|
145
|
+
|
|
146
|
+
## The trigger's glyph is the app's
|
|
147
|
+
|
|
148
|
+
The library ships no icons, so `menuIcon` has no default — U+2630 renders as nothing where
|
|
149
|
+
the font lacks it, which includes this sandbox's chromium and the kiosk image. With no icon
|
|
150
|
+
the trigger is a text button reading `menuLabel`, which works everywhere.
|
|
151
|
+
|
|
152
|
+
`menuLabel` names the trigger **and** the panel it opens: a `role="dialog"` takes no
|
|
153
|
+
accessible name from its content.
|
|
154
|
+
|
|
155
|
+
## Keyboard
|
|
156
|
+
|
|
157
|
+
Every link in the bar is its own tab stop, which is what a `<nav>` is — this is not a
|
|
158
|
+
`role="toolbar"`, and there is no roving focus to learn.
|
|
159
|
+
|
|
160
|
+
Folded, it is one tab stop: Enter or Space opens the panel, focus moves into it, Escape
|
|
161
|
+
closes it and hands focus back to the trigger. Choosing a destination closes it too —
|
|
162
|
+
unless the click was modified, because a ctrl-click leaves the reader exactly where they
|
|
163
|
+
were and shutting the menu they are still reading is how people stop ctrl-clicking.
|
|
164
|
+
|
|
165
|
+
## In a shell
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
<NavBar currentHref="/projects" label="Main" items={[{ href: "/projects", key: "projects", label: "Projects" }]} />
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Published TypeScript API
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
const NavBar: ({ className, currentHref, isMenuVisible, items, label, menuAlign, menuIcon, menuLabel, menuPlacement, size, }: NavBarProps) => ReactNode
|
|
175
|
+
|
|
176
|
+
type NavBarProps = {
|
|
177
|
+
className?: string;
|
|
178
|
+
currentHref?: string;
|
|
179
|
+
isMenuVisible?: boolean;
|
|
180
|
+
items: readonly NavBarItem[];
|
|
181
|
+
label: string;
|
|
182
|
+
menuAlign?: "end" | "start";
|
|
183
|
+
menuIcon?: ReactNode;
|
|
184
|
+
menuLabel?: string;
|
|
185
|
+
menuPlacement?: Placement;
|
|
186
|
+
size?: ControlSize;
|
|
187
|
+
};
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
[Full declarations](../../dist/NavBar/NavBar.d.ts)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Picker
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Picker } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Use Picker for a short option list with a built-in trigger. Use Listbox for a custom trigger or Combobox when users need to search.
|
|
8
|
+
|
|
9
|
+
A `Listbox` with its trigger already attached — the shape an app reaches for when it wants
|
|
10
|
+
"a select, but ours".
|
|
11
|
+
|
|
12
|
+
## Why this exists when `Listbox` already does
|
|
13
|
+
|
|
14
|
+
`Listbox` is deliberately trigger-agnostic. It takes a `trigger` element and owns none of the
|
|
15
|
+
open state, which is what lets it hang off a button, a tile, or a table header. The cost is
|
|
16
|
+
that the *common* case — a button showing the current value, with a chevron — is about thirty
|
|
17
|
+
lines, and the fleet wrote those lines **four separate times**: queuepilot's
|
|
18
|
+
`SelectListbox`, board-games' `SelectMenu` (on `useState` rather than `useVisibility`),
|
|
19
|
+
mux-magic's `ListboxPicker`, and twice inside this package (`QueryBuilderCombinator` and
|
|
20
|
+
`QueryBuilder`'s own story). Each hand-rolled the same chevron.
|
|
21
|
+
|
|
22
|
+
`Listbox` is unchanged. `Picker` is the assembled default; reach for `Listbox` directly when
|
|
23
|
+
the trigger is not a button.
|
|
24
|
+
|
|
25
|
+
## The accessible name carries the current value
|
|
26
|
+
|
|
27
|
+
`"Language: English"`, not `"Language"`. The trigger's visible text **is** the value, and
|
|
28
|
+
WCAG 2.5.3 requires the visible text to be contained in the accessible name — a bare
|
|
29
|
+
`aria-label={label}` fails it. It also keeps each control uniquely findable when a form has
|
|
30
|
+
several:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
getByRole("button", { name: /^Language: / })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Rich options need a `textValue`
|
|
37
|
+
|
|
38
|
+
`label` takes a `ReactNode` — a flag, a badge, two lines. When it is not a plain string, give
|
|
39
|
+
the option a `textValue`: it is the type-ahead target, and it is what the trigger and the
|
|
40
|
+
accessible name read, so the button says `Audio track: English` rather than the flattened
|
|
41
|
+
text of the whole node.
|
|
42
|
+
|
|
43
|
+
## The trigger is flush — the parent owns the gap
|
|
44
|
+
|
|
45
|
+
`Picker` is a `Button`. It has **no outer margin**. Next to a text
|
|
46
|
+
label it sits hard against the last word, which is how queuepilot's
|
|
47
|
+
"Chapters queued per turn" landed flush on the `[2 Default]` trigger,
|
|
48
|
+
and why that same app already had a one-off `#setmodal .fieldselect {
|
|
49
|
+
margin-left: 10px }` for the *other* inline pickers.
|
|
50
|
+
|
|
51
|
+
Do not put the gutter on `Picker`. A control that ships its own
|
|
52
|
+
margin is a control that fights `Field` (`flex flex-col gap-1.5`) and
|
|
53
|
+
every toolbar row. The parent that decided to sit text next to a
|
|
54
|
+
trigger also owns the space:
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
The same rule is `Button`, `Select`, and a `Listbox` trigger. They are
|
|
59
|
+
all flush; they are all the same trap.
|
|
60
|
+
|
|
61
|
+
## A stretched trigger reads like a select
|
|
62
|
+
|
|
63
|
+
`Picker` is a `Button`, and a `Button` centers its content. Inside a `Field` — a `flex-col`,
|
|
64
|
+
so the trigger stretches to the column — or under `w-full`, that used to give a full-width bar
|
|
65
|
+
with the value floating in the middle. The trigger now lays its value out at the **inline
|
|
66
|
+
start** and the chevron at the **inline end**, and a value wider than the trigger truncates
|
|
67
|
+
with an ellipsis rather than pushing the chevron out. The full value stays in the accessible
|
|
68
|
+
name and in the open list.
|
|
69
|
+
|
|
70
|
+
The width still comes from the container: a trigger the parent does not stretch keeps its
|
|
71
|
+
content width and renders exactly as before.
|
|
72
|
+
|
|
73
|
+
## `id` does not survive; `data-testid` does
|
|
74
|
+
|
|
75
|
+
`useAnchoredOverlay` overwrites the trigger's `id` with a generated one so the portalled
|
|
76
|
+
listbox can point `aria-labelledby` across at it. An `id` passed to `Picker` is therefore
|
|
77
|
+
silently replaced — queuepilot found this the hard way and moved its e2e handles to
|
|
78
|
+
`data-testid`, which nothing injects. Every other button prop (`data-*`, `onClick`, `form`,
|
|
79
|
+
…) passes straight through; an `onClick` you pass runs before the panel toggles, which is how
|
|
80
|
+
a picker inside a clickable row stops the event reaching its parent.
|
|
81
|
+
|
|
82
|
+
## Not the component of `useSinglePicker`
|
|
83
|
+
|
|
84
|
+
The state layer has `useSinglePicker` and `useMultiplePicker`, and the name invites the
|
|
85
|
+
question. `useSinglePicker` is a **state kind** that `Listbox`, `Combobox` and `Tabs` all
|
|
86
|
+
compose; it has no component of its own. `Picker` owns a `useVisibility` and delegates
|
|
87
|
+
selection to `Listbox`, which is where that state actually lives.
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { useState } from "react"
|
|
91
|
+
|
|
92
|
+
function LanguagePicker() {
|
|
93
|
+
const [language, setLanguage] = useState("en")
|
|
94
|
+
return <Picker label="Language" value={language} onChange={setLanguage}
|
|
95
|
+
options={[{ label: "English", value: "en" }, { label: "Spanish", value: "es" }]} />
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Published TypeScript API
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const Picker: ({ appearance, className, iconEnd, intent, isDisabled, label, onChange, options, placement, placeholder, size, value, ...buttonProps }: PickerProps) => ReactNode
|
|
103
|
+
|
|
104
|
+
type PickerProps = Omit<ComponentPropsWithRef<"button">, "disabled" | "onChange" | "value"> & {
|
|
105
|
+
appearance?: IntentAppearance;
|
|
106
|
+
className?: string;
|
|
107
|
+
intent?: IntentName;
|
|
108
|
+
isDisabled?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* What the control is FOR — "Language", "Quantifier", "Rule type".
|
|
111
|
+
* Not the current value; that is read off `options`.
|
|
112
|
+
*/
|
|
113
|
+
label: string;
|
|
114
|
+
/**
|
|
115
|
+
* Defaults to a chevron. Pass `null` to drop it — a picker rendered
|
|
116
|
+
* inside a denser control row may not want the affordance, and a
|
|
117
|
+
* refactor moving an existing hand-rolled trigger onto `Picker`
|
|
118
|
+
* stays pixel-identical by passing `null` rather than re-baselining
|
|
119
|
+
* every screenshot that contains it.
|
|
120
|
+
*/
|
|
121
|
+
iconEnd?: ReactNode;
|
|
122
|
+
onChange: (value: string) => void;
|
|
123
|
+
options: readonly PickerOption[];
|
|
124
|
+
placement?: Placement;
|
|
125
|
+
/** Read by the trigger when `value` matches no option. */
|
|
126
|
+
placeholder?: string;
|
|
127
|
+
size?: ControlSize;
|
|
128
|
+
value?: string;
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
[Full declarations](../../dist/Picker/Picker.d.ts)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Popover
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Popover } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Replaces mux-magic's `@radix-ui/react-popover` re-export — a rewrite rather than a swap,
|
|
8
|
+
for one reason: **Radix owns `open`.** Wrapping it leaves `useVisibility` and Radix both
|
|
9
|
+
believing they hold the state, which is the conflict the whole state layer exists to
|
|
10
|
+
avoid.
|
|
11
|
+
|
|
12
|
+
## floating-ui, and only for what it is good at
|
|
13
|
+
|
|
14
|
+
`@floating-ui/react` is the layer Radix, Base UI, and Ark UI are all *built on*, and it is
|
|
15
|
+
**controlled by construction**: you pass state in and it never stores any.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
useFloating({
|
|
19
|
+
open: isVisible, // ← read-only. Charcuterie stays the owner.
|
|
20
|
+
onOpenChange: (isNext) => { if (!isNext) hide() },
|
|
21
|
+
middleware: [offset(8), flip(), shift({ padding: 8 })],
|
|
22
|
+
strategy: "fixed",
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
It is used for the three things only it can do — collision handling, a real dismiss layer,
|
|
27
|
+
and focus management — all consolidated in `useAnchoredOverlay`. The positioning strategy
|
|
28
|
+
and the ARIA wiring come from the platform and from `useRole`.
|
|
29
|
+
|
|
30
|
+
Passing `open:` *into* floating-ui does not violate the `is`/`has` rule; the adapter
|
|
31
|
+
boundary is exactly the carve-out that rule already has
|
|
32
|
+
([decision](https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-07-29-is-has-rule-has-no-external-api-carve-out.md)).
|
|
33
|
+
|
|
34
|
+
## Portalled, not the top layer
|
|
35
|
+
|
|
36
|
+
The panel renders in a `FloatingPortal` at `document.body`. `popover="manual"` was reached
|
|
37
|
+
for first — no `z-index` contest, no portal — but the top layer does not escape an
|
|
38
|
+
`overflow: hidden` ancestor's *clipping* in every case the fleet hit, and a portal does
|
|
39
|
+
([decision](https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-08-03-overlays-portal-to-the-body-not-the-top-layer.md)).
|
|
40
|
+
|
|
41
|
+
The objection a portal used to raise — that it moves the panel out of a scoped `canvas`
|
|
42
|
+
query — is answered:
|
|
43
|
+
|
|
44
|
+
> `useRole` writes `aria-controls` on the trigger pointing at the panel `id`, so
|
|
45
|
+
> trigger→panel stays followable across the boundary (the test asserts it). And the story
|
|
46
|
+
> scopes panel queries to `within(document.body)` while `expectAgentDrivable` — structural
|
|
47
|
+
> — needs no change.
|
|
48
|
+
|
|
49
|
+
`useDismiss` owns Escape and outside-press through our callback, so Charcuterie stays the
|
|
50
|
+
only thing that decides `isVisible`. `strategy: "fixed"` keeps the coordinates
|
|
51
|
+
viewport-relative; `AllVariants` asserts the panel is positioned at all, for exactly this
|
|
52
|
+
reason.
|
|
53
|
+
|
|
54
|
+
## The name is required
|
|
55
|
+
|
|
56
|
+
`role="dialog"` takes **no accessible name from its content**, so `heading` is required and
|
|
57
|
+
becomes `aria-label`. An unnamed panel is announced as "dialog" and is unfindable by
|
|
58
|
+
`getByRole("dialog", { name })` — the same trap `Spinner` walked into in M3 with
|
|
59
|
+
`role="status"`
|
|
60
|
+
([decision](https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-07-29-status-regions-carry-an-aria-label.md)).
|
|
61
|
+
|
|
62
|
+
`aria-expanded`, `aria-haspopup`, and `aria-controls` on the trigger, and `id` and `role`
|
|
63
|
+
on the panel, all come from `useRole` — one source for both ends of the link, because a
|
|
64
|
+
hand-written `aria-controls` pointing at an id that moved renders identically and
|
|
65
|
+
announces nothing.
|
|
66
|
+
|
|
67
|
+
## The trigger is cloned, not wrapped
|
|
68
|
+
|
|
69
|
+
`useClonedChild` injects the reference props and the ref into whatever button you already
|
|
70
|
+
have. An extra `<div>` around it is how a toolbar's layout quietly changes, and it is why
|
|
71
|
+
this is the pattern v1 chose and M2 ported.
|
|
72
|
+
|
|
73
|
+
It **composes** rather than overwrites: your button's own `ref` and its own `onClick` are
|
|
74
|
+
still called, with the popover's added. Until 1.0.1 they were replaced — silently, because a
|
|
75
|
+
ref that is never called and a handler that never runs both look exactly like nothing
|
|
76
|
+
happening.
|
|
77
|
+
|
|
78
|
+
## Escape *is* pressable here
|
|
79
|
+
|
|
80
|
+
Unlike `Modal`'s. `useDismiss` listens for a keydown rather than relying on a UA default
|
|
81
|
+
action, and a synthetic keydown is a real keydown as far as a listener is concerned — so
|
|
82
|
+
the `Interactive` story presses it for real, and also dismisses by pressing the page
|
|
83
|
+
behind the panel.
|
|
84
|
+
|
|
85
|
+
A popover is positioned against the **viewport**, so `Responsive` is three triggers pinned
|
|
86
|
+
to three edges rather than a `ContainerBoard`. The assertion is that the panel stays
|
|
87
|
+
inside the viewport — which is all `flip` and `shift` actually promise; asserting a
|
|
88
|
+
specific side would be asserting the collision did not happen.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { Button, Checkbox } from "@charcuterie/ui"
|
|
92
|
+
import { useVisibility } from "@charcuterie/logic"
|
|
93
|
+
|
|
94
|
+
function Filters() {
|
|
95
|
+
const { hide, isVisible, toggle } = useVisibility()
|
|
96
|
+
return <Popover heading="Filters" isVisible={isVisible} onDismiss={hide}
|
|
97
|
+
trigger={<Button onClick={toggle}>Filters</Button>}>
|
|
98
|
+
<Checkbox label="Include completed" />
|
|
99
|
+
</Popover>
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Published TypeScript API
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const Popover: ({ children, className, heading, isVisible, onDismiss, placement, trigger, }: PopoverProps) => ReactNode
|
|
107
|
+
|
|
108
|
+
type PopoverProps = {
|
|
109
|
+
children: ReactNode;
|
|
110
|
+
className?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Required, and it becomes the panel's `aria-label`. A
|
|
113
|
+
* `role="dialog"` takes **no accessible name from its content**,
|
|
114
|
+
* so an unnamed one is announced as "dialog" and is unfindable
|
|
115
|
+
* by `getByRole("dialog", { name })` — the same trap `Spinner`
|
|
116
|
+
* walked into in M3 with `role="status"`.
|
|
117
|
+
*/
|
|
118
|
+
heading: string;
|
|
119
|
+
isVisible: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Outside press and Escape both land here, through floating-ui's
|
|
122
|
+
* `useDismiss`. Wire it to a `useVisibility()`'s `hide`.
|
|
123
|
+
*/
|
|
124
|
+
onDismiss: () => void;
|
|
125
|
+
placement?: Placement;
|
|
126
|
+
/**
|
|
127
|
+
* The control the panel hangs off. **Cloned, not wrapped** — an
|
|
128
|
+
* extra `<div>` around a button is how a toolbar's layout
|
|
129
|
+
* quietly changes.
|
|
130
|
+
*/
|
|
131
|
+
trigger: ReactElement;
|
|
132
|
+
};
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
[Full declarations](../../dist/Popover/Popover.d.ts)
|