@overdoser/react-toolkit 0.6.0 → 0.8.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.
Files changed (116) hide show
  1. package/AGENTS.md +6 -0
  2. package/CHANGELOG.md +82 -0
  3. package/components/ActionButton/ActionButton.d.ts +105 -0
  4. package/components/ActionButton/ActionButton.js +211 -0
  5. package/components/ActionButton/ActionButton.module.scss.js +47 -0
  6. package/components/ActionButton/CopyButton.d.ts +31 -0
  7. package/components/ActionButton/CopyButton.js +66 -0
  8. package/components/ActionButton/index.d.ts +4 -0
  9. package/components/Alert/Alert.js +82 -0
  10. package/components/Alert/Alert.module.scss.js +25 -0
  11. package/components/Avatar/Avatar.js +57 -0
  12. package/components/Avatar/Avatar.module.scss.js +43 -0
  13. package/components/Badge/Badge.js +38 -0
  14. package/components/Badge/Badge.module.scss.js +31 -0
  15. package/components/Breadcrumbs/Breadcrumbs.js +49 -0
  16. package/components/Breadcrumbs/Breadcrumbs.module.scss.js +17 -0
  17. package/components/Button/Button.js +57 -0
  18. package/components/Button/Button.module.scss.js +47 -0
  19. package/components/Chart/AreaChart.js +244 -0
  20. package/components/Chart/Axis.js +45 -0
  21. package/components/Chart/BarChart.js +353 -0
  22. package/components/Chart/Chart.module.scss.js +61 -0
  23. package/components/Chart/ChartContainer.js +41 -0
  24. package/components/Chart/ChartLegend.js +31 -0
  25. package/components/Chart/ChartTooltip.js +42 -0
  26. package/components/Chart/LineChart.js +236 -0
  27. package/components/Chart/PieChart.js +248 -0
  28. package/components/Chart/RadarChart.js +221 -0
  29. package/components/Chart/Sparkline.js +69 -0
  30. package/components/Chart/TradingChart.js +732 -0
  31. package/components/Chart/scales.js +39 -0
  32. package/components/Chart/trading/indicators.js +68 -0
  33. package/components/Chart/trading/period.js +71 -0
  34. package/components/Chart/useChartDimensions.js +23 -0
  35. package/components/Divider/Divider.js +36 -0
  36. package/components/Divider/Divider.module.scss.js +31 -0
  37. package/components/Draggable/Draggable.js +155 -0
  38. package/components/Draggable/Draggable.module.scss.js +17 -0
  39. package/components/Drawer/Drawer.js +126 -0
  40. package/components/Drawer/Drawer.module.scss.js +117 -0
  41. package/components/Dropdown/Dropdown.js +142 -0
  42. package/components/Dropdown/Dropdown.module.scss.js +35 -0
  43. package/components/Dropdown/DropdownItem.js +31 -0
  44. package/components/Dropzone/Dropzone.js +107 -0
  45. package/components/Dropzone/Dropzone.module.scss.js +21 -0
  46. package/components/Form/Form.js +36 -0
  47. package/components/Form/Form.module.scss.js +29 -0
  48. package/components/Form/FormField.js +76 -0
  49. package/components/Form/FormRow.js +9 -0
  50. package/components/Form/formFieldDefaults.js +5 -0
  51. package/components/Link/Link.js +59 -0
  52. package/components/Link/Link.module.scss.js +16 -0
  53. package/components/List/List.js +46 -0
  54. package/components/List/List.module.scss.js +21 -0
  55. package/components/Modal/Modal.js +109 -0
  56. package/components/Modal/Modal.module.scss.js +31 -0
  57. package/components/Pagination/Pagination.js +84 -0
  58. package/components/Pagination/Pagination.module.scss.js +23 -0
  59. package/components/Pagination/paginationRange.js +24 -0
  60. package/components/Popover/Popover.js +138 -0
  61. package/components/Popover/Popover.module.scss.js +21 -0
  62. package/components/Skeleton/Skeleton.js +50 -0
  63. package/components/Skeleton/Skeleton.module.scss.js +25 -0
  64. package/components/Spinner/Spinner.js +25 -0
  65. package/components/Spinner/Spinner.module.scss.js +20 -0
  66. package/components/Table/Table.d.ts +61 -6
  67. package/components/Table/Table.js +284 -0
  68. package/components/Table/Table.module.scss.js +59 -0
  69. package/components/Table/useTableSort.d.ts +7 -5
  70. package/components/Table/useTableSort.js +44 -0
  71. package/components/Tabs/Tabs.js +163 -0
  72. package/components/Tabs/Tabs.module.scss.js +53 -0
  73. package/components/Timer/Timer.js +159 -0
  74. package/components/Timer/Timer.module.scss.js +55 -0
  75. package/components/Toast/Toast.js +133 -0
  76. package/components/Toast/Toast.module.scss.js +62 -0
  77. package/components/Toast/toastStore.js +62 -0
  78. package/components/ToggleIconButton/ToggleIconButton.d.ts +62 -0
  79. package/components/ToggleIconButton/ToggleIconButton.js +58 -0
  80. package/components/ToggleIconButton/ToggleIconButton.module.scss.js +27 -0
  81. package/components/ToggleIconButton/index.d.ts +2 -0
  82. package/components/Tooltip/Tooltip.js +86 -0
  83. package/components/Tooltip/Tooltip.module.scss.js +30 -0
  84. package/components/Typography/Typography.js +37 -0
  85. package/components/Typography/Typography.module.scss.js +53 -0
  86. package/components/inputs/Checkbox/Checkbox.js +50 -0
  87. package/components/inputs/Checkbox/Checkbox.module.scss.js +15 -0
  88. package/components/inputs/Checkbox/CheckboxGroup.js +111 -0
  89. package/components/inputs/Checkbox/CheckboxGroup.module.scss.js +31 -0
  90. package/components/inputs/DatePicker/DatePicker.js +229 -0
  91. package/components/inputs/DatePicker/DatePicker.module.scss.js +45 -0
  92. package/components/inputs/DatePicker/dateUtils.js +41 -0
  93. package/components/inputs/Input/Input.js +50 -0
  94. package/components/inputs/Input/Input.module.scss.js +25 -0
  95. package/components/inputs/NumberInput/NumberInput.js +134 -0
  96. package/components/inputs/NumberInput/NumberInput.module.scss.js +25 -0
  97. package/components/inputs/Radio/Radio.js +68 -0
  98. package/components/inputs/Radio/Radio.module.scss.js +13 -0
  99. package/components/inputs/Select/Select.js +520 -0
  100. package/components/inputs/Select/Select.module.scss.js +69 -0
  101. package/components/inputs/Slider/Slider.js +128 -0
  102. package/components/inputs/Slider/Slider.module.scss.js +15 -0
  103. package/components/inputs/Textarea/Textarea.js +58 -0
  104. package/components/inputs/Textarea/Textarea.module.scss.js +25 -0
  105. package/hooks/useClickOutside.js +15 -0
  106. package/hooks/useFocusTrap.js +39 -0
  107. package/hooks/useKeyboard.js +19 -0
  108. package/hooks/usePortalPosition.js +20 -0
  109. package/index.css +1 -1
  110. package/index.d.ts +4 -0
  111. package/index.js +119 -6575
  112. package/index.layered.css +1 -1
  113. package/llms.txt +123 -5
  114. package/manifest.json +230 -2
  115. package/package.json +3 -2
  116. package/recipes/comparison-table.tsx +123 -0
