@overdoser/react-toolkit 0.18.0 → 0.20.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/AGENTS.md +51 -7
- package/CHANGELOG.md +162 -0
- package/components/Accordion/Accordion.d.ts +94 -0
- package/components/Accordion/Accordion.js +180 -0
- package/components/Accordion/Accordion.module.scss.js +36 -0
- package/components/Accordion/index.d.ts +2 -0
- package/components/Alert/Alert.d.ts +29 -1
- package/components/Alert/Alert.js +44 -30
- package/components/Alert/Alert.module.scss.js +24 -16
- package/components/Alert/index.d.ts +1 -1
- package/components/Card/Card.d.ts +86 -0
- package/components/Card/Card.js +132 -0
- package/components/Card/Card.module.scss.js +60 -0
- package/components/Card/index.d.ts +2 -0
- package/components/Chip/Chip.d.ts +86 -0
- package/components/Chip/Chip.js +141 -0
- package/components/Chip/Chip.module.scss.js +59 -0
- package/components/Chip/index.d.ts +2 -0
- package/components/CodeBlock/CodeBlock.d.ts +78 -0
- package/components/CodeBlock/CodeBlock.js +120 -0
- package/components/CodeBlock/CodeBlock.module.scss.js +43 -0
- package/components/CodeBlock/index.d.ts +2 -0
- package/components/CommandPalette/CommandPalette.d.ts +141 -0
- package/components/CommandPalette/CommandPalette.js +397 -0
- package/components/CommandPalette/CommandPalette.module.scss.js +49 -0
- package/components/CommandPalette/index.d.ts +2 -0
- package/components/ConfirmDialog/ConfirmDialog.d.ts +119 -0
- package/components/ConfirmDialog/ConfirmDialog.js +201 -0
- package/components/ConfirmDialog/ConfirmDialog.module.scss.js +21 -0
- package/components/ConfirmDialog/index.d.ts +2 -0
- package/components/Drawer/Drawer.d.ts +1 -0
- package/components/Drawer/Drawer.js +35 -36
- package/components/Drawer/Drawer.module.scss.js +20 -18
- package/components/Dropdown/Dropdown.d.ts +47 -7
- package/components/Dropdown/Dropdown.js +174 -81
- package/components/Dropdown/Dropdown.module.scss.js +40 -22
- package/components/Dropdown/DropdownItem.d.ts +31 -2
- package/components/Dropdown/DropdownItem.js +54 -27
- package/components/Dropdown/DropdownLabel.d.ts +11 -0
- package/components/Dropdown/DropdownLabel.js +11 -0
- package/components/Dropdown/DropdownSeparator.d.ts +12 -0
- package/components/Dropdown/DropdownSeparator.js +11 -0
- package/components/Dropdown/dropdownContext.d.ts +6 -0
- package/components/Dropdown/dropdownContext.js +5 -0
- package/components/Dropdown/index.d.ts +8 -2
- package/components/Dropdown/useContextMenu.d.ts +32 -0
- package/components/Dropdown/useContextMenu.js +18 -0
- package/components/EmptyState/EmptyState.d.ts +53 -0
- package/components/EmptyState/EmptyState.js +55 -0
- package/components/EmptyState/EmptyState.module.scss.js +25 -0
- package/components/EmptyState/index.d.ts +2 -0
- package/components/Form/FormField.js +25 -24
- package/components/ImageViewer/ImageViewer.d.ts +105 -0
- package/components/ImageViewer/ImageViewer.js +201 -0
- package/components/ImageViewer/ImageViewer.module.scss.js +47 -0
- package/components/ImageViewer/index.d.ts +4 -0
- package/components/ImageViewer/useZoomPan.d.ts +94 -0
- package/components/ImageViewer/useZoomPan.js +141 -0
- package/components/Kbd/Kbd.d.ts +26 -0
- package/components/Kbd/Kbd.js +22 -0
- package/components/Kbd/Kbd.module.scss.js +17 -0
- package/components/Kbd/index.d.ts +2 -0
- package/components/KeyValueList/KeyValueList.d.ts +84 -0
- package/components/KeyValueList/KeyValueList.js +127 -0
- package/components/KeyValueList/KeyValueList.module.scss.js +43 -0
- package/components/KeyValueList/index.d.ts +2 -0
- package/components/Modal/Modal.d.ts +1 -0
- package/components/Modal/Modal.js +40 -41
- package/components/Modal/Modal.module.scss.js +18 -16
- package/components/PageHeader/PageHeader.d.ts +61 -0
- package/components/PageHeader/PageHeader.js +73 -0
- package/components/PageHeader/PageHeader.module.scss.js +43 -0
- package/components/PageHeader/index.d.ts +2 -0
- package/components/ProgressBar/ProgressBar.d.ts +74 -0
- package/components/ProgressBar/ProgressBar.js +90 -0
- package/components/ProgressBar/ProgressBar.module.scss.js +51 -0
- package/components/ProgressBar/index.d.ts +2 -0
- package/components/RelativeTime/RelativeTime.d.ts +45 -0
- package/components/RelativeTime/RelativeTime.js +43 -0
- package/components/RelativeTime/RelativeTime.module.scss.js +7 -0
- package/components/RelativeTime/index.d.ts +2 -0
- package/components/SegmentedControl/SegmentedControl.d.ts +84 -0
- package/components/SegmentedControl/SegmentedControl.js +131 -0
- package/components/SegmentedControl/SegmentedControl.module.scss.js +39 -0
- package/components/SegmentedControl/index.d.ts +2 -0
- package/components/SplitPane/SplitPane.d.ts +61 -0
- package/components/SplitPane/SplitPane.js +171 -0
- package/components/SplitPane/SplitPane.module.scss.js +25 -0
- package/components/SplitPane/index.d.ts +2 -0
- package/components/StatCard/StatCard.d.ts +105 -0
- package/components/StatCard/StatCard.js +127 -0
- package/components/StatCard/StatCard.module.scss.js +72 -0
- package/components/StatCard/index.d.ts +2 -0
- package/components/StatusDot/StatusDot.d.ts +33 -0
- package/components/StatusDot/StatusDot.js +39 -0
- package/components/StatusDot/StatusDot.module.scss.js +32 -0
- package/components/StatusDot/index.d.ts +2 -0
- package/components/Table/Table.d.ts +140 -17
- package/components/Table/Table.js +382 -210
- package/components/Table/Table.module.scss.js +68 -46
- package/components/Table/index.d.ts +1 -1
- package/components/Table/useTableSort.d.ts +1 -1
- package/components/ThemeToggle/ThemeToggle.d.ts +40 -0
- package/components/ThemeToggle/ThemeToggle.js +98 -0
- package/components/ThemeToggle/ThemeToggle.module.scss.js +23 -0
- package/components/ThemeToggle/index.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.d.ts +2 -0
- package/components/inputs/Checkbox/Checkbox.js +29 -28
- package/components/inputs/Checkbox/Checkbox.module.scss.js +8 -6
- package/components/inputs/Input/Input.d.ts +33 -1
- package/components/inputs/Input/Input.js +94 -35
- package/components/inputs/Input/Input.module.scss.js +14 -12
- package/components/inputs/Radio/Radio.d.ts +5 -4
- package/components/inputs/Radio/Radio.js +55 -50
- package/components/inputs/Radio/Radio.module.scss.js +12 -10
- package/components/inputs/SearchInput/SearchInput.d.ts +57 -0
- package/components/inputs/SearchInput/SearchInput.js +116 -0
- package/components/inputs/SearchInput/SearchInput.module.scss.js +13 -0
- package/components/inputs/SearchInput/index.d.ts +2 -0
- package/components/inputs/Select/Select.d.ts +52 -0
- package/components/inputs/Select/Select.js +494 -385
- package/components/inputs/Select/Select.module.scss.js +34 -30
- package/components/inputs/Switch/Switch.d.ts +15 -0
- package/components/inputs/Switch/Switch.js +8 -0
- package/components/inputs/Switch/index.d.ts +2 -0
- package/hooks/useDebouncedValue.d.ts +15 -0
- package/hooks/useDebouncedValue.js +15 -0
- package/hooks/useElementSize.d.ts +20 -0
- package/hooks/useElementSize.js +23 -0
- package/hooks/useKeyboard.d.ts +49 -5
- package/hooks/useKeyboard.js +66 -16
- package/hooks/useMediaQuery.d.ts +14 -0
- package/hooks/useMediaQuery.js +16 -0
- package/hooks/useNow.d.ts +14 -0
- package/hooks/useNow.js +35 -0
- package/hooks/usePersistedState.d.ts +30 -0
- package/hooks/usePersistedState.js +99 -0
- package/hooks/useResizable.d.ts +66 -0
- package/hooks/useResizable.js +105 -0
- package/hooks/useTheme.d.ts +33 -0
- package/hooks/useTheme.js +25 -0
- package/index.css +1 -1
- package/index.d.ts +58 -4
- package/index.js +208 -132
- package/index.layered.css +1 -1
- package/llms.txt +620 -26
- package/manifest.json +1795 -99
- package/package.json +1 -1
- package/recipes/confirm-modal.tsx +65 -53
- package/recipes/floating-copy-button.tsx +32 -28
- package/utils/formatBytes.d.ts +21 -0
- package/utils/formatBytes.js +14 -0
- package/utils/index.d.ts +6 -0
- package/utils/themeScript.d.ts +19 -0
- package/utils/themeScript.js +9 -0
- package/utils/timeAgo.d.ts +33 -0
- package/utils/timeAgo.js +37 -0
package/AGENTS.md
CHANGED
|
@@ -25,6 +25,8 @@ For exhaustive component reference (every prop, every variant, every signature),
|
|
|
25
25
|
```
|
|
26
26
|
It wraps all toolkit CSS in a `crk` cascade layer, so any of your own *unlayered* rules beat it deterministically. See "Customizing styles" below.
|
|
27
27
|
|
|
28
|
+
4. **Dark mode (optional, opt-in):** with no `data-theme` the toolkit is light, so upgrading never changes an app's look. To offer dark mode put `THEME_INIT_SCRIPT` in `<head>` (applies the stored choice before first paint; writes `system` when nothing is stored) and drop `<ThemeToggle />` in the header. A dark-only app just sets `data-theme="dark"` on `<html>`. `data-theme` on any element forces a theme for that subtree. Never hand-roll a theme switch or a second token set.
|
|
29
|
+
|
|
28
30
|
## Import rules
|
|
29
31
|
|
|
30
32
|
- Always import from the package root: `import { Button } from '@overdoser/react-toolkit'`. Do **not** reach into subpaths (`@overdoser/react-toolkit/dist/...`) — they're not part of the public API.
|
|
@@ -47,21 +49,22 @@ For exhaustive component reference (every prop, every variant, every signature),
|
|
|
47
49
|
- Few options, native UX OK → `<Select options={...} />`.
|
|
48
50
|
- Many options, want a search filter → `<Select searchable options={...} />`.
|
|
49
51
|
- Multi-pick with chips → `<Select multiple options={...} onValuesChange={...} />`.
|
|
52
|
+
- Options come from a server as the user types (async autocomplete / combobox) → `<Select searchable onSearch={fetch} loading={…} options={results} selectedLabels={…} />` (same for `multiple`). Don't build a Combobox.
|
|
50
53
|
- You want it to look like a "menu trigger" instead of a form input → `<Dropdown options={...} value={...} onChange={...} />` (select-mode dropdown).
|
|
51
54
|
|
|
52
55
|
- **Need to pick several values from a small fixed set?** → `<CheckboxGroup options={...} value={...} onChange={...} />` (a checkbox list, or `variant="chips"` for toggle chips). For a large/searchable set, prefer `<Select multiple>` instead.
|
|
53
56
|
|
|
54
|
-
- **Need a menu (Edit / Delete / Archive)?** → `<Dropdown trigger={...}>` with `<DropdownItem>` children.
|
|
57
|
+
- **Need a menu (Edit / Delete / Archive)?** → `<Dropdown trigger={...}>` with `<DropdownItem>` children — `icon`, `shortcut={<Kbd …/>}`, `description`, `danger` for destructive items, `checked` for toggles; `<DropdownSeparator>` and `<DropdownLabel>` for structure. **Right-click menu?** → `const menu = useContextMenu()`; put `menu.onContextMenu` on the area and `anchor={menu.anchor} open={menu.open} onOpenChange={menu.onOpenChange}` on the `Dropdown`.
|
|
55
58
|
|
|
56
59
|
- **Need row actions with one default exposed (table "Operations" column)?** → `<SplitButton actions={[...]} />` — flat list of `{ label, onClick?, href?, danger?, disabled? }`; the first action is the visible button, the rest live behind the chevron. `href` actions render as real anchors. Use `Dropdown` menu mode instead when all actions are equal-weight.
|
|
57
60
|
|
|
58
|
-
- **Need a copy-to-clipboard button?** → `<CopyButton value={text} />` (icon + "Copy"→"Copied" morph), or `<CopyButton value={text} iconOnly aria-label="Copy" />` for icon-only. **Other one-shot actions with success feedback (send, download, delete-with-confirm)?** → `<ActionButton icon label successLabel onAction />` — async `onAction` gets a pending spinner; call `context.setProgress(0–100)` inside it for a determinate % + fill bar (downloads); `confirmLabel` adds a two-step confirm for destructive actions. Use plain `Button` when no phase feedback is needed.
|
|
61
|
+
- **Need a copy-to-clipboard button?** → `<CopyButton value={text} />` (icon + "Copy"→"Copied" morph; `value` may be a function returning a string or a `Promise<string>` for lazy/async text, `onCopied` fires after), or `<CopyButton value={text} iconOnly aria-label="Copy" />` for icon-only. **Other one-shot actions with success feedback (send, download, delete-with-confirm)?** → `<ActionButton icon label successLabel onAction />` — async `onAction` gets a pending spinner; call `context.setProgress(0–100)` inside it for a determinate % + fill bar (downloads); `confirmLabel` adds a two-step confirm for destructive actions. Use plain `Button` when no phase feedback is needed.
|
|
59
62
|
|
|
60
63
|
- **Need a like/save/bookmark toggle?** → `<ToggleIconButton icon={<HeartIcon />} aria-label="Like" />` — round icon-only toggle with `aria-pressed`, fill + pop on toggle, optional `burst` ring, `activeColor` for semantic colors. Controlled (`pressed` + `onPressedChange`, optimistic) or uncontrolled (`defaultPressed`). Not for text toggles — it's icon-only by design.
|
|
61
64
|
|
|
62
65
|
- **Need a tooltip / hover card / contextual panel?** → `<Popover trigger={...} content={...} />`.
|
|
63
66
|
|
|
64
|
-
- **Need a confirm prompt
|
|
67
|
+
- **Need a confirm prompt ("Delete this?")?** → mount `<ConfirmProvider>` once, then `const confirm = useConfirm(); if (await confirm({ title, description, danger: true, confirmLabel: 'Delete', onConfirm: () => api.remove(id) })) …` — never `window.confirm`. `requireText` adds type-to-confirm. The controlled `<ConfirmDialog open onConfirm onCancel>` exists for custom flows; `ActionButton confirmLabel` covers an inline two-step confirm on a button. **A full dialog?** → `<Modal>` with `Modal.Header`/`Body`/`Footer`. Always provide either `aria-label` or use a `Modal.Header` (it's auto-wired as `aria-labelledby`).
|
|
65
68
|
|
|
66
69
|
- **Need a slide-in side panel?** → `<Drawer open onClose side="right">` with `Drawer.Header`/`Body`/`Footer`. Same focus-trap/scroll-lock/Escape behavior as `Modal`, but anchored to a screen edge. Use `Modal` for centered dialogs, `Drawer` for side panels.
|
|
67
70
|
|
|
@@ -81,17 +84,57 @@ For exhaustive component reference (every prop, every variant, every signature),
|
|
|
81
84
|
|
|
82
85
|
- **Need a countdown / stopwatch / elapsed display?** → `<Timer mode="countdown|stopwatch" duration={…} variant="digital|ring" label="…" />`. Drive it with `autoStart` + an imperative ref (`start`/`pause`/`reset`/`restart`), or make it display-only with `value`.
|
|
83
86
|
|
|
87
|
+
- **Need a lightbox / image gallery viewer?** → `<ImageViewer open onClose items index onIndexChange showThumbnails />`. Zoom/pan elsewhere → `useZoomPan()`.
|
|
88
|
+
|
|
89
|
+
- **Need a resizable sidebar / editor-preview / terminal split?** → `<SplitPane defaultSize minSize collapsible persistKey>` with two children (nest for 3-way). Custom resizable panel → `useResizable()` and spread `handleProps` on your handle.
|
|
90
|
+
|
|
84
91
|
- **Need a movable panel / floating widget the user can drag around?** → `<Draggable>` wrapping any content. Add a `<Draggable.Handle>` (e.g. a title bar) to restrict the grab area; without one the whole surface drags. Uncontrolled by default (`defaultPosition`); pass `position` + `onDrag` to control it. It's a free-move/reposition primitive — not a sortable list or drag-and-drop-between-zones helper.
|
|
85
92
|
|
|
86
93
|
- **Need transient notifications (toasts)?** → Mount `<ToastProvider>` once near the root (sets `position` / `duration` / `max`); it's the renderer and owns the portal/stack — do NOT render toast JSX yourself. To trigger, import the standalone `toast({ variant, title, description })` and call it from anywhere (no hook/context needed); `toast.dismiss(id)` / `toast.dismissAll()` are attached. A `useToast()` hook returns the same `{ toast, dismiss, dismissAll }` if you prefer hook style.
|
|
87
94
|
|
|
88
95
|
- **Need to switch between sections of content?** → `<Tabs>` with `Tabs.List` / `Tabs.Tab` / `Tabs.Panel`. Each `Tab` and its `Panel` share a `value`. Uncontrolled via `defaultValue` or controlled via `value` + `onValueChange`. Keyboard nav is built in.
|
|
89
96
|
|
|
90
|
-
- **Need an inline status message?** → `<Alert variant="info|success|warning|danger">`. Add `title` for a heading, `onClose` to make it dismissible. For *transient* feedback prefer Toast; use Alert for persistent, in-flow messaging.
|
|
97
|
+
- **Need an inline status message?** → `<Alert variant="info|success|warning|danger">`. Add `title` for a heading, `onClose` to make it dismissible, `action` for a Retry/Undo button. **A full-width page banner (trial ending, offline)?** → `<Alert layout="banner" action onClose>`. For *transient* feedback prefer Toast; use Alert for persistent, in-flow messaging.
|
|
98
|
+
|
|
99
|
+
- **Need a view / period / mode switcher (pill buttons, no panels)?** → `<SegmentedControl options value onChange aria-label />`. Don't use panel-less `Tabs` for it. Multi-select version → `<CheckboxGroup variant="chips">`.
|
|
100
|
+
|
|
101
|
+
- **Need removable / selectable tags (filters, labels, recipients)?** → `<Chip onRemove />`, `<Chip selected onSelectedChange />`, grouped with `<ChipGroup max expandable>`. Read-only status pills stay `<Badge>`.
|
|
102
|
+
|
|
103
|
+
- **Need the page title block (title + actions + breadcrumbs + tabs)?** → `<PageHeader title actions breadcrumbs tabs onBack />`.
|
|
104
|
+
|
|
105
|
+
- **Need collapsible sections / FAQ?** → `<Accordion>` with `Accordion.Item` / `Trigger` / `Content` (or `items={[…]}`).
|
|
106
|
+
|
|
107
|
+
- **Need a label/value detail panel (profile, request headers, config)?** → `<KeyValueList items={[{ label, value, copyable, masked, href }]} layout="rows|grid|inline" />`. Not a `Table`.
|
|
108
|
+
|
|
109
|
+
- **Need KPI tiles?** → `<StatGrid><StatCard label value delta chart={<Sparkline />} /></StatGrid>`; `trendColor="positive-down"` for latency / cost.
|
|
110
|
+
|
|
111
|
+
- **Need a ⌘K command palette?** → `const palette = useCommandPalette(); <CommandPalette {...palette.paletteProps} items={[…]} recentIds={…} />` — groups, nested pages, shortcuts, `href` items, `filter={null}` + `loading` for remote results.
|
|
112
|
+
|
|
113
|
+
- **Need a search box?** → `<SearchInput onSearch hotkey="/" loading />` (debounce, clear, Escape, Kbd hint built in). Don't wire `Input` + `useDebouncedValue` by hand for this.
|
|
114
|
+
|
|
115
|
+
- **Need a toggle switch (on/off setting)?** → `<Switch label="…" checked onChange />` — the same control as `<Checkbox variant="switch">`; binds in `FormField` for a boolean field. Don't hand-roll one.
|
|
116
|
+
|
|
117
|
+
- **Need an empty / no-results / load-error placeholder?** → `<EmptyState title description action={<Button>…</Button>} />` (`variant="error"` for failures, with a Retry button in `action`). Also the right thing to pass as `Table`'s `emptyMessage`.
|
|
118
|
+
|
|
119
|
+
- **Need a progress bar?** → `<ProgressBar value max label showValue />` — omit `value` for indeterminate, `thresholds` for battery/quota colours, `segments` for wizard steps. `ActionButton` already has its own in-button fill for one-shot downloads.
|
|
120
|
+
|
|
121
|
+
- **Need a content container / tile?** → `<Card>` with `Card.Header` / `Card.Body` / `Card.Footer`; `interactive` + `onClick` for a clickable tile, `href` for a link card, `selected` for pick-one grids, `accent` for a colour stripe.
|
|
122
|
+
|
|
123
|
+
- **Need a "3 minutes ago" timestamp?** → `<RelativeTime value={date} />` (live, shared timer; `maxAge` to switch to an absolute date). The plain function is `timeAgo()`.
|
|
124
|
+
|
|
125
|
+
- **Need a light/dark switch?** → `<ThemeToggle />` (+ `THEME_INIT_SCRIPT` in `<head>`); read it with `useTheme()`. See the setup checklist.
|
|
126
|
+
|
|
127
|
+
- **Need a shortcut hint?** → `<Kbd keys={['⌘', 'K']} />` or `<Kbd>Esc</Kbd>`. **Need the shortcut itself?** → `useKeyboard({ 'mod+k': open })` (chords, skips inputs for plain keys).
|
|
128
|
+
|
|
129
|
+
- **Need a persisted preference (sidebar collapsed, theme, column visibility)?** → `usePersistedState(key, initial)`. **Debounced search text?** → `useDebouncedValue`. **Responsive branch?** → `useMediaQuery`. **Element size?** → `useElementSize`. **File sizes?** → `formatBytes`.
|
|
130
|
+
|
|
131
|
+
- **Need a status pill / count / tag?** → `<Badge>`. **A bare coloured status dot (online / degraded / saving…)?** → `<StatusDot status label pulse />`. For loading states: `<Loader>` (page / container loading — wrap content to overlay it without a height jump, `mode="overlay"` drop-in, or `mode="fullscreen"`; variants `dots|pulse|spinner|grid|morph`), `<Spinner>` (small inline indicator for buttons and text, inherits text color) and `<Skeleton>` (content placeholder — `variant="text|circle|rect"`, `lines` for multi-line text).
|
|
132
|
+
|
|
133
|
+
- **Need a code snippet?** → `<CodeBlock code language title lineNumbers />` (built-in copy button; `highlight` prop to plug a highlighter) and `<Code>` for inline. Don't hand-roll a `<pre>` + CopyButton.
|
|
91
134
|
|
|
92
|
-
- **Need a
|
|
135
|
+
- **Need a password field?** → `<Input type="password" revealable />`. **A text field with a clear button?** → `<Input clearable />`.
|
|
93
136
|
|
|
94
|
-
- **Need a data table?** → `<Table>`.
|
|
137
|
+
- **Need a data table?** → `<Table>`. Row links/navigation → `onRowClick`; bulk operations → `selectable` + `rowKey` + `bulkActions`; async data → `loading`; column picker → `columnVisibility`; live-updating cells → `layout="fixed"`.
|
|
95
138
|
- All data in memory → don't pass `onSort`; pass `pagination` (without `totalRows`) for client-side paging.
|
|
96
139
|
- Data from a server → pass `sortConfig` + `onSort`, and `pagination` with `totalRows`.
|
|
97
140
|
- Wide table / comparison matrix → `scrollable` (horizontal scroll), `dragScroll` (middle/right-button drag-to-pan, implies scrollable; left button keeps selection/clicks), `sticky: true` on the first column to pin it. Per-cell shading via `cellClassName`/`cellStyle` on the column def; `defaultSortDirection: 'desc'` for highest-first columns; remove buttons can live in `header` (call `e.stopPropagation()` when the column is sortable). See [recipes/comparison-table.tsx](./recipes/comparison-table.tsx).
|
|
@@ -171,7 +214,7 @@ Full copy-paste-able files live alongside this doc. Each is one self-contained f
|
|
|
171
214
|
- [recipes/paginated-table.tsx](./recipes/paginated-table.tsx) — Client-side sortable + paginated table.
|
|
172
215
|
- [recipes/server-side-table.tsx](./recipes/server-side-table.tsx) — Server-driven sort & pagination.
|
|
173
216
|
- [recipes/comparison-table.tsx](./recipes/comparison-table.tsx) — Wide comparison matrix: sticky first column, drag-to-scroll, per-cell %DV bucket shading, removable columns, desc-first sort.
|
|
174
|
-
- [recipes/confirm-modal.tsx](./recipes/confirm-modal.tsx) —
|
|
217
|
+
- [recipes/confirm-modal.tsx](./recipes/confirm-modal.tsx) — `ConfirmProvider` + `useConfirm()` wiring: provider at the root, async delete with toast, type-to-confirm.
|
|
175
218
|
- [recipes/searchable-multi-select.tsx](./recipes/searchable-multi-select.tsx) — Multi-select with search and form integration.
|
|
176
219
|
- [recipes/dropdown-menu.tsx](./recipes/dropdown-menu.tsx) — Row action menu with `Dropdown` + `DropdownItem`.
|
|
177
220
|
- [recipes/dashboard-charts.tsx](./recipes/dashboard-charts.tsx) — Multi-chart dashboard layout with KPI tiles + Sparkline.
|
|
@@ -182,6 +225,7 @@ Full copy-paste-able files live alongside this doc. Each is one self-contained f
|
|
|
182
225
|
- [recipes/trading-chart.tsx](./recipes/trading-chart.tsx) — Full-stack `TradingChart` with a resolution selector, in-memory datafeed adapter, and the SMA/EMA/Bollinger/RSI/Volume indicator stack. Swap `createMemoryDatafeed` for your own REST/WebSocket adapter; everything else carries over.
|
|
183
226
|
- [recipes/tag-input.tsx](./recipes/tag-input.tsx) — Tag-input pattern via `<Select multiple allowCreate>`: pick from existing tags or type a new one + Enter to create. `onCreate` persists the new tag back into the options list. Wired through `<FormField>` for react-hook-form integration.
|
|
184
227
|
- [recipes/live-timeline-feed.tsx](./recipes/live-timeline-feed.tsx) — Live event feeds into `TraceTimeline` / `HistoryTimeline` / `GanttTimeline`: consumer-side push/complete merge hooks (start appends with `end: null`, complete merges response fields + stamps `end`), optional WebSocket source, and consumer-side correlation filtering.
|
|
228
|
+
- [recipes/floating-copy-button.tsx](./recipes/floating-copy-button.tsx) — Copy button floating over a non-code box (solid wrapper surface trick); code itself goes through `<CodeBlock>`.
|
|
185
229
|
- [recipes/multi-select-in-modal.tsx](./recipes/multi-select-in-modal.tsx) — `<Select multiple>` inside `<Modal size="sm">`. Default `portal={true}` lets the menu escape the modal's `overflow: hidden` and sit above the modal via `--crk-z-floating`, so the modal does NOT need to be sized to contain the menu. Pair with `closeOnBackdrop={false}` so a backdrop click closes the open menu only, not the modal.
|
|
186
230
|
|
|
187
231
|
## Anti-patterns to refuse
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,168 @@ All notable changes to `@overdoser/react-toolkit` are documented here.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
|
|
5
5
|
project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.20.0]
|
|
8
|
+
|
|
9
|
+
Follow-ups from rolling 0.19.0 out to sixteen apps. Dark mode becomes opt-in
|
|
10
|
+
(a light-only app no longer turns dark on a dark-OS machine), the accent
|
|
11
|
+
tokens follow the app's primary, and `Table` gets a proper display-column
|
|
12
|
+
type. Apps that relied on 0.19.0 following the OS with no attribute must now
|
|
13
|
+
set `data-theme="system"` on `<html>`.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **Dark mode is opt-in.** With no `data-theme` the toolkit is light again;
|
|
18
|
+
`data-theme="system"` on `<html>` follows the OS. 0.19.0 followed the OS
|
|
19
|
+
by default, which flipped light-only apps to dark on dark-OS machines.
|
|
20
|
+
`useTheme`, `ThemeToggle` and `THEME_INIT_SCRIPT` now write `system`
|
|
21
|
+
instead of removing the attribute, so apps that adopted them are
|
|
22
|
+
unaffected. `ThemeToggle` and `getThemeInitScript` take `defaultTheme`.
|
|
23
|
+
- **`Table`** — `ColumnDef` is now `DataColumnDef | DisplayColumnDef`: a
|
|
24
|
+
data column keeps `key: keyof T` (a misspelled key is a type error again), a
|
|
25
|
+
column with no backing field (`'actions'`) is `{ id, render(row, index) }`
|
|
26
|
+
with a required renderer and row-typed callbacks. Rows may be any `object`
|
|
27
|
+
(interface-typed rows no longer fail `Record<string, unknown>`);
|
|
28
|
+
`useTableSort` is relaxed the same way.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **Tokens** — `--crk-color-primary-text` and `--crk-color-primary-selected`
|
|
33
|
+
derive from `--crk-color-primary` with `color-mix` instead of fixed indigo,
|
|
34
|
+
so an app's accent carries into tints and dark mode.
|
|
35
|
+
- **`THEME_INIT_SCRIPT`** — a storage read that throws (blocked cookies,
|
|
36
|
+
sandboxed iframe) no longer skips the fallback theme.
|
|
37
|
+
- **`usePersistedState`** — two hooks on the same empty key each got the
|
|
38
|
+
first hook's initial value; each now falls back to its own.
|
|
39
|
+
|
|
40
|
+
## [0.19.0]
|
|
41
|
+
|
|
42
|
+
The survey release: everything the ~/GITCRK projects kept hand-rolling, plus
|
|
43
|
+
dark mode. Twenty-one new components, a hooks/utils bundle, and upgrades to
|
|
44
|
+
Dropdown, Table, Select, Alert and Input. Two behaviour changes are listed
|
|
45
|
+
under *Changed* (Dropdown items close the menu; `useKeyboard` skips plain keys
|
|
46
|
+
while typing).
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- **Dark mode** — the stylesheet now ships a full dark token set. No
|
|
51
|
+
attribute follows the OS; `data-theme="light" | "dark"` on `<html>` (or on
|
|
52
|
+
any element, for a subtree) forces one. New tokens for text-on-tint
|
|
53
|
+
(`--crk-color-*-text`), backdrops and hover overlays; hard-coded surface
|
|
54
|
+
colours in Checkbox, Radio, Modal, Drawer, Badge, Chip, Alert, Toast,
|
|
55
|
+
Dropdown, SplitButton and the Timelines now use tokens (light output
|
|
56
|
+
unchanged). **`ThemeToggle`**, **`useTheme()`** and
|
|
57
|
+
**`THEME_INIT_SCRIPT`** (a pre-paint `<head>` script) complete it.
|
|
58
|
+
- **`Switch`** — the toggle switch as its own export (an alias of
|
|
59
|
+
`<Checkbox variant="switch">`, same a11y/form behaviour) so it is findable.
|
|
60
|
+
- **`Kbd`** — keyboard key cap; `keys={['⌘', 'K']}` renders a combination.
|
|
61
|
+
- **`EmptyState`** — centered placeholder for empty lists / no results / load
|
|
62
|
+
errors: icon (built-in per variant), title, description, `action` slot,
|
|
63
|
+
`variant="error"` (role=alert), sizes, `bordered` dashed frame.
|
|
64
|
+
- **`StatusDot`** — coloured indicator dot with `status`, `pulse`, optional
|
|
65
|
+
`label`, sizes and a `color` override.
|
|
66
|
+
- **`ProgressBar`** — determinate / indeterminate, `label` + `showValue`,
|
|
67
|
+
`thresholds` (colour by value), `segments` (discrete steps, `showCurrent`
|
|
68
|
+
for done / current / remaining shades, `shape="square"` for a flat strip),
|
|
69
|
+
sizes, variants.
|
|
70
|
+
- **`Card`** — surface with `Card.Header` / `Card.Title` / `Card.Body` /
|
|
71
|
+
`Card.Footer`; `variant` outlined / elevated / filled, `padding`,
|
|
72
|
+
`interactive` (keyboard-operable with `onClick`, anchor with `href`),
|
|
73
|
+
`selected`, `accent` stripe.
|
|
74
|
+
- **`RelativeTime`** — live "3 minutes ago" `<time>` element via
|
|
75
|
+
`Intl.RelativeTimeFormat`, with `maxAge` fallback to an absolute date.
|
|
76
|
+
- **`CommandPalette`** + **`useCommandPalette`** — ⌘K palette with fuzzy
|
|
77
|
+
filtering and match highlighting, groups, recent items, nested pages,
|
|
78
|
+
`Kbd` shortcuts, `href` items, and a remote mode (`filter={null}` +
|
|
79
|
+
`loading`).
|
|
80
|
+
- **`ConfirmDialog`** + **`ConfirmProvider`** / **`useConfirm()`** — the
|
|
81
|
+
confirm-modal recipe as a component: `danger`, `requireText`
|
|
82
|
+
(type-to-confirm), async `onConfirm` with loading + error display, and a
|
|
83
|
+
promise API (`if (await confirm({ … })) …`) to replace `window.confirm`.
|
|
84
|
+
- **`CodeBlock`** + **`Code`** — `<pre><code>` with a built-in copy button
|
|
85
|
+
(floating or in a title/language header), line numbers with highlighted
|
|
86
|
+
lines, wrap toggle, `maxHeight`, and a `highlight` hook for an external
|
|
87
|
+
highlighter. The floating-copy-button recipe now points here.
|
|
88
|
+
- **`Dropdown`** — menu items grow `danger`, `icon`, `shortcut`, `description`
|
|
89
|
+
and `checked` (menuitemcheckbox); new `DropdownSeparator` and
|
|
90
|
+
`DropdownLabel`; keyboard navigation (arrows wrap, Home/End, typeahead);
|
|
91
|
+
controlled `open` / `onOpenChange`; and a context-menu mode via
|
|
92
|
+
`anchor={{ x, y }}` with a `useContextMenu()` helper.
|
|
93
|
+
- **`Table`** — `loading` (overlay, rows keep their height; skeleton rows
|
|
94
|
+
when empty), `onRowClick` (keyboard-operable rows; inner buttons keep
|
|
95
|
+
working), row selection (`selectable`, `selectedKeys` /
|
|
96
|
+
`onSelectionChange`, `isRowSelectable`, page-scoped select-all, Shift-range)
|
|
97
|
+
with a `bulkActions` bar, `columnVisibility`, and `layout="fixed"`.
|
|
98
|
+
- **`Alert`** — `action` slot, `layout="banner"` for full-width page
|
|
99
|
+
banners, `size="sm"`.
|
|
100
|
+
- **`Input`** — `revealable` password toggle (controlled via `revealed` /
|
|
101
|
+
`onRevealedChange`) and `clearable` (fires `onChange` with `''` + `onClear`).
|
|
102
|
+
- **`Modal`** / **`Drawer`** — `headerTitle` class on the new title wrapper.
|
|
103
|
+
- **`SegmentedControl`** — single-select button group (`role="radiogroup"`,
|
|
104
|
+
roving tabindex, icons, counts, tooltips, `href` items, sizes, shapes,
|
|
105
|
+
filled / outlined).
|
|
106
|
+
- **`Chip`** + **`ChipGroup`** — interactive tags: removable, toggleable
|
|
107
|
+
(`selected`), clickable, colours / outline / sizes; `ChipGroup max` with a
|
|
108
|
+
`+N` overflow that can expand.
|
|
109
|
+
- **`PageHeader`** — breadcrumbs, back link, title + badge, subtitle /
|
|
110
|
+
description / meta, actions slot, tabs slot, sticky.
|
|
111
|
+
- **`Accordion`** — single / multiple, controlled, `collapsible`,
|
|
112
|
+
`keepMounted`, three variants, `items` shorthand, keyboard navigation,
|
|
113
|
+
CSS-grid height animation.
|
|
114
|
+
- **`KeyValueList`** — `<dl>` rows / grid / inline layouts with copyable,
|
|
115
|
+
masked, monospace and linked values, hints and empty fallbacks.
|
|
116
|
+
- **`StatCard`** + **`StatGrid`** — KPI tile with delta + trend colour
|
|
117
|
+
(`positive-down` for latency-style metrics), icon / sparkline / footer
|
|
118
|
+
slots, loading skeleton, and a responsive grid.
|
|
119
|
+
- **`SearchInput`** — `Input` preconfigured for search: debounced
|
|
120
|
+
`onSearch`, Enter bypass, clear, `loading`, focus `hotkey` with a `Kbd`
|
|
121
|
+
hint, Escape-to-clear.
|
|
122
|
+
- **`Select`** (searchable / multi) — remote search: `onSearch` (debounced,
|
|
123
|
+
`searchDebounce`, `minSearchLength` + `searchPrompt`), `loading` /
|
|
124
|
+
`loadingMessage`, `noResultsMessage`, `highlightMatches` (local mode) and
|
|
125
|
+
`selectedLabels` so chips stay labelled when results move on. No separate
|
|
126
|
+
Combobox needed.
|
|
127
|
+
- **`ImageViewer`** + **`useZoomPan`** — lightbox with prev/next, counter,
|
|
128
|
+
thumbnails, zoom/pan (wheel, pinch, double-click, keyboard), caption and
|
|
129
|
+
download; `renderSlide` for non-image slides.
|
|
130
|
+
- **`SplitPane`** + **`useResizable`** — drag / keyboard resizable split
|
|
131
|
+
(horizontal or vertical, collapsible, `persistKey`), with the engine
|
|
132
|
+
exported as a hook.
|
|
133
|
+
- **Hooks** — `usePersistedState` (localStorage/sessionStorage, SSR- and
|
|
134
|
+
private-mode-safe, cross-tab sync), `useDebouncedValue`, `useMediaQuery`,
|
|
135
|
+
`useElementSize`, `useNow` (shared timer per interval).
|
|
136
|
+
- **Utils** — `formatBytes`, `timeAgo`.
|
|
137
|
+
- **`Checkbox`**, **`Radio`**, **`RadioGroup`** — `error?: boolean` prop (danger
|
|
138
|
+
border, like `Input`). `RadioGroup` applies it to every `Radio` inside and now
|
|
139
|
+
forwards its ref to the group element, so react-hook-form can focus it.
|
|
140
|
+
|
|
141
|
+
### Changed
|
|
142
|
+
|
|
143
|
+
- **`Dropdown`** — activating a `DropdownItem` now closes the menu (as
|
|
144
|
+
`onClose`'s docs always said); checkable items stay open. `closeOnSelect`
|
|
145
|
+
on the item overrides either way.
|
|
146
|
+
- **`useKeyboard`** — accepts chords (`'mod+k'`, `'ctrl+shift+z'`), an
|
|
147
|
+
options object (`active`, `ignoreEditable`, `preventDefault`, `target`), and
|
|
148
|
+
reads handlers through a ref so inline objects no longer re-subscribe the
|
|
149
|
+
listener on every render. Plain printable keys are now skipped while typing
|
|
150
|
+
in an editable element (pass `ignoreEditable: false` for the old behaviour);
|
|
151
|
+
bare keys no longer fire while Ctrl/Alt/Meta is held. The old
|
|
152
|
+
`useKeyboard(handlers, active)` signature still works.
|
|
153
|
+
|
|
154
|
+
### Fixed
|
|
155
|
+
|
|
156
|
+
- **`Modal`** / **`Drawer`** — the auto `aria-labelledby` pointed at the whole
|
|
157
|
+
header, so a dialog with a close button was announced as "Title ×". The id
|
|
158
|
+
now sits on a title wrapper.
|
|
159
|
+
- **`FormField`** — `Checkbox` and `Radio` children received `error` and (for a
|
|
160
|
+
boolean field) `value` as raw DOM attributes: React warned about a non-boolean
|
|
161
|
+
attribute and the checkbox submitted `value="false"`/`"true"`. Both inputs now
|
|
162
|
+
accept `error` and a boolean field value is bridged to `checked` only.
|
|
163
|
+
- **`Select`** (native) — `onValuesChange` and the other multi-only props
|
|
164
|
+
(`allowCreate`, `onCreate`, `createLabel`, `closeOnSelect`,
|
|
165
|
+
`clearSearchOnSelect`, `portal`) were spread onto the native `<select>`,
|
|
166
|
+
tripping React's "Unknown event handler property" warning on every
|
|
167
|
+
`<FormField><Select /></FormField>`. They are dropped in native mode.
|
|
168
|
+
|
|
7
169
|
## [0.18.0]
|
|
8
170
|
|
|
9
171
|
A loader for pages and containers.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ReactNode } from 'react';
|
|
2
|
+
export type AccordionType = 'single' | 'multiple';
|
|
3
|
+
export type AccordionVariant = 'default' | 'bordered' | 'separated';
|
|
4
|
+
export type AccordionSize = 'sm' | 'md';
|
|
5
|
+
export interface AccordionClasses {
|
|
6
|
+
root: string;
|
|
7
|
+
item: string;
|
|
8
|
+
itemOpen: string;
|
|
9
|
+
header: string;
|
|
10
|
+
trigger: string;
|
|
11
|
+
icon: string;
|
|
12
|
+
content: string;
|
|
13
|
+
contentInner: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AccordionItemData {
|
|
16
|
+
/** Identifier of the item (used in `value`). */
|
|
17
|
+
value: string;
|
|
18
|
+
/** Trigger content. */
|
|
19
|
+
title: ReactNode;
|
|
20
|
+
/** Panel content. */
|
|
21
|
+
content: ReactNode;
|
|
22
|
+
/** Non-interactive when true. */
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface AccordionProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange'> {
|
|
26
|
+
/** One open item at a time, or any number. @default 'single' */
|
|
27
|
+
type?: AccordionType;
|
|
28
|
+
/** Controlled open value(s): a `string` for `single`, `string[]` for `multiple`. */
|
|
29
|
+
value?: string | string[];
|
|
30
|
+
/** Uncontrolled initial open value(s). */
|
|
31
|
+
defaultValue?: string | string[];
|
|
32
|
+
/** Called with the next value (`string` for `single`, `string[]` for `multiple`). */
|
|
33
|
+
onValueChange?: (value: string | string[]) => void;
|
|
34
|
+
/** In `single` mode, let the open item be closed by clicking it again. @default true */
|
|
35
|
+
collapsible?: boolean;
|
|
36
|
+
/** Keep closed panels mounted (and `hidden`) instead of unmounting them. @default false */
|
|
37
|
+
keepMounted?: boolean;
|
|
38
|
+
/** Item separation style. @default 'default' */
|
|
39
|
+
variant?: AccordionVariant;
|
|
40
|
+
/** Trigger/content sizing. @default 'md' */
|
|
41
|
+
size?: AccordionSize;
|
|
42
|
+
/** Disables every item. @default false */
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/** Heading level wrapping each trigger. @default 3 */
|
|
45
|
+
headingLevel?: 2 | 3 | 4;
|
|
46
|
+
/** Data-driven shorthand instead of `Accordion.Item` children. */
|
|
47
|
+
items?: AccordionItemData[];
|
|
48
|
+
/** Override class names on internal elements. */
|
|
49
|
+
classes?: Partial<AccordionClasses>;
|
|
50
|
+
}
|
|
51
|
+
declare const AccordionRoot: import('react').ForwardRefExoticComponent<Omit<AccordionProps, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
|
|
52
|
+
export interface AccordionItemProps extends ComponentPropsWithRef<'div'> {
|
|
53
|
+
/** Identifier of this item (matches `value` on the root). */
|
|
54
|
+
value: string;
|
|
55
|
+
/** Non-interactive when true. @default false */
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
}
|
|
58
|
+
declare const AccordionItem: import('react').ForwardRefExoticComponent<Omit<AccordionItemProps, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
|
|
59
|
+
export interface AccordionTriggerProps extends ComponentPropsWithRef<'button'> {
|
|
60
|
+
/** Trailing chevron (rotates when open). Pass a node to replace it, `false` to hide. @default chevron */
|
|
61
|
+
icon?: ReactNode | false;
|
|
62
|
+
/** Side of the icon. @default 'end' */
|
|
63
|
+
iconPosition?: 'start' | 'end';
|
|
64
|
+
}
|
|
65
|
+
declare const AccordionTrigger: import('react').ForwardRefExoticComponent<Omit<AccordionTriggerProps, "ref"> & import('react').RefAttributes<HTMLButtonElement>>;
|
|
66
|
+
export interface AccordionContentProps extends ComponentPropsWithRef<'div'> {
|
|
67
|
+
children?: ReactNode;
|
|
68
|
+
}
|
|
69
|
+
declare const AccordionContent: import('react').ForwardRefExoticComponent<Omit<AccordionContentProps, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
|
|
70
|
+
type AccordionComponent = typeof AccordionRoot & {
|
|
71
|
+
Item: typeof AccordionItem;
|
|
72
|
+
Trigger: typeof AccordionTrigger;
|
|
73
|
+
Content: typeof AccordionContent;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Vertically stacked disclosure sections. One open at a time (`type="single"`)
|
|
77
|
+
* or any number (`type="multiple"`); controlled or uncontrolled. Each trigger
|
|
78
|
+
* is a real `<button>` inside a heading with `aria-expanded` / `aria-controls`;
|
|
79
|
+
* ArrowUp / ArrowDown / Home / End move focus between triggers.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* <Accordion defaultValue="shipping">
|
|
83
|
+
* <Accordion.Item value="shipping">
|
|
84
|
+
* <Accordion.Trigger>Shipping</Accordion.Trigger>
|
|
85
|
+
* <Accordion.Content>Orders ship within 2 business days.</Accordion.Content>
|
|
86
|
+
* </Accordion.Item>
|
|
87
|
+
* <Accordion.Item value="returns">
|
|
88
|
+
* <Accordion.Trigger>Returns</Accordion.Trigger>
|
|
89
|
+
* <Accordion.Content>30-day return window.</Accordion.Content>
|
|
90
|
+
* </Accordion.Item>
|
|
91
|
+
* </Accordion>
|
|
92
|
+
*/
|
|
93
|
+
export declare const Accordion: AccordionComponent;
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { jsx as o, jsxs as j } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as y, useId as Z, useRef as _, useState as ee, useCallback as L, createContext as E, useContext as S } from "react";
|
|
3
|
+
import h from "clsx";
|
|
4
|
+
import r from "./Accordion.module.scss.js";
|
|
5
|
+
const H = E(null), K = E(null);
|
|
6
|
+
function N(t) {
|
|
7
|
+
const n = S(H);
|
|
8
|
+
if (!n) throw new Error(`${t} must be rendered inside an <Accordion>.`);
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
function M(t) {
|
|
12
|
+
const n = S(K);
|
|
13
|
+
if (!n) throw new Error(`${t} must be rendered inside an <Accordion.Item>.`);
|
|
14
|
+
return n;
|
|
15
|
+
}
|
|
16
|
+
function O(t) {
|
|
17
|
+
return t === void 0 ? [] : Array.isArray(t) ? t : [t];
|
|
18
|
+
}
|
|
19
|
+
const P = y(
|
|
20
|
+
({
|
|
21
|
+
type: t = "single",
|
|
22
|
+
value: n,
|
|
23
|
+
defaultValue: f,
|
|
24
|
+
onValueChange: g,
|
|
25
|
+
collapsible: d = !0,
|
|
26
|
+
keepMounted: i = !1,
|
|
27
|
+
variant: a = "default",
|
|
28
|
+
size: c = "md",
|
|
29
|
+
disabled: s = !1,
|
|
30
|
+
headingLevel: p = 3,
|
|
31
|
+
items: m,
|
|
32
|
+
classes: b,
|
|
33
|
+
className: q,
|
|
34
|
+
children: B,
|
|
35
|
+
onKeyDown: U,
|
|
36
|
+
...V
|
|
37
|
+
}, I) => {
|
|
38
|
+
const W = Z(), R = _(null), C = n !== void 0, [z, F] = ee(() => O(f)), v = C ? O(n) : z, G = L(
|
|
39
|
+
(e) => {
|
|
40
|
+
const A = v.includes(e);
|
|
41
|
+
let l;
|
|
42
|
+
if (t === "multiple")
|
|
43
|
+
l = A ? v.filter((u) => u !== e) : [...v, e];
|
|
44
|
+
else if (A) {
|
|
45
|
+
if (!d) return;
|
|
46
|
+
l = [];
|
|
47
|
+
} else
|
|
48
|
+
l = [e];
|
|
49
|
+
C || F(l), g?.(t === "multiple" ? l : l[0] ?? "");
|
|
50
|
+
},
|
|
51
|
+
[v, t, d, C, g]
|
|
52
|
+
), J = L(
|
|
53
|
+
(e) => {
|
|
54
|
+
R.current = e, typeof I == "function" ? I(e) : I && (I.current = e);
|
|
55
|
+
},
|
|
56
|
+
[I]
|
|
57
|
+
), Q = (e) => {
|
|
58
|
+
if (U?.(e), e.defaultPrevented) return;
|
|
59
|
+
const A = R.current;
|
|
60
|
+
if (!A) return;
|
|
61
|
+
const l = e.target;
|
|
62
|
+
if (!l.matches("[data-accordion-trigger]")) return;
|
|
63
|
+
const u = Array.from(
|
|
64
|
+
A.querySelectorAll("[data-accordion-trigger]:not(:disabled)")
|
|
65
|
+
).filter((Y) => Y.closest("[data-accordion-root]") === A);
|
|
66
|
+
if (u.length === 0) return;
|
|
67
|
+
const T = u.indexOf(l);
|
|
68
|
+
let x = null;
|
|
69
|
+
e.key === "ArrowDown" ? x = (T + 1) % u.length : e.key === "ArrowUp" ? x = (T - 1 + u.length) % u.length : e.key === "Home" ? x = 0 : e.key === "End" && (x = u.length - 1), x !== null && (e.preventDefault(), u[x].focus());
|
|
70
|
+
}, X = {
|
|
71
|
+
openValues: v,
|
|
72
|
+
toggle: G,
|
|
73
|
+
baseId: W,
|
|
74
|
+
keepMounted: i,
|
|
75
|
+
disabled: s,
|
|
76
|
+
headingLevel: p,
|
|
77
|
+
classes: b
|
|
78
|
+
};
|
|
79
|
+
return /* @__PURE__ */ o(H.Provider, { value: X, children: /* @__PURE__ */ o(
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
ref: J,
|
|
83
|
+
"data-accordion-root": "",
|
|
84
|
+
className: h(r.root, r[a], r[c], b?.root, q),
|
|
85
|
+
onKeyDown: Q,
|
|
86
|
+
...V,
|
|
87
|
+
children: m ? m.map((e) => /* @__PURE__ */ j(w, { value: e.value, disabled: e.disabled, children: [
|
|
88
|
+
/* @__PURE__ */ o(k, { children: e.title }),
|
|
89
|
+
/* @__PURE__ */ o($, { children: e.content })
|
|
90
|
+
] }, e.value)) : B
|
|
91
|
+
}
|
|
92
|
+
) });
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
P.displayName = "Accordion";
|
|
96
|
+
const w = y(
|
|
97
|
+
({ value: t, disabled: n = !1, className: f, children: g, ...d }, i) => {
|
|
98
|
+
const a = N("Accordion.Item"), c = a.openValues.includes(t), s = n || a.disabled, p = `${a.baseId}-${t}`, m = {
|
|
99
|
+
value: t,
|
|
100
|
+
open: c,
|
|
101
|
+
disabled: s,
|
|
102
|
+
triggerId: `${p}-trigger`,
|
|
103
|
+
contentId: `${p}-content`
|
|
104
|
+
};
|
|
105
|
+
return /* @__PURE__ */ o(K.Provider, { value: m, children: /* @__PURE__ */ o(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
ref: i,
|
|
109
|
+
"data-state": c ? "open" : "closed",
|
|
110
|
+
"data-disabled": s || void 0,
|
|
111
|
+
className: h(
|
|
112
|
+
r.item,
|
|
113
|
+
c && r.itemOpen,
|
|
114
|
+
s && r.itemDisabled,
|
|
115
|
+
a.classes?.item,
|
|
116
|
+
c && a.classes?.itemOpen,
|
|
117
|
+
f
|
|
118
|
+
),
|
|
119
|
+
...d,
|
|
120
|
+
children: g
|
|
121
|
+
}
|
|
122
|
+
) });
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
w.displayName = "Accordion.Item";
|
|
126
|
+
const te = /* @__PURE__ */ o("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", width: "1em", height: "1em", children: /* @__PURE__ */ o("path", { d: "M5 8l5 5 5-5", strokeLinecap: "round", strokeLinejoin: "round" }) }), k = y(
|
|
127
|
+
({ icon: t = te, iconPosition: n = "end", className: f, children: g, onClick: d, ...i }, a) => {
|
|
128
|
+
const c = N("Accordion.Trigger"), s = M("Accordion.Trigger"), p = `h${c.headingLevel}`, m = t === !1 ? null : /* @__PURE__ */ o("span", { className: h(r.icon, c.classes?.icon), "aria-hidden": "true", children: t });
|
|
129
|
+
return /* @__PURE__ */ o(p, { className: h(r.header, c.classes?.header), children: /* @__PURE__ */ j(
|
|
130
|
+
"button",
|
|
131
|
+
{
|
|
132
|
+
ref: a,
|
|
133
|
+
type: "button",
|
|
134
|
+
id: s.triggerId,
|
|
135
|
+
"data-accordion-trigger": "",
|
|
136
|
+
"aria-expanded": s.open,
|
|
137
|
+
"aria-controls": s.contentId,
|
|
138
|
+
disabled: s.disabled,
|
|
139
|
+
className: h(r.trigger, n === "start" && r.iconStart, c.classes?.trigger, f),
|
|
140
|
+
onClick: (b) => {
|
|
141
|
+
d?.(b), !b.defaultPrevented && c.toggle(s.value);
|
|
142
|
+
},
|
|
143
|
+
...i,
|
|
144
|
+
children: [
|
|
145
|
+
n === "start" && m,
|
|
146
|
+
/* @__PURE__ */ o("span", { className: r.triggerLabel, children: g }),
|
|
147
|
+
n === "end" && m
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
) });
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
k.displayName = "Accordion.Trigger";
|
|
154
|
+
const $ = y(
|
|
155
|
+
({ className: t, children: n, ...f }, g) => {
|
|
156
|
+
const d = N("Accordion.Content"), i = M("Accordion.Content");
|
|
157
|
+
return !i.open && !d.keepMounted ? null : /* @__PURE__ */ o(
|
|
158
|
+
"div",
|
|
159
|
+
{
|
|
160
|
+
ref: g,
|
|
161
|
+
id: i.contentId,
|
|
162
|
+
role: "region",
|
|
163
|
+
"aria-labelledby": i.triggerId,
|
|
164
|
+
hidden: !i.open,
|
|
165
|
+
"data-state": i.open ? "open" : "closed",
|
|
166
|
+
className: h(r.content, d.classes?.content, t),
|
|
167
|
+
...f,
|
|
168
|
+
children: /* @__PURE__ */ o("div", { className: r.contentClip, children: /* @__PURE__ */ o("div", { className: h(r.contentInner, d.classes?.contentInner), children: n }) })
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
$.displayName = "Accordion.Content";
|
|
174
|
+
const D = P;
|
|
175
|
+
D.Item = w;
|
|
176
|
+
D.Trigger = k;
|
|
177
|
+
D.Content = $;
|
|
178
|
+
export {
|
|
179
|
+
D as Accordion
|
|
180
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const t = "crk-root-cCog2", e = "crk-sm-xQI6G", r = "crk-item-YNNr-", n = "crk-bordered-PfF4R", c = "crk-separated-X-Y5o", o = "crk-itemDisabled-JQ4TD", s = "crk-header-AYOT5", i = "crk-trigger-sPQlj", a = "crk-iconStart-5fvpd", d = "crk-triggerLabel-FZx-J", k = "crk-icon-TdeJS", l = "crk-itemOpen-pU-Q4", g = "crk-content-RyBzl", m = "crk-contentClip-S5IS2", p = "crk-contentInner-gJF2F", b = {
|
|
2
|
+
root: t,
|
|
3
|
+
sm: e,
|
|
4
|
+
default: "crk-default-D79k9",
|
|
5
|
+
item: r,
|
|
6
|
+
bordered: n,
|
|
7
|
+
separated: c,
|
|
8
|
+
itemDisabled: o,
|
|
9
|
+
header: s,
|
|
10
|
+
trigger: i,
|
|
11
|
+
iconStart: a,
|
|
12
|
+
triggerLabel: d,
|
|
13
|
+
icon: k,
|
|
14
|
+
itemOpen: l,
|
|
15
|
+
content: g,
|
|
16
|
+
contentClip: m,
|
|
17
|
+
contentInner: p
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
n as bordered,
|
|
21
|
+
g as content,
|
|
22
|
+
m as contentClip,
|
|
23
|
+
p as contentInner,
|
|
24
|
+
b as default,
|
|
25
|
+
s as header,
|
|
26
|
+
k as icon,
|
|
27
|
+
a as iconStart,
|
|
28
|
+
r as item,
|
|
29
|
+
o as itemDisabled,
|
|
30
|
+
l as itemOpen,
|
|
31
|
+
t as root,
|
|
32
|
+
c as separated,
|
|
33
|
+
e as sm,
|
|
34
|
+
i as trigger,
|
|
35
|
+
d as triggerLabel
|
|
36
|
+
};
|