@charcuterie/ui 4.30.0 → 4.31.1
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/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/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
- package/src/sourceRules.test.ts +16 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# ColorSchemeSwitcher
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { ColorSchemeSwitcher } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The connected switcher — **Layer 3, and the only layer that touches the browser.** It wires
|
|
8
|
+
the `useColorScheme` hook to the three defaults from `@charcuterie/logic/browser`
|
|
9
|
+
(`matchMedia` + `localStorage` + `data-scheme` on `<html>`) and renders the presentational
|
|
10
|
+
[`ColorSchemeToggle`](ColorSchemeToggle.md). Drop it in and the app
|
|
11
|
+
follows the OS, remembers the user's choice, and re-themes with zero React re-render.
|
|
12
|
+
|
|
13
|
+
## Tone is neutral chrome
|
|
14
|
+
|
|
15
|
+
Like `ColorSchemeToggle`, this forwards `intent="neutral"` to the button by default — a
|
|
16
|
+
scheme switcher is chrome, not an accent action, so its ghost hover is the neutral surface
|
|
17
|
+
rather than accent-violet. Pass `intent` (any tone `Button` accepts) to change it.
|
|
18
|
+
|
|
19
|
+
## Every seam is overridable — that is the point
|
|
20
|
+
|
|
21
|
+
`resolver`, `persistence`, and `apply` all default to the browser implementations but can be
|
|
22
|
+
replaced. Isolating the browser dependency to this one component is what lets a **non-browser
|
|
23
|
+
host** reuse the entire stack unchanged.
|
|
24
|
+
|
|
25
|
+
### Electron (`nativeTheme`) — copy-paste
|
|
26
|
+
|
|
27
|
+
The image-viewer is Electron, which owns the OS appearance through `nativeTheme`. Pass it as
|
|
28
|
+
the resolver and nothing else changes:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { ColorSchemeSwitcher } from "@charcuterie/ui";
|
|
32
|
+
import type { ColorSchemeResolver } from "@charcuterie/logic";
|
|
33
|
+
import { nativeTheme } from "electron";
|
|
34
|
+
import { Monitor, Moon, Sun } from "lucide-react";
|
|
35
|
+
|
|
36
|
+
const nativeThemeResolver: ColorSchemeResolver = {
|
|
37
|
+
get: () => (nativeTheme.shouldUseDarkColors ? "dark" : "light"),
|
|
38
|
+
subscribe: (listener) => {
|
|
39
|
+
nativeTheme.on("updated", listener);
|
|
40
|
+
return () => nativeTheme.off("updated", listener);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
<ColorSchemeSwitcher
|
|
45
|
+
resolver={nativeThemeResolver}
|
|
46
|
+
icons={{ light: <Sun />, dark: <Moon />, system: <Monitor /> }}
|
|
47
|
+
/>;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`persistence` and `apply` keep their browser defaults in an Electron **renderer** (it has
|
|
51
|
+
`localStorage` and a `document`). Only the resolver needs replacing, because only the OS
|
|
52
|
+
answer comes from outside the DOM.
|
|
53
|
+
|
|
54
|
+
### React-Native — the shape
|
|
55
|
+
|
|
56
|
+
RN has no `data-scheme` and no `matchMedia`. Replace **all three** seams: a resolver over
|
|
57
|
+
`Appearance.getColorScheme()` / `Appearance.addChangeListener`, a persistence over
|
|
58
|
+
`AsyncStorage`, and an `apply` that sets a theme **context value** instead of a DOM
|
|
59
|
+
attribute. `ColorSchemeToggle` renders as-is; only the seams differ.
|
|
60
|
+
|
|
61
|
+
## First paint
|
|
62
|
+
|
|
63
|
+
Following the OS/persisted choice means `<html data-scheme>` must be set **before first
|
|
64
|
+
paint**, or the page flashes the wrong theme for a frame. `@charcuterie/tokens` ships the
|
|
65
|
+
inline snippet — `buildFirstPaintScript(variant, { storageKey })`, emitted to
|
|
66
|
+
`dist/first-paint-script.html`. Paste it into `<head>` before any stylesheet, and keep its
|
|
67
|
+
`storageKey` equal to the one `localStoragePersistence(key)` uses — the shared default is
|
|
68
|
+
`DEFAULT_COLOR_SCHEME_STORAGE_KEY` (`"charcuterie-scheme"`), exported from both packages.
|
|
69
|
+
|
|
70
|
+
## Published TypeScript API
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const ColorSchemeSwitcher: ({ apply, icons, order, persistence, resolver, storageKey, ...toggleProps }: ColorSchemeSwitcherProps) => ReactNode
|
|
74
|
+
|
|
75
|
+
type ColorSchemeSwitcherProps = Pick<ColorSchemeToggleProps, "appearance" | "className" | "intent" | "isDisabled" | "label" | "order" | "size"> & {
|
|
76
|
+
/** Override where the resolved scheme is written. Default `<html>`. */
|
|
77
|
+
apply?: ColorSchemeApplier;
|
|
78
|
+
icons: ColorSchemeIcons;
|
|
79
|
+
/** Override persistence. Default `localStorage` under `storageKey`. */
|
|
80
|
+
persistence?: ColorSchemePersistence;
|
|
81
|
+
/**
|
|
82
|
+
* Override the OS resolver. Default `matchMedia`. This is the seam
|
|
83
|
+
* the image-viewer passes Electron `nativeTheme` into, and a
|
|
84
|
+
* future React-Native app passes `Appearance` — the whole reason
|
|
85
|
+
* the browser dependency is isolated to this one layer.
|
|
86
|
+
*/
|
|
87
|
+
resolver?: ColorSchemeResolver;
|
|
88
|
+
storageKey?: string;
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
[Full declarations](../../dist/ColorSchemeSwitcher/ColorSchemeSwitcher.d.ts)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# ColorSchemeToggle
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { ColorSchemeToggle } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The cycling colour-scheme button — **light → dark → system → light**. Layer 2 of three:
|
|
8
|
+
presentational and **controlled**, with no `matchMedia`, `localStorage`, or `document` in
|
|
9
|
+
sight. It renders the current `mode` and reports the next one through `onCycle`; it stores
|
|
10
|
+
nothing.
|
|
11
|
+
|
|
12
|
+
That split is deliberate. The browser dependency lives one layer up in
|
|
13
|
+
[`ColorSchemeSwitcher`](ColorSchemeSwitcher.md), so this component
|
|
14
|
+
runs unchanged in any runtime — a plain React app wires `onCycle` to `useState`, an Electron
|
|
15
|
+
or React-Native host wires it to `useColorScheme` with its own resolver.
|
|
16
|
+
|
|
17
|
+
## `mode` vs scheme
|
|
18
|
+
|
|
19
|
+
`mode` is the three-way user preference — `"light" | "dark" | "system"`. It is **not** a
|
|
20
|
+
`data-scheme` value: `data-scheme` only ever holds `"light"` or `"dark"`. Resolving
|
|
21
|
+
`system` to a concrete scheme is the connected layer's job, not this one's.
|
|
22
|
+
|
|
23
|
+
## Icons are yours
|
|
24
|
+
|
|
25
|
+
The library ships **no icons**
|
|
26
|
+
(decision) — `icons` is a `ReactNode` per mode,
|
|
27
|
+
and an app passes lucide `Sun` / `Moon` / `Monitor` (the fleet recommendation). The glyph is
|
|
28
|
+
`aria-hidden`; the button's name comes from `label`, which states the current mode so the
|
|
29
|
+
control is agent-drivable and a screen reader that lands on it hears "Colour scheme: system"
|
|
30
|
+
rather than a nameless button.
|
|
31
|
+
|
|
32
|
+
## Intent is `neutral`, not accent
|
|
33
|
+
|
|
34
|
+
`intent` is the same tone union `Button`/`IconButton` accept, and it **defaults to
|
|
35
|
+
`neutral`** here on purpose. A scheme switcher is toolbar chrome, so its ghost hover reads
|
|
36
|
+
as `hover:bg-intent-neutral-surface` and its icon as `text-intent-neutral-content` —
|
|
37
|
+
chrome, not a violet accent action. `IconButton`'s own default is `accent`, which on real
|
|
38
|
+
app chrome made this control look like a call-to-action; forwarding `neutral` is the fix,
|
|
39
|
+
and it means a consumer no longer needs an `!important` className to tone it down. Pass
|
|
40
|
+
`intent="accent"` (or any tone) to opt back in.
|
|
41
|
+
|
|
42
|
+
## Cycling is the only form, for now
|
|
43
|
+
|
|
44
|
+
A segmented, all-three-visible `ColorSchemePicker` was considered and deferred (owner chose
|
|
45
|
+
cycling-only, 2026-08-03). `icons` and `order` are shaped so that form can be added later
|
|
46
|
+
without changing this API.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import type { ComponentProps } from "react"
|
|
50
|
+
|
|
51
|
+
function SchemeControl({ icons, mode, onCycle }: ComponentProps<typeof ColorSchemeToggle>) {
|
|
52
|
+
return <ColorSchemeToggle icons={icons} mode={mode} onCycle={onCycle} />
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Published TypeScript API
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const ColorSchemeToggle: ({ appearance, className, icons, intent, isDisabled, label, mode, onCycle, order, size, }: ColorSchemeToggleProps) => ReactNode
|
|
60
|
+
|
|
61
|
+
type ColorSchemeToggleProps = {
|
|
62
|
+
appearance?: IntentAppearance;
|
|
63
|
+
className?: string;
|
|
64
|
+
icons: ColorSchemeIcons;
|
|
65
|
+
/**
|
|
66
|
+
* The intent (tone) forwarded to the underlying `IconButton` — the
|
|
67
|
+
* same union `Button`/`IconButton` accept. **Defaults to `neutral`**,
|
|
68
|
+
* not `accent`: a scheme switcher is toolbar chrome, so its ghost
|
|
69
|
+
* hover reads as `hover:bg-intent-neutral-surface` and its icon as
|
|
70
|
+
* `text-intent-neutral-content` rather than accent-violet. Pass
|
|
71
|
+
* `intent="accent"` (or any tone) to make it an accent action.
|
|
72
|
+
*/
|
|
73
|
+
intent?: IntentName;
|
|
74
|
+
isDisabled?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Builds the accessible name from the current and next mode.
|
|
77
|
+
* Default announces the current mode and where a press goes —
|
|
78
|
+
* "Colour scheme: dark. Activate to switch to system." — so the
|
|
79
|
+
* name updates as the control cycles and
|
|
80
|
+
* `getByRole("button", { name: /colour scheme/i })` resolves.
|
|
81
|
+
*/
|
|
82
|
+
label?: (mode: ColorSchemeMode, nextMode: ColorSchemeMode) => string;
|
|
83
|
+
mode: ColorSchemeMode;
|
|
84
|
+
/**
|
|
85
|
+
* Called with the next mode on activation. **Controlled**: this
|
|
86
|
+
* component stores nothing — it renders `mode` and reports intent,
|
|
87
|
+
* which is what keeps it free of `matchMedia`/`document` and
|
|
88
|
+
* usable in any runtime. `<ColorSchemeSwitcher>` wires this to the
|
|
89
|
+
* `useColorScheme` hook; a plain consumer wires it to its own
|
|
90
|
+
* state.
|
|
91
|
+
*/
|
|
92
|
+
onCycle: (nextMode: ColorSchemeMode) => void;
|
|
93
|
+
order?: readonly ColorSchemeMode[];
|
|
94
|
+
size?: ControlSize;
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
[Full declarations](../../dist/ColorSchemeToggle/ColorSchemeToggle.d.ts)
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Combobox
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { Combobox } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The searchable, filtering, virtualized picker — the other half of the picker family, and
|
|
8
|
+
the one that consolidates the fleet's hand-rolled dropdowns
|
|
9
|
+
([decision](https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-08-03-listbox-and-combobox-are-siblings-of-select.md)).
|
|
10
|
+
Use it when the list is long enough to search or filter; reach for
|
|
11
|
+
[`Listbox`](Listbox.md) for a short rich-option list, and the
|
|
12
|
+
native [`Select`](Select.md) for a plain one.
|
|
13
|
+
|
|
14
|
+
## The ARIA is forced, not stylistic
|
|
15
|
+
|
|
16
|
+
Unlike `Listbox`, **focus stays in the text input**, so the active option is tracked with
|
|
17
|
+
`aria-activedescendant`, not roving tabindex. The input is the `role="combobox"`
|
|
18
|
+
(`aria-autocomplete="list"`, `aria-expanded`, `aria-controls`); the popup is a
|
|
19
|
+
`role="listbox"`. Arrows move the active descendant while the caret stays put; Enter
|
|
20
|
+
selects; Escape clears the query before it closes. The options are `<div>`-shaped
|
|
21
|
+
`role="option"`s with **zero** tab stops — a combobox popup legitimately has none.
|
|
22
|
+
|
|
23
|
+
## Filtering is the consumer's, or the component's
|
|
24
|
+
|
|
25
|
+
Omit `onQueryChange` and the list filters internally by `textValue`. Supply it — a
|
|
26
|
+
react-query search, say — and you own the query: the `options` then arrive pre-filtered,
|
|
27
|
+
and the debounce, the request token, and the per-parent cache stay yours, exactly the way
|
|
28
|
+
`PathPicker` already splits async work.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Loading, error, empty, footer, creatable, multiple
|
|
33
|
+
|
|
34
|
+
`isLoading` and `error` are panel states (only `PathPicker` had all of them); an empty
|
|
35
|
+
result shows `emptyLabel` and stays open. `footer` is a sticky hint (`LinkPicker`'s "type a
|
|
36
|
+
path directly"). `isCreatable` lets Enter commit the raw query (`AssFieldPicker`), and Tab
|
|
37
|
+
accepts the active suggestion (`PathPicker`). `isMultiple` renders the chosen values as
|
|
38
|
+
removable chips rather than filling the input, and keeps the popup open.
|
|
39
|
+
|
|
40
|
+
## Attached input & drill-down
|
|
41
|
+
|
|
42
|
+
Supply `inputRef` and Combobox stops rendering its own input: it anchors a **list-only**
|
|
43
|
+
popup to the consumer's `<input>`, mirrors the combobox ARIA (`role`, `aria-controls`,
|
|
44
|
+
`aria-activedescendant`) onto it, and drives arrows/Enter/Tab/Escape off it while focus
|
|
45
|
+
stays put. Use it when the field is **both the value and the query** — a path field whose
|
|
46
|
+
text you type *and* filter by, the shape `PathPicker` needs.
|
|
47
|
+
|
|
48
|
+
The consumer owns the input's `value`/`onChange` (wire them to the controlled `query`,
|
|
49
|
+
which is then required) **and** `isVisible`. Because of that, **a select does not
|
|
50
|
+
auto-dismiss** in this mode: `onSelect` fires and the consumer decides what happens next —
|
|
51
|
+
append the folder and leave `isVisible` on to drill deeper (the popup re-queries from the
|
|
52
|
+
new path and stays open), or call its own `close()` to finish. Enter and Tab both accept
|
|
53
|
+
the active option; Escape closes outright. Single-select only (`isMultiple` is classic-mode
|
|
54
|
+
only, and it stays the only mode that keeps the popup open on a normal select).
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Virtualization, and why `aria-setsize` is not optional
|
|
59
|
+
|
|
60
|
+
Above ~100 options (or with `isVirtualized`), the list is windowed with
|
|
61
|
+
`@tanstack/react-virtual` — the second runtime dependency this package has ever taken (MIT,
|
|
62
|
+
US-origin, ~4 KB gz). Because most of the list is not in the DOM, every windowed option
|
|
63
|
+
**must** carry `aria-setsize` and `aria-posinset`, or a screen reader announces "2 of 12"
|
|
64
|
+
for a 4,000-item list. Below the threshold the list is plain DOM.
|
|
65
|
+
|
|
66
|
+
## One panel, one row size
|
|
67
|
+
|
|
68
|
+
`itemSize` drives the search field **and** the options together, from the same
|
|
69
|
+
density-aware `--control-height-*` tokens a `Button` reads. It defaults to `md`, so at the
|
|
70
|
+
default a trigger, the search field and every option are all 2.25rem.
|
|
71
|
+
|
|
72
|
+
Covering the search row is the point rather than a bonus. The report that started this was
|
|
73
|
+
that a `Combobox`'s trigger was bigger than the options under it — but the panel's own
|
|
74
|
+
field was bigger than them too, and **two sizes inside one panel** is the defect rather
|
|
75
|
+
than either number being wrong.
|
|
76
|
+
|
|
77
|
+
It also retires a hand-picked number. The search row used to carry `px-3` to line its caret
|
|
78
|
+
up with the option labels below it, which worked only while the option padding was a
|
|
79
|
+
hardcoded `px-2`; it is now wrapped in the list's own `p-1` and given the same row-size
|
|
80
|
+
class, so the two cannot drift apart again.
|
|
81
|
+
|
|
82
|
+
`lg` is the fat one — 2.75rem, the 44px WCAG 2.5.5 target. A window shorter than 40rem
|
|
83
|
+
steps each size down one step on its own.
|
|
84
|
+
|
|
85
|
+
The virtualizer's `estimateSize` tracks `itemSize` too. Every row is re-measured
|
|
86
|
+
immediately, so the estimate only decides how far the scrollbar lies before the first
|
|
87
|
+
measurement lands — but a `lg` list opening with a scrollbar a third too short and visibly
|
|
88
|
+
settling is exactly the kind of thing nobody files a bug about.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { useState } from "react"
|
|
92
|
+
|
|
93
|
+
function FruitChoice() {
|
|
94
|
+
const [query, setQuery] = useState("")
|
|
95
|
+
const [isVisible, setIsVisible] = useState(true)
|
|
96
|
+
const options = [{ label: "Apple", value: "apple" }].filter(({ label }) =>
|
|
97
|
+
label.toLowerCase().includes(query.toLowerCase()))
|
|
98
|
+
return <Combobox isVisible={isVisible} options={options} query={query}
|
|
99
|
+
placeholder="Find fruit" onQueryChange={setQuery}
|
|
100
|
+
onDismiss={() => setIsVisible(false)}
|
|
101
|
+
onSelect={(value) => { setQuery(value); setIsVisible(false) }} />
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Published TypeScript API
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const Combobox: ({ className, emptyLabel, error, footer, inputRef, isCreatable, isLoading, isMultiple, isVirtualized, isVisible, itemSize: requestedItemSize, onDismiss, onQueryChange, onSelect, options, placeholder, query, selectedValue, trigger, }: ComboboxProps) => ReactNode
|
|
109
|
+
|
|
110
|
+
type ComboboxProps = {
|
|
111
|
+
className?: string;
|
|
112
|
+
/** Shown when nothing matches. Default "No matches". */
|
|
113
|
+
emptyLabel?: string;
|
|
114
|
+
/** The error panel state (`PathPicker`). */
|
|
115
|
+
error?: ReactNode;
|
|
116
|
+
/** A sticky footer hint (`LinkPicker`'s "type a path directly"). */
|
|
117
|
+
footer?: ReactNode;
|
|
118
|
+
/**
|
|
119
|
+
* Attached-input mode. Supply the consumer's own `<input>` and
|
|
120
|
+
* Combobox stops rendering its internal input/chip bar: it anchors the
|
|
121
|
+
* popup to this element, drives arrow/Enter/Tab/Escape off it, and
|
|
122
|
+
* mirrors the active option onto it for a screen reader. The consumer
|
|
123
|
+
* owns the input's `value`/`onChange` (wire them to the controlled
|
|
124
|
+
* `query`, which is then required) **and** `isVisible` — so a select
|
|
125
|
+
* does NOT auto-dismiss in this mode; staying open (a folder-picker
|
|
126
|
+
* drilling in) or closing (`onSelect` calls the consumer's own close)
|
|
127
|
+
* is the consumer's call. Options arrive pre-filtered (as with
|
|
128
|
+
* `onQueryChange`). Single-select only; `isMultiple` is not supported
|
|
129
|
+
* here.
|
|
130
|
+
*/
|
|
131
|
+
inputRef?: RefObject<HTMLInputElement | null>;
|
|
132
|
+
/** Enter commits the raw query as a value (`AssFieldPicker`). */
|
|
133
|
+
isCreatable?: boolean;
|
|
134
|
+
/** The loading panel state. */
|
|
135
|
+
isLoading?: boolean;
|
|
136
|
+
/** Multi-select, rendered as removable chips (`LanguageCodeField`). */
|
|
137
|
+
isMultiple?: boolean;
|
|
138
|
+
/** Windowing. Auto-on above ~100 options when left undefined. */
|
|
139
|
+
isVirtualized?: boolean;
|
|
140
|
+
isVisible: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* How tall each option — and the search field above them — is, from
|
|
143
|
+
* the same density-aware tokens a `Button` reads.
|
|
144
|
+
*
|
|
145
|
+
* It covers the search row deliberately. The owner's report was that
|
|
146
|
+
* the panel's own field was visibly bigger than the options under it
|
|
147
|
+
* (*"the button is huge, but the options don't match it"*), and two
|
|
148
|
+
* sizes inside one panel is the defect. One prop drives both.
|
|
149
|
+
*
|
|
150
|
+
* A short window steps it back down on its own (`usePanelItemSize`).
|
|
151
|
+
*/
|
|
152
|
+
itemSize?: ControlSize;
|
|
153
|
+
onDismiss: () => void;
|
|
154
|
+
onSelect: (value: string) => void;
|
|
155
|
+
/**
|
|
156
|
+
* Omit to filter internally by `textValue`; supply to own the query
|
|
157
|
+
* (a react-query search, say), in which case `options` arrives
|
|
158
|
+
* pre-filtered.
|
|
159
|
+
*/
|
|
160
|
+
onQueryChange?: (query: string) => void;
|
|
161
|
+
options: readonly ListboxItem[];
|
|
162
|
+
placeholder?: string;
|
|
163
|
+
/** Controlled query; uncontrolled when absent. */
|
|
164
|
+
query?: string;
|
|
165
|
+
selectedValue?: readonly string[] | string;
|
|
166
|
+
/**
|
|
167
|
+
* The control the popup hangs off. **Cloned, not wrapped.** Omit only
|
|
168
|
+
* in attached-input mode (`inputRef`), where the consumer's `<input>`
|
|
169
|
+
* is the anchor.
|
|
170
|
+
*/
|
|
171
|
+
trigger?: ReactElement;
|
|
172
|
+
};
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
[Full declarations](../../dist/Combobox/Combobox.d.ts)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# CommandPalette
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { CommandPalette } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
The launcher: a search field over a grouped list, opened over the page. Press **Search**
|
|
8
|
+
below, or press `Ctrl K`, `Ctrl Space` or `/`, or start typing anywhere on the page.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
The library owns the shape. Every name, link and search target is data the app passes in.
|
|
13
|
+
|
|
14
|
+
## It lists something before anything is typed
|
|
15
|
+
|
|
16
|
+
`suggestions` are groups shown the moment it opens — a start page passes "Pinned" and
|
|
17
|
+
"Recently opened". A launcher that shows nothing until you type makes you remember the
|
|
18
|
+
name first, which is the job it was supposed to do.
|
|
19
|
+
|
|
20
|
+
## How typing matches
|
|
21
|
+
|
|
22
|
+
**Word prefixes.** Every typed word must start a word of the title, the `description` or a
|
|
23
|
+
`keyword`, in any order: `serv` finds `Media Server`, `media serv` finds it too, and `edia`
|
|
24
|
+
finds nothing. **Initials** count — `ha` finds `Home Automation` — and a camel-case step
|
|
25
|
+
starts a word, so `bit` finds `qBitTracker`. Case and accents are folded.
|
|
26
|
+
|
|
27
|
+
The tiers, best first: the title starts with the query; every word starts a title word; the
|
|
28
|
+
title's initials; every word starts a word anywhere. Inside a tier, a higher `weight` (an
|
|
29
|
+
open count, say) wins, and then the order of `items`. Matches are grouped under each item's
|
|
30
|
+
`group`, and the groups are ordered by their best match, so the first row — the one Enter
|
|
31
|
+
opens — is always the best match.
|
|
32
|
+
|
|
33
|
+
It is deliberately **not** subsequence ("fuzzy") matching, which accepts any letters in
|
|
34
|
+
order and lets `ha` match `Chat` and `Shared Files`. The logic is
|
|
35
|
+
`rankWordPrefixMatches` in `@charcuterie/logic`, for a list that wants the same rule without
|
|
36
|
+
a palette.
|
|
37
|
+
|
|
38
|
+
**Folders.** A folder's members are ordinary items: flatten them into `items` and put the
|
|
39
|
+
folder's name in `description`, so a hit inside a folder still says where it lives.
|
|
40
|
+
|
|
41
|
+
## Prefix commands and the fallback
|
|
42
|
+
|
|
43
|
+
A short prefix, a space, and a query — `au lego` — lists one row that sends the rest of the
|
|
44
|
+
query to that prefix's target. A prefix with nothing after it is ordinary text. For any
|
|
45
|
+
other query, `getFallbackItem` supplies the last row ("Search the web for …"), so a query
|
|
46
|
+
nothing matches still goes somewhere.
|
|
47
|
+
|
|
48
|
+
## Rows
|
|
49
|
+
|
|
50
|
+
An icon, the title with its matched letters highlighted, a `description`, and a trailing
|
|
51
|
+
`hint`; only the title is required. An item with an `href` is a real `<a href>`, routed
|
|
52
|
+
through `RouterLinkProvider`, so middle-click and "copy link address" work. `onSelect` runs
|
|
53
|
+
on choice, with or without an `href`.
|
|
54
|
+
|
|
55
|
+
## Keys
|
|
56
|
+
|
|
57
|
+
| Key | Does |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `Ctrl K`, `Ctrl Space` (`⌘` on a Mac) | Opens it, from anywhere, a text field included |
|
|
60
|
+
| `/` | Opens it, when focus is not in a field |
|
|
61
|
+
| Any printable key | Opens it with that key as the query, when focus is not in a field |
|
|
62
|
+
| Up, Down | Move the active row |
|
|
63
|
+
| Home, End | First row, last row |
|
|
64
|
+
| Enter | Opens the active row |
|
|
65
|
+
| `Ctrl Enter`, `⌘ Enter` | Opens a link row in a new tab |
|
|
66
|
+
| Escape | Closes, and focus goes back where it was |
|
|
67
|
+
|
|
68
|
+
Focus stays in the field the whole time: the active row is its `aria-activedescendant`, the
|
|
69
|
+
APG combobox pattern `Combobox` uses. The pointer moves the active row too.
|
|
70
|
+
|
|
71
|
+
In this demo every row reports what it chose instead of navigating. On this page the global
|
|
72
|
+
keys open the first palette above; this one opens from its button. Two palettes on one page
|
|
73
|
+
do not both open: the first listener to take a key marks it handled, and the hook leaves a
|
|
74
|
+
handled key alone.
|
|
75
|
+
|
|
76
|
+
## Open state, and the global keys
|
|
77
|
+
|
|
78
|
+
`isVisible` and `onClose` work as on `Modal`. `useCommandPalette()` holds that state and
|
|
79
|
+
registers the keys; `useCommandPaletteHotkeys({ onOpen })` is the keys alone, for an app
|
|
80
|
+
that keeps its own state. The keys are a hook, not something the palette does on mount,
|
|
81
|
+
because a document-wide listener is a page-level decision — a page with its own letter
|
|
82
|
+
shortcuts passes `isOpenedByTyping: false`, or does not call the hook at all.
|
|
83
|
+
|
|
84
|
+
The query is uncontrolled (`defaultQuery`, read each time it opens, which is how a typed
|
|
85
|
+
letter arrives) or controlled (`query` + `onQueryChange`), as on `Combobox`.
|
|
86
|
+
|
|
87
|
+
## Size
|
|
88
|
+
|
|
89
|
+
Like `Dialog`, it is measured against the window, not a container. On a wide window it hangs
|
|
90
|
+
from the top at up to 45rem wide, so the list grows down from a field that does not move. In
|
|
91
|
+
the Narrow View it takes nearly the whole screen, and the footer drops the key hints and
|
|
92
|
+
keeps the prefixes.
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
import type { ComponentProps } from "react"
|
|
96
|
+
import { Button, useCommandPalette } from "@charcuterie/ui"
|
|
97
|
+
|
|
98
|
+
function Commands({ items }: Pick<ComponentProps<typeof CommandPalette>, "items">) {
|
|
99
|
+
const { open, paletteProps } = useCommandPalette()
|
|
100
|
+
return <>
|
|
101
|
+
<Button onClick={() => open()}>Search commands</Button>
|
|
102
|
+
<CommandPalette {...paletteProps} items={items} label="Search commands" />
|
|
103
|
+
</>
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Published TypeScript API
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const CommandPalette: ({ className, isVisible, label, onClose, ...panelProps }: CommandPaletteProps) => ReactNode
|
|
111
|
+
|
|
112
|
+
type CommandPaletteProps = Omit<CommandPalettePanelProps, "inputRef" | "onChoose"> & {
|
|
113
|
+
className?: string;
|
|
114
|
+
isVisible: boolean;
|
|
115
|
+
/** Every route out: Escape, a press outside, and a chosen row. */
|
|
116
|
+
onClose: () => void;
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
[Full declarations](../../dist/CommandPalette/CommandPalette.d.ts)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# ComparisonChart
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { ComparisonChart } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Horizontal TanStack comparisons with one legend and a common zero baseline. Unequal values nest by thickness. Equal or tightly spaced values use separate lanes, retaining proportional lengths. Values appear inside when they fit and beside short bars otherwise. Null is missing, zero is a value. Apps supply data and a formatter; this component never fetches or aggregates.
|
|
8
|
+
|
|
9
|
+
Supply a title and distinct labels. Set `isTableVisible` if readers need exact values in a semantic table.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<ComparisonChart title="Jobs completed" labels={["North", "South"]} isTableVisible
|
|
13
|
+
series={[{ id: "done", label: "Completed", values: [4, 7] }]} />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Published TypeScript API
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const ComparisonChart: ({ title, labels, series, layout, formatValue, isTableVisible, }: ComparisonChartProps) => import("react").JSX.Element
|
|
20
|
+
|
|
21
|
+
type ComparisonChartProps = {
|
|
22
|
+
title: string;
|
|
23
|
+
labels: readonly string[];
|
|
24
|
+
series: readonly ChartSeries[];
|
|
25
|
+
layout?: "nested" | "grouped";
|
|
26
|
+
formatValue?: (value: number) => string;
|
|
27
|
+
isTableVisible?: boolean;
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
[Full declarations](../../dist/ComparisonChart/ComparisonChart.d.ts)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# CopyButton
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { CopyButton } from "@charcuterie/ui"
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
**A button that puts a string on the clipboard and says so.** Press it, the label turns to
|
|
8
|
+
`Copied`, and the caller is told whether that is true.
|
|
9
|
+
|
|
10
|
+
## Where it came from
|
|
11
|
+
|
|
12
|
+
Four repos spell this shape by hand, and no two agree:
|
|
13
|
+
|
|
14
|
+
| Repo | How it copies | What it does when the clipboard says no |
|
|
15
|
+
| --- | --- | --- |
|
|
16
|
+
| mux-magic (`YamlModal`) | flips its own label on a `setTimeout` | nothing — the label still says `Copied!` |
|
|
17
|
+
| spoolbuddy (`Settings`) | 15 lines inline, with the `execCommand` fallback | a toast |
|
|
18
|
+
| bambuddy (`ArchivesPage`) | a menu item, twice in one file | a toast |
|
|
19
|
+
| mail-sifter | a verification-code banner | **marks the mail done anyway** |
|
|
20
|
+
|
|
21
|
+
The last row is why the failure path is a first-class state here rather than a `catch` that
|
|
22
|
+
shrugs. That consumer files the mail away on a copy, so a copy that did not happen has to be
|
|
23
|
+
distinguishable from one that did.
|
|
24
|
+
|
|
25
|
+
## The confirmation is the button
|
|
26
|
+
|
|
27
|
+
The press and the proof are the same object, so the eye does not travel. A toast is the
|
|
28
|
+
right shape for something that happened **somewhere else** — a background job, another pane
|
|
29
|
+
— and the wrong shape for the thing directly under the pointer. A consumer that wants a
|
|
30
|
+
toast as well still gets one from `onCopy`.
|
|
31
|
+
|
|
32
|
+
## The label is a word, and so is the failure
|
|
33
|
+
|
|
34
|
+
`Copy` → `Copied`, with the intent moving to `success` underneath it. The colour is not the
|
|
35
|
+
message: a colour change alone is invisible to a screen reader, unreliable for a
|
|
36
|
+
colour-blind reader, and this library [ships no icons](../building-an-app.md),
|
|
37
|
+
so a tick glyph is not available to carry it either.
|
|
38
|
+
|
|
39
|
+
The refusal says what to do next rather than only that something went wrong.
|
|
40
|
+
|
|
41
|
+
## Three routes to the clipboard
|
|
42
|
+
|
|
43
|
+
`copyText.ts` tries them in order and never throws:
|
|
44
|
+
|
|
45
|
+
1. **`navigator.clipboard.writeText`** — the real API, and it exists only in a *secure
|
|
46
|
+
context*. A `devshare` URL and `localhost` are secure; a plain `http://` dev server on
|
|
47
|
+
the LAN is not.
|
|
48
|
+
2. **A hidden `<textarea>` and `document.execCommand("copy")`** — deprecated, kept because
|
|
49
|
+
it is the only thing that works in that insecure context, and because spoolbuddy already
|
|
50
|
+
carries this exact block inline.
|
|
51
|
+
3. **Report the failure**, so the caller can hold on to whatever it was about to discard.
|
|
52
|
+
|
|
53
|
+
`copy` is injectable, which is how the `Refused` story above exists and how a host with its
|
|
54
|
+
own clipboard bridge — Electron, a kiosk shell — supplies it.
|
|
55
|
+
|
|
56
|
+
## Own labels
|
|
57
|
+
|
|
58
|
+
The labels are content. A surface that copies one specific thing should say which thing.
|
|
59
|
+
|
|
60
|
+
## What it does not do
|
|
61
|
+
|
|
62
|
+
**It does not own the value.** No `children`-as-value, no reading text out of a sibling
|
|
63
|
+
node: the string is a prop, because the thing on screen is regularly not the thing worth
|
|
64
|
+
copying (a masked key, a truncated URL, a code split across two spans).
|
|
65
|
+
|
|
66
|
+
**It does not clear the timer for you and hope.** The confirmation timer is cancelled on
|
|
67
|
+
unmount and on a re-press — two of the four hand-rolled copies set state on an unmounted
|
|
68
|
+
component if you press and navigate away.
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
<CopyButton value="INV-1042">Copy invoice number</CopyButton>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Published TypeScript API
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const CopyButton: ({ appearance, children, confirmDuration, copiedLabel, copy, failedLabel, intent, onClick, onCopy, value, ...buttonProps }: CopyButtonProps) => ReactNode
|
|
78
|
+
|
|
79
|
+
type CopyButtonProps = Omit<ButtonProps, "children" | "isLoading" | "loadingLabel" | "onCopy"> & {
|
|
80
|
+
/**
|
|
81
|
+
* How long the confirmation stays up, in milliseconds.
|
|
82
|
+
*
|
|
83
|
+
* Long enough to be read after the eye has moved back to the form
|
|
84
|
+
* being filled in, short enough that a second copy of a *different*
|
|
85
|
+
* value is not mistaken for the first one's tick.
|
|
86
|
+
*/
|
|
87
|
+
confirmDuration?: number;
|
|
88
|
+
/** Resting label. A word, not a glyph — this library ships no icons. */
|
|
89
|
+
children?: ReactNode;
|
|
90
|
+
/** Shown while the copy is confirmed. */
|
|
91
|
+
copiedLabel?: ReactNode;
|
|
92
|
+
/**
|
|
93
|
+
* The clipboard write, injected. Swapped in tests and in a host
|
|
94
|
+
* that owns its own clipboard bridge (Electron, a kiosk shell).
|
|
95
|
+
*/
|
|
96
|
+
copy?: (value: string) => Promise<boolean> | boolean;
|
|
97
|
+
/** Shown when the clipboard refused. */
|
|
98
|
+
failedLabel?: ReactNode;
|
|
99
|
+
/**
|
|
100
|
+
* Told what actually happened, every press.
|
|
101
|
+
*
|
|
102
|
+
* `isCopied` is the point of the callback rather than a detail: a
|
|
103
|
+
* consumer that files the mail away on a copy must not file it away
|
|
104
|
+
* on a copy the browser refused.
|
|
105
|
+
*/
|
|
106
|
+
onCopy?: (isCopied: boolean, value: string) => void;
|
|
107
|
+
/** The string that goes on the clipboard. */
|
|
108
|
+
value: string;
|
|
109
|
+
};
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
[Full declarations](../../dist/CopyButton/CopyButton.d.ts)
|