package/AGENTS.md CHANGED
@@ -53,6 +53,10 @@ For exhaustive component reference (every prop, every variant, every signature),
53
53
 
54
54
  - **Need a menu (Edit / Delete / Archive)?** → `<Dropdown trigger={...}>` with `<DropdownItem>` children.
55
55
 
56
+ - **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.
57
+
58
+ - **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.
59
+
56
60
  - **Need a tooltip / hover card / contextual panel?** → `<Popover trigger={...} content={...} />`.
57
61
 
58
62
  - **Need a confirm prompt or 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`).
@@ -86,6 +90,7 @@ For exhaustive component reference (every prop, every variant, every signature),
86
90
  - **Need a data table?** → `<Table>`.
87
91
  - All data in memory → don't pass `onSort`; pass `pagination` (without `totalRows`) for client-side paging.
88
92
  - Data from a server → pass `sortConfig` + `onSort`, and `pagination` with `totalRows`.
93
+ - 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).
89
94
 
90
95
  - **Need a chart?**
91
96
  - Time series / trend → `<LineChart>` or `<AreaChart>` (use Area when the magnitude matters more than the precise line).
@@ -156,6 +161,7 @@ Full copy-paste-able files live alongside this doc. Each is one self-contained f
156
161
  - [recipes/login-form.tsx](./recipes/login-form.tsx) — Form + Input + Button with validation rules.
157
162
  - [recipes/paginated-table.tsx](./recipes/paginated-table.tsx) — Client-side sortable + paginated table.
158
163
  - [recipes/server-side-table.tsx](./recipes/server-side-table.tsx) — Server-driven sort & pagination.
164
+ - [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.
159
165
  - [recipes/confirm-modal.tsx](./recipes/confirm-modal.tsx) — Reusable destructive-action confirm dialog.
160
166
  - [recipes/searchable-multi-select.tsx](./recipes/searchable-multi-select.tsx) — Multi-select with search and form integration.
161
167
  - [recipes/dropdown-menu.tsx](./recipes/dropdown-menu.tsx) — Row action menu with `Dropdown` + `DropdownItem`.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,88 @@ 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.8.0]
8
+
9
+ Bundle-size release: the package now tree-shakes properly. No API changes.
10
+
11
+ ### Changed
12
+
13
+ - **Per-module build (`preserveModules`).** The library used to ship as a
14
+ single ES module, so consumer bundlers had to prove top-level
15
+ `forwardRef()`/`Object.assign()` calls side-effect-free to drop unused
16
+ components — they can't, and importing a lone `Button` bundled ~28K gzip
17
+ (about half the library). `dist/` now mirrors the source module graph (one
18
+ JS file per module, with the root entry re-exporting them), and bundlers
19
+ skip unimported files entirely via the `sideEffects` field. Measured with
20
+ an esbuild consumer: `import { Button }` → **0.9K gzip** (was 28.0K),
21
+ `import { CopyButton }` → 2.4K; importing everything is unchanged
22
+ (~51K gzip). The public API, `exports` map, and `theme.css` /
23
+ `theme.layered.css` are untouched — no consumer changes needed.
24
+ - **`clsx` is no longer inlined** into the build; it resolves from the
25
+ package's own declared dependency instead (deduplicates when your app also
26
+ uses it).
27
+
28
+ ### Fixed
29
+
30
+ - **`react-hook-form` is now a declared (optional) peer dependency.** `Form`
31
+ imports it, but the package never declared it, so package managers could
32
+ not warn on version mismatches and plain-Node/SSR imports of the package
33
+ root failed with an unresolvable bare specifier unless it happened to be
34
+ installed. It was already marked optional in `peerDependenciesMeta`; the
35
+ missing `peerDependencies` range (`^7.0.0`) is now declared. You only need
36
+ to install it if you use `Form`/`FormField` — bundlers don't touch it
37
+ otherwise now that unimported files are skipped (see above).
38
+
39
+ ## [0.7.0]
40
+
41
+ A new family of stateful action buttons, and wide-table / comparison-matrix
42
+ support for `Table`. Everything is opt-in — no behavior changes for existing
43
+ usage (one addition: Shift+click now also triggers `Table` multi-sort,
44
+ alongside Ctrl/Cmd+click).
45
+
46
+ ### Added
47
+
48
+ - **`ActionButton`** — stateful action button with morphing icon/label layers
49
+ (`idle → armed → pending → success → idle`). Sync actions jump straight to a
50
+ success check + tinted surface, then auto-reset. Async actions (a
51
+ promise-returning `onAction`) show a pending spinner and only reach success
52
+ on resolve; rejections return to idle and call `onError`. Calling
53
+ `context.setProgress(0–100)` inside the action switches pending to a
54
+ determinate state — live % label plus an accent fill bar (drive it from
55
+ received bytes for downloads). `confirmLabel` adds a two-step confirm for
56
+ destructive actions (danger tint, icon shake, auto-disarm). Labels swap as a
57
+ directional carousel so transitions roll one way instead of jumping.
58
+ Variants/sizes match `Button`; `speed` scales every duration and timer at
59
+ once; colors/timings/transforms are themeable via `--crk-action-*` custom
60
+ properties; the current phase is exposed as `data-phase` for custom CSS;
61
+ respects `prefers-reduced-motion`.
62
+ - **`CopyButton`** — copy-to-clipboard preset of `ActionButton`: clipboard
63
+ icon morphs into a check, `Copy → Copied`, success tint, auto-reset. Works
64
+ icon+text or `iconOnly`. Success shows only after the clipboard write
65
+ confirms (with an `execCommand` fallback for insecure contexts); `value`
66
+ accepts a string or a lazy/async getter.
67
+ - **`ToggleIconButton`** — round icon-only toggle for like/save/bookmark-style
68
+ optimistic actions, with `aria-pressed`. Toggling on fills the icon with
69
+ `activeColor`, tints the surface, and pops the icon; optional `burst` ring.
70
+ Controlled (`pressed` + `onPressedChange`) or uncontrolled
71
+ (`defaultPressed`); themeable via `--crk-toggle-*` custom properties.
72
+ - **`Table` wide-table / comparison-matrix support** (all opt-in):
73
+ - `scrollable` — horizontal scroll container around the table.
74
+ - `dragScroll` — drag with the middle or right mouse button to pan
75
+ (implies `scrollable`). The left button keeps its native behavior (text
76
+ selection, clicks); the context menu opens only on a direct right click,
77
+ never after a drag.
78
+ - `ColumnDef.sticky` — pin the first column to the left edge while the
79
+ table scrolls; sticky cells stay opaque under striped/hover tints.
80
+ - `ColumnDef.cellClassName` / `cellStyle` — per-cell class/style hooks
81
+ (`(value, row, index) => …`) for value-bucket shading and the like.
82
+ - `ColumnDef.defaultSortDirection` — start the sort cycle at `'desc'` for
83
+ "highest first" columns; Shift+click now also adds a multi-sort column.
84
+ - `useTableSort`'s `requestSort`/`requestMultiSort` accept an optional
85
+ start direction.
86
+ - New `recipes/comparison-table.tsx` — copy-paste comparison matrix
87
+ (sticky first column, drag-to-scroll, %DV shading, removable columns).
88
+
7
89
  ## [0.6.0]
8
90
 
9
91
  Component polish plus an SSR-safety fix for `Toast`.
@@ -0,0 +1,105 @@
1
+ import { ComponentPropsWithRef, ReactNode } from 'react';
2
+ /** Lifecycle of one action run. */
3
+ export type ActionButtonPhase = 'idle' | 'armed' | 'pending' | 'success';
4
+ export interface ActionButtonClasses {
5
+ root: string;
6
+ iconStack: string;
7
+ iconLayer: string;
8
+ labelStack: string;
9
+ labelLayer: string;
10
+ progressFill: string;
11
+ }
12
+ /** Passed to `onAction` so long-running actions can report progress. */
13
+ export interface ActionButtonContext {
14
+ /**
15
+ * Report determinate progress (0–100) while the action's promise is in
16
+ * flight: the pending spinner gives way to the idle icon, the label shows
17
+ * the percentage, and an accent fill bar tracks it. Pass `null` to fall
18
+ * back to the indeterminate spinner (e.g. unknown content length).
19
+ */
20
+ setProgress: (percent: number | null) => void;
21
+ }
22
+ export interface ActionButtonProps extends Omit<ComponentPropsWithRef<'button'>, 'children'> {
23
+ /** Icon shown in the idle (and armed) state. */
24
+ icon: ReactNode;
25
+ /** Label shown in the idle state. Hidden when `iconOnly` is set. */
26
+ label?: ReactNode;
27
+ /** Icon shown while `onAction`'s promise is in flight. @default built-in spinner arc */
28
+ pendingIcon?: ReactNode;
29
+ /** Label shown while pending. Defaults to keeping `label` visible. */
30
+ pendingLabel?: ReactNode;
31
+ /** Icon shown in the success state. @default built-in check mark */
32
+ successIcon?: ReactNode;
33
+ /** Label shown in the success state (e.g. `'Copied'`). Defaults to keeping `label` visible. */
34
+ successLabel?: ReactNode;
35
+ /**
36
+ * Two-step confirm: when set, the first click arms the button (shows this
37
+ * label with a danger tint and a shake on the icon) and only a second
38
+ * click within `confirmTimeout` runs the action. For destructive actions.
39
+ */
40
+ confirmLabel?: ReactNode;
41
+ /** How long the armed state waits for the confirming click, in ms (scaled by `speed`). @default 2600 */
42
+ confirmTimeout?: number;
43
+ /**
44
+ * The action to run. Return a promise to get a pending phase — success
45
+ * shows only after it resolves; a rejection returns to idle and calls
46
+ * `onError`. Synchronous returns jump straight to success. Call
47
+ * `context.setProgress(0–100)` during the promise to switch the pending
48
+ * state from an indeterminate spinner to a determinate progress fill
49
+ * (e.g. a download driven by received bytes / `Content-Length`).
50
+ */
51
+ onAction?: (context: ActionButtonContext) => void | Promise<unknown>;
52
+ /** Label shown while determinate progress is reported. @default percent → `${Math.round(percent)}%` */
53
+ progressLabel?: (percent: number) => ReactNode;
54
+ /** Called when `onAction` throws or rejects. */
55
+ onError?: (error: unknown) => void;
56
+ /** Called whenever the phase changes. */
57
+ onPhaseChange?: (phase: ActionButtonPhase) => void;
58
+ /**
59
+ * How long the success state is held before auto-resetting to idle, in ms
60
+ * (scaled by `speed`). Pass `0` to stay in success until unmounted.
61
+ * @default 1800
62
+ */
63
+ resetAfter?: number;
64
+ /**
65
+ * Playback-speed multiplier for every transition and timer: `2` halves
66
+ * all durations, `0.5` doubles them.
67
+ * @default 1
68
+ */
69
+ speed?: number;
70
+ /** Visual style, same scale as `Button`. @default 'secondary' */
71
+ variant?: 'primary' | 'secondary' | 'danger' | 'ghost';
72
+ /** Button size, same scale as `Button`. @default 'md' */
73
+ size?: 'sm' | 'md' | 'lg';
74
+ /** Square icon-only button — hides all labels. Pair with `aria-label`. @default false */
75
+ iconOnly?: boolean;
76
+ /** Override class names on internal elements. */
77
+ classes?: Partial<ActionButtonClasses>;
78
+ }
79
+ /**
80
+ * Stateful action button with morphing icon and label layers:
81
+ * `idle → (armed) → (pending) → success → idle`.
82
+ *
83
+ * - Sync `onAction` jumps straight to success (icon morphs into a check,
84
+ * label swaps, surface takes a success tint), then auto-resets.
85
+ * - Async `onAction` (returns a promise) shows a pending spinner until it
86
+ * resolves; a rejection returns to idle and calls `onError`.
87
+ * - Call `context.setProgress(0–100)` during the promise for a determinate
88
+ * pending state: % label plus an accent fill bar (download/upload style).
89
+ * - `confirmLabel` adds a two-step confirm for destructive actions.
90
+ * - Clicks are ignored while a sequence is running.
91
+ *
92
+ * Layers are stacked in a grid cell, so the button width never jumps
93
+ * between states. Transitions, colors, and timings are themeable via
94
+ * `--crk-action-*` custom properties; `speed` scales everything at once.
95
+ * The current phase is exposed as `data-phase` on the root for custom CSS.
96
+ *
97
+ * @example
98
+ * <ActionButton
99
+ * icon={<SendIcon />}
100
+ * label="Send"
101
+ * successLabel="Sent"
102
+ * onAction={() => api.send(message)}
103
+ * />
104
+ */
105
+ export declare const ActionButton: import('react').ForwardRefExoticComponent<Omit<ActionButtonProps, "ref"> & import('react').RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,211 @@
1
+ import { jsxs as Y, jsx as t } from "react/jsx-runtime";
2
+ import { forwardRef as Z, useState as M, useRef as b, useEffect as _ } from "react";
3
+ import o from "clsx";
4
+ import i from "./ActionButton.module.scss.js";
5
+ function ee() {
6
+ return /* @__PURE__ */ t(
7
+ "svg",
8
+ {
9
+ width: "1em",
10
+ height: "1em",
11
+ viewBox: "0 0 24 24",
12
+ fill: "none",
13
+ stroke: "currentColor",
14
+ strokeWidth: "2.4",
15
+ strokeLinecap: "round",
16
+ strokeLinejoin: "round",
17
+ "aria-hidden": "true",
18
+ children: /* @__PURE__ */ t("path", { d: "M4 12l5 5L20 6" })
19
+ }
20
+ );
21
+ }
22
+ function ne() {
23
+ return /* @__PURE__ */ t(
24
+ "svg",
25
+ {
26
+ width: "1em",
27
+ height: "1em",
28
+ viewBox: "0 0 24 24",
29
+ fill: "none",
30
+ stroke: "currentColor",
31
+ strokeWidth: "2.4",
32
+ strokeLinecap: "round",
33
+ "aria-hidden": "true",
34
+ children: /* @__PURE__ */ t("path", { d: "M21 12a9 9 0 1 1-9-9" })
35
+ }
36
+ );
37
+ }
38
+ const ie = Z(
39
+ ({
40
+ icon: R,
41
+ label: j,
42
+ pendingIcon: v,
43
+ pendingLabel: T,
44
+ successIcon: A,
45
+ successLabel: k,
46
+ confirmLabel: p,
47
+ confirmTimeout: F = 2600,
48
+ onAction: V,
49
+ progressLabel: O,
50
+ onError: g,
51
+ onPhaseChange: W,
52
+ resetAfter: y = 1800,
53
+ speed: h = 1,
54
+ variant: $ = "secondary",
55
+ size: E = "md",
56
+ iconOnly: L = !1,
57
+ classes: s,
58
+ className: I,
59
+ style: N,
60
+ disabled: w,
61
+ onClick: q,
62
+ ...z
63
+ }, D) => {
64
+ const [n, G] = M("idle"), [a, m] = M(null), f = b("idle"), l = b(!0), u = b({});
65
+ _(() => {
66
+ l.current = !0;
67
+ const e = u.current;
68
+ return () => {
69
+ l.current = !1, Object.values(e).forEach(clearTimeout);
70
+ };
71
+ }, []);
72
+ const r = (e) => {
73
+ f.current = e, G(e), W?.(e);
74
+ }, S = (e, d, X) => {
75
+ clearTimeout(u.current[e]), u.current[e] = setTimeout(d, X / h);
76
+ }, x = () => {
77
+ m(null), r("success"), y > 0 && S("reset", () => {
78
+ f.current === "success" && r("idle");
79
+ }, y);
80
+ }, H = {
81
+ setProgress: (e) => {
82
+ l.current && m(e == null ? null : Math.max(0, Math.min(100, e)));
83
+ }
84
+ }, J = () => {
85
+ clearTimeout(u.current.disarm);
86
+ let e;
87
+ try {
88
+ e = V?.(H);
89
+ } catch (d) {
90
+ r("idle"), g?.(d);
91
+ return;
92
+ }
93
+ e && typeof e.then == "function" ? (r("pending"), e.then(
94
+ () => {
95
+ l.current && x();
96
+ },
97
+ (d) => {
98
+ l.current && (m(null), r("idle"), g?.(d));
99
+ }
100
+ )) : x();
101
+ }, K = (e) => {
102
+ if (q?.(e), !(w || e.defaultPrevented) && !(n === "pending" || n === "success")) {
103
+ if (p != null && n === "idle") {
104
+ r("armed"), S("disarm", () => {
105
+ f.current === "armed" && r("idle");
106
+ }, F);
107
+ return;
108
+ }
109
+ J();
110
+ }
111
+ }, c = n === "pending" && a != null, Q = [
112
+ // During determinate progress the idle icon returns (the fill bar and
113
+ // % label carry the "working" signal); the spinner is for the
114
+ // indeterminate wait only.
115
+ { key: "idle", node: R, visible: n === "idle" || n === "armed" || c },
116
+ {
117
+ key: "pending",
118
+ node: v ?? /* @__PURE__ */ t(ne, {}),
119
+ visible: n === "pending" && !c,
120
+ spin: v === void 0
121
+ },
122
+ { key: "success", node: A ?? /* @__PURE__ */ t(ee, {}), visible: n === "success" }
123
+ ], C = c ? O?.(a) ?? `${Math.round(a)}%` : T, U = n === "idle" || n === "armed" && p == null || n === "pending" && C == null || n === "success" && k == null, P = {
124
+ idle: 0,
125
+ armed: 1,
126
+ pending: 2,
127
+ success: 3
128
+ }, B = [
129
+ { key: "idle", node: j, visible: U },
130
+ { key: "armed", node: p, visible: n === "armed" },
131
+ { key: "pending", node: C, visible: n === "pending" },
132
+ { key: "success", node: k, visible: n === "success" }
133
+ ].filter((e) => e.node != null).map((e) => ({
134
+ ...e,
135
+ position: e.visible ? void 0 : P[e.key] < P[n] ? i.labelAbove : i.labelBelow
136
+ }));
137
+ return /* @__PURE__ */ Y(
138
+ "button",
139
+ {
140
+ ref: D,
141
+ type: "button",
142
+ className: o(
143
+ i.root,
144
+ i[$],
145
+ i[E],
146
+ L && i.iconOnly,
147
+ s?.root,
148
+ I
149
+ ),
150
+ style: h !== 1 ? { ...N, "--crk-action-speed": h } : N,
151
+ "data-phase": n,
152
+ disabled: w,
153
+ "aria-busy": n === "pending" || void 0,
154
+ onClick: K,
155
+ ...z,
156
+ children: [
157
+ /* @__PURE__ */ t(
158
+ "span",
159
+ {
160
+ className: o(
161
+ i.progressFill,
162
+ c && i.progressFillActive,
163
+ s?.progressFill
164
+ ),
165
+ style: { width: `${a ?? 0}%` },
166
+ "aria-hidden": "true"
167
+ }
168
+ ),
169
+ /* @__PURE__ */ t("span", { className: o(i.iconStack, s?.iconStack), "aria-hidden": "true", children: Q.map((e) => /* @__PURE__ */ t(
170
+ "span",
171
+ {
172
+ className: o(
173
+ i.iconLayer,
174
+ e.visible && i.layerVisible,
175
+ e.visible && e.spin && i.iconSpin,
176
+ s?.iconLayer
177
+ ),
178
+ children: e.node
179
+ },
180
+ e.key
181
+ )) }),
182
+ !L && B.length > 0 && /* @__PURE__ */ t(
183
+ "span",
184
+ {
185
+ className: o(i.labelStack, s?.labelStack),
186
+ "aria-live": c ? "off" : "polite",
187
+ children: B.map((e) => /* @__PURE__ */ t(
188
+ "span",
189
+ {
190
+ "aria-hidden": e.visible ? void 0 : !0,
191
+ className: o(
192
+ i.labelLayer,
193
+ e.visible && i.layerVisible,
194
+ e.position,
195
+ s?.labelLayer
196
+ ),
197
+ children: e.node
198
+ },
199
+ e.key
200
+ ))
201
+ }
202
+ )
203
+ ]
204
+ }
205
+ );
206
+ }
207
+ );
208
+ ie.displayName = "ActionButton";
209
+ export {
210
+ ie as ActionButton
211
+ };
@@ -0,0 +1,47 @@
1
+ const c = "crk-root--5DQa", o = "crk-primary-8sEXz", r = "crk-secondary-gchUR", n = "crk-danger-3Rwvr", l = "crk-ghost-NA6NO", e = "crk-sm-8Gx7n", s = "crk-md-1Aojo", t = "crk-lg-G-QeV", a = "crk-iconOnly-RXD7w", i = "crk-progressFill-fQBjO", k = "crk-progressFillActive-UUIFs", y = "crk-iconStack-cDz8K", b = "crk-iconLayer--8ZB0", g = "crk-iconSpin-P42Mx", p = "crk-crkActionSpin-hNXj5", S = "crk-labelStack-IdCBl", A = "crk-labelLayer-42FKW", d = "crk-labelAbove-GC0xj", m = "crk-labelBelow-ozPt1", h = "crk-layerVisible-zoVoM", F = "crk-crkActionShake-IQ6fK", v = {
2
+ root: c,
3
+ primary: o,
4
+ secondary: r,
5
+ danger: n,
6
+ ghost: l,
7
+ sm: e,
8
+ md: s,
9
+ lg: t,
10
+ iconOnly: a,
11
+ progressFill: i,
12
+ progressFillActive: k,
13
+ iconStack: y,
14
+ iconLayer: b,
15
+ iconSpin: g,
16
+ crkActionSpin: p,
17
+ labelStack: S,
18
+ labelLayer: A,
19
+ labelAbove: d,
20
+ labelBelow: m,
21
+ layerVisible: h,
22
+ crkActionShake: F
23
+ };
24
+ export {
25
+ F as crkActionShake,
26
+ p as crkActionSpin,
27
+ n as danger,
28
+ v as default,
29
+ l as ghost,
30
+ b as iconLayer,
31
+ a as iconOnly,
32
+ g as iconSpin,
33
+ y as iconStack,
34
+ d as labelAbove,
35
+ m as labelBelow,
36
+ A as labelLayer,
37
+ S as labelStack,
38
+ h as layerVisible,
39
+ t as lg,
40
+ s as md,
41
+ o as primary,
42
+ i as progressFill,
43
+ k as progressFillActive,
44
+ c as root,
45
+ r as secondary,
46
+ e as sm
47
+ };
@@ -0,0 +1,31 @@
1
+ import { ReactNode } from 'react';
2
+ import { ActionButtonProps } from './ActionButton';
3
+ export interface CopyButtonProps extends Omit<ActionButtonProps, 'icon' | 'label' | 'onAction' | 'value'> {
4
+ /**
5
+ * The text to copy, or a function returning it (lazily, possibly async —
6
+ * an async function shows the pending spinner until it resolves).
7
+ */
8
+ value: string | (() => string | Promise<string>);
9
+ /** Idle icon. @default built-in clipboard icon */
10
+ icon?: ReactNode;
11
+ /** Idle label. Hidden when `iconOnly` is set. @default 'Copy' */
12
+ label?: ReactNode;
13
+ /** Called with the copied text after a successful copy. */
14
+ onCopied?: (text: string) => void;
15
+ }
16
+ /**
17
+ * Copy-to-clipboard button: clipboard icon morphs into a check, the label
18
+ * swaps `Copy → Copied`, and the surface takes a success tint before
19
+ * auto-resetting. Built on `ActionButton` — all its props (`variant`,
20
+ * `size`, `speed`, `resetAfter`, `classes`, …) apply.
21
+ *
22
+ * Icon + text by default; pass `iconOnly` (with an `aria-label`) for a
23
+ * square icon-only trigger. Success shows only after the clipboard write
24
+ * confirms; failures return to idle and call `onError`.
25
+ *
26
+ * @example
27
+ * <CopyButton value={shareUrl} />
28
+ * // icon-only:
29
+ * <CopyButton value={shareUrl} iconOnly aria-label="Copy link" />
30
+ */
31
+ export declare const CopyButton: import('react').ForwardRefExoticComponent<Omit<CopyButtonProps, "ref"> & import('react').RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,66 @@
1
+ import { jsx as e, jsxs as l } from "react/jsx-runtime";
2
+ import { forwardRef as s } from "react";
3
+ import { ActionButton as y } from "./ActionButton.js";
4
+ function f() {
5
+ return /* @__PURE__ */ l(
6
+ "svg",
7
+ {
8
+ width: "1em",
9
+ height: "1em",
10
+ viewBox: "0 0 24 24",
11
+ fill: "none",
12
+ stroke: "currentColor",
13
+ strokeWidth: "2",
14
+ strokeLinecap: "round",
15
+ strokeLinejoin: "round",
16
+ "aria-hidden": "true",
17
+ children: [
18
+ /* @__PURE__ */ e("rect", { x: "9", y: "9", width: "12", height: "12", rx: "2" }),
19
+ /* @__PURE__ */ e("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
20
+ ]
21
+ }
22
+ );
23
+ }
24
+ async function m(o) {
25
+ if (typeof navigator < "u" && navigator.clipboard?.writeText) {
26
+ await navigator.clipboard.writeText(o);
27
+ return;
28
+ }
29
+ const t = document.createElement("textarea");
30
+ t.value = o, t.style.position = "fixed", t.style.opacity = "0", document.body.appendChild(t), t.select();
31
+ try {
32
+ if (!document.execCommand("copy"))
33
+ throw new Error("Copy to clipboard failed");
34
+ } finally {
35
+ t.remove();
36
+ }
37
+ }
38
+ const u = s(
39
+ ({
40
+ value: o,
41
+ icon: t = /* @__PURE__ */ e(f, {}),
42
+ label: n = "Copy",
43
+ successLabel: r = "Copied",
44
+ onCopied: a,
45
+ style: c,
46
+ ...d
47
+ }, p) => /* @__PURE__ */ e(
48
+ y,
49
+ {
50
+ ref: p,
51
+ icon: t,
52
+ label: n,
53
+ successLabel: r,
54
+ onAction: async () => {
55
+ const i = typeof o == "function" ? await o() : o;
56
+ await m(i), a?.(i);
57
+ },
58
+ style: { "--crk-action-icon-exit": "scale(0.4) rotate(-40deg)", ...c },
59
+ ...d
60
+ }
61
+ )
62
+ );
63
+ u.displayName = "CopyButton";
64
+ export {
65
+ u as CopyButton
66
+ };
@@ -0,0 +1,4 @@
1
+ export { ActionButton } from './ActionButton';
2
+ export type { ActionButtonProps, ActionButtonClasses, ActionButtonPhase, ActionButtonContext, } from './ActionButton';
3
+ export { CopyButton } from './CopyButton';
4
+ export type { CopyButtonProps } from './CopyButton';
@@ -0,0 +1,82 @@
1
+ import { jsxs as u, jsx as e } from "react/jsx-runtime";
2
+ import { forwardRef as f } from "react";
3
+ import a from "clsx";
4
+ import l from "./Alert.module.scss.js";
5
+ const p = {
6
+ info: /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ e(
7
+ "path",
8
+ {
9
+ fillRule: "evenodd",
10
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zM9 9a1 1 0 012 0v4a1 1 0 11-2 0V9zm1-4a1 1 0 100 2 1 1 0 000-2z",
11
+ clipRule: "evenodd"
12
+ }
13
+ ) }),
14
+ success: /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ e(
15
+ "path",
16
+ {
17
+ fillRule: "evenodd",
18
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.7-9.3a1 1 0 00-1.4-1.4L9 10.6 7.7 9.3a1 1 0 00-1.4 1.4l2 2a1 1 0 001.4 0l4-4z",
19
+ clipRule: "evenodd"
20
+ }
21
+ ) }),
22
+ warning: /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ e(
23
+ "path",
24
+ {
25
+ fillRule: "evenodd",
26
+ d: "M8.26 3.1c.77-1.33 2.71-1.33 3.48 0l5.58 9.67c.77 1.33-.19 3-1.74 3H4.42c-1.55 0-2.51-1.67-1.74-3L8.26 3.1zM10 7a1 1 0 011 1v3a1 1 0 11-2 0V8a1 1 0 011-1zm0 7a1 1 0 100-2 1 1 0 000 2z",
27
+ clipRule: "evenodd"
28
+ }
29
+ ) }),
30
+ danger: /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ e(
31
+ "path",
32
+ {
33
+ fillRule: "evenodd",
34
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.7 7.3a1 1 0 00-1.4 1.4L8.6 10l-1.3 1.3a1 1 0 101.4 1.4L10 11.4l1.3 1.3a1 1 0 001.4-1.4L11.4 10l1.3-1.3a1 1 0 00-1.4-1.4L10 8.6 8.7 7.3z",
35
+ clipRule: "evenodd"
36
+ }
37
+ ) })
38
+ }, z = f(
39
+ ({
40
+ variant: d = "info",
41
+ title: o,
42
+ icon: i = !0,
43
+ onClose: n,
44
+ closeLabel: s = "Dismiss",
45
+ classes: r,
46
+ className: v,
47
+ children: t,
48
+ ...m
49
+ }, h) => {
50
+ const c = i === !0 ? p[d] : i === !1 ? null : i;
51
+ return /* @__PURE__ */ u(
52
+ "div",
53
+ {
54
+ ref: h,
55
+ role: "alert",
56
+ className: a(l.root, l[d], r?.root, v),
57
+ ...m,
58
+ children: [
59
+ c != null && /* @__PURE__ */ e("span", { className: a(l.icon, r?.icon), "aria-hidden": "true", children: c }),
60
+ /* @__PURE__ */ u("div", { className: a(l.content, r?.content), children: [
61
+ o != null && /* @__PURE__ */ e("div", { className: a(l.title, r?.title), children: o }),
62
+ t != null && /* @__PURE__ */ e("div", { className: a(l.message, r?.message), children: t })
63
+ ] }),
64
+ n && /* @__PURE__ */ e(
65
+ "button",
66
+ {
67
+ type: "button",
68
+ className: a(l.close, r?.close),
69
+ onClick: n,
70
+ "aria-label": s,
71
+ children: /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M6.3 6.3a1 1 0 011.4 0L10 8.6l2.3-2.3a1 1 0 111.4 1.4L11.4 10l2.3 2.3a1 1 0 01-1.4 1.4L10 11.4l-2.3 2.3a1 1 0 01-1.4-1.4L8.6 10 6.3 7.7a1 1 0 010-1.4z" }) })
72
+ }
73
+ )
74
+ ]
75
+ }
76
+ );
77
+ }
78
+ );
79
+ z.displayName = "Alert";
80
+ export {
81
+ z as Alert
82
+ };