@overdoser/react-toolkit 0.17.0 → 0.19.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 (160) hide show
  1. package/AGENTS.md +51 -7
  2. package/CHANGELOG.md +149 -0
  3. package/components/Accordion/Accordion.d.ts +94 -0
  4. package/components/Accordion/Accordion.js +180 -0
  5. package/components/Accordion/Accordion.module.scss.js +36 -0
  6. package/components/Accordion/index.d.ts +2 -0
  7. package/components/Alert/Alert.d.ts +29 -1
  8. package/components/Alert/Alert.js +44 -30
  9. package/components/Alert/Alert.module.scss.js +24 -16
  10. package/components/Alert/index.d.ts +1 -1
  11. package/components/Card/Card.d.ts +86 -0
  12. package/components/Card/Card.js +132 -0
  13. package/components/Card/Card.module.scss.js +60 -0
  14. package/components/Card/index.d.ts +2 -0
  15. package/components/Chip/Chip.d.ts +86 -0
  16. package/components/Chip/Chip.js +141 -0
  17. package/components/Chip/Chip.module.scss.js +59 -0
  18. package/components/Chip/index.d.ts +2 -0
  19. package/components/CodeBlock/CodeBlock.d.ts +78 -0
  20. package/components/CodeBlock/CodeBlock.js +120 -0
  21. package/components/CodeBlock/CodeBlock.module.scss.js +43 -0
  22. package/components/CodeBlock/index.d.ts +2 -0
  23. package/components/CommandPalette/CommandPalette.d.ts +141 -0
  24. package/components/CommandPalette/CommandPalette.js +397 -0
  25. package/components/CommandPalette/CommandPalette.module.scss.js +49 -0
  26. package/components/CommandPalette/index.d.ts +2 -0
  27. package/components/ConfirmDialog/ConfirmDialog.d.ts +119 -0
  28. package/components/ConfirmDialog/ConfirmDialog.js +201 -0
  29. package/components/ConfirmDialog/ConfirmDialog.module.scss.js +21 -0
  30. package/components/ConfirmDialog/index.d.ts +2 -0
  31. package/components/Drawer/Drawer.d.ts +1 -0
  32. package/components/Drawer/Drawer.js +35 -36
  33. package/components/Drawer/Drawer.module.scss.js +20 -18
  34. package/components/Dropdown/Dropdown.d.ts +47 -7
  35. package/components/Dropdown/Dropdown.js +174 -81
  36. package/components/Dropdown/Dropdown.module.scss.js +40 -22
  37. package/components/Dropdown/DropdownItem.d.ts +31 -2
  38. package/components/Dropdown/DropdownItem.js +54 -27
  39. package/components/Dropdown/DropdownLabel.d.ts +11 -0
  40. package/components/Dropdown/DropdownLabel.js +11 -0
  41. package/components/Dropdown/DropdownSeparator.d.ts +12 -0
  42. package/components/Dropdown/DropdownSeparator.js +11 -0
  43. package/components/Dropdown/dropdownContext.d.ts +6 -0
  44. package/components/Dropdown/dropdownContext.js +5 -0
  45. package/components/Dropdown/index.d.ts +8 -2
  46. package/components/Dropdown/useContextMenu.d.ts +32 -0
  47. package/components/Dropdown/useContextMenu.js +18 -0
  48. package/components/EmptyState/EmptyState.d.ts +53 -0
  49. package/components/EmptyState/EmptyState.js +55 -0
  50. package/components/EmptyState/EmptyState.module.scss.js +25 -0
  51. package/components/EmptyState/index.d.ts +2 -0
  52. package/components/Form/FormField.js +25 -24
  53. package/components/ImageViewer/ImageViewer.d.ts +105 -0
  54. package/components/ImageViewer/ImageViewer.js +201 -0
  55. package/components/ImageViewer/ImageViewer.module.scss.js +47 -0
  56. package/components/ImageViewer/index.d.ts +4 -0
  57. package/components/ImageViewer/useZoomPan.d.ts +94 -0
  58. package/components/ImageViewer/useZoomPan.js +141 -0
  59. package/components/Kbd/Kbd.d.ts +26 -0
  60. package/components/Kbd/Kbd.js +22 -0
  61. package/components/Kbd/Kbd.module.scss.js +17 -0
  62. package/components/Kbd/index.d.ts +2 -0
  63. package/components/KeyValueList/KeyValueList.d.ts +84 -0
  64. package/components/KeyValueList/KeyValueList.js +127 -0
  65. package/components/KeyValueList/KeyValueList.module.scss.js +43 -0
  66. package/components/KeyValueList/index.d.ts +2 -0
  67. package/components/Loader/Loader.d.ts +104 -0
  68. package/components/Loader/Loader.js +186 -0
  69. package/components/Loader/Loader.module.scss.js +70 -0
  70. package/components/Loader/index.d.ts +2 -0
  71. package/components/Modal/Modal.d.ts +1 -0
  72. package/components/Modal/Modal.js +40 -41
  73. package/components/Modal/Modal.module.scss.js +18 -16
  74. package/components/PageHeader/PageHeader.d.ts +61 -0
  75. package/components/PageHeader/PageHeader.js +73 -0
  76. package/components/PageHeader/PageHeader.module.scss.js +43 -0
  77. package/components/PageHeader/index.d.ts +2 -0
  78. package/components/ProgressBar/ProgressBar.d.ts +74 -0
  79. package/components/ProgressBar/ProgressBar.js +90 -0
  80. package/components/ProgressBar/ProgressBar.module.scss.js +51 -0
  81. package/components/ProgressBar/index.d.ts +2 -0
  82. package/components/RelativeTime/RelativeTime.d.ts +45 -0
  83. package/components/RelativeTime/RelativeTime.js +43 -0
  84. package/components/RelativeTime/RelativeTime.module.scss.js +7 -0
  85. package/components/RelativeTime/index.d.ts +2 -0
  86. package/components/SegmentedControl/SegmentedControl.d.ts +84 -0
  87. package/components/SegmentedControl/SegmentedControl.js +131 -0
  88. package/components/SegmentedControl/SegmentedControl.module.scss.js +39 -0
  89. package/components/SegmentedControl/index.d.ts +2 -0
  90. package/components/SplitPane/SplitPane.d.ts +61 -0
  91. package/components/SplitPane/SplitPane.js +171 -0
  92. package/components/SplitPane/SplitPane.module.scss.js +25 -0
  93. package/components/SplitPane/index.d.ts +2 -0
  94. package/components/StatCard/StatCard.d.ts +105 -0
  95. package/components/StatCard/StatCard.js +127 -0
  96. package/components/StatCard/StatCard.module.scss.js +72 -0
  97. package/components/StatCard/index.d.ts +2 -0
  98. package/components/StatusDot/StatusDot.d.ts +33 -0
  99. package/components/StatusDot/StatusDot.js +39 -0
  100. package/components/StatusDot/StatusDot.module.scss.js +32 -0
  101. package/components/StatusDot/index.d.ts +2 -0
  102. package/components/Table/Table.d.ts +100 -2
  103. package/components/Table/Table.js +371 -210
  104. package/components/Table/Table.module.scss.js +68 -46
  105. package/components/Table/index.d.ts +1 -1
  106. package/components/ThemeToggle/ThemeToggle.d.ts +38 -0
  107. package/components/ThemeToggle/ThemeToggle.js +97 -0
  108. package/components/ThemeToggle/ThemeToggle.module.scss.js +23 -0
  109. package/components/ThemeToggle/index.d.ts +2 -0
  110. package/components/inputs/Checkbox/Checkbox.d.ts +2 -0
  111. package/components/inputs/Checkbox/Checkbox.js +29 -28
  112. package/components/inputs/Checkbox/Checkbox.module.scss.js +8 -6
  113. package/components/inputs/Input/Input.d.ts +33 -1
  114. package/components/inputs/Input/Input.js +94 -35
  115. package/components/inputs/Input/Input.module.scss.js +14 -12
  116. package/components/inputs/Radio/Radio.d.ts +5 -4
  117. package/components/inputs/Radio/Radio.js +55 -50
  118. package/components/inputs/Radio/Radio.module.scss.js +12 -10
  119. package/components/inputs/SearchInput/SearchInput.d.ts +57 -0
  120. package/components/inputs/SearchInput/SearchInput.js +116 -0
  121. package/components/inputs/SearchInput/SearchInput.module.scss.js +13 -0
  122. package/components/inputs/SearchInput/index.d.ts +2 -0
  123. package/components/inputs/Select/Select.d.ts +52 -0
  124. package/components/inputs/Select/Select.js +494 -385
  125. package/components/inputs/Select/Select.module.scss.js +34 -30
  126. package/components/inputs/Switch/Switch.d.ts +15 -0
  127. package/components/inputs/Switch/Switch.js +8 -0
  128. package/components/inputs/Switch/index.d.ts +2 -0
  129. package/hooks/useDebouncedValue.d.ts +15 -0
  130. package/hooks/useDebouncedValue.js +15 -0
  131. package/hooks/useElementSize.d.ts +20 -0
  132. package/hooks/useElementSize.js +23 -0
  133. package/hooks/useKeyboard.d.ts +49 -5
  134. package/hooks/useKeyboard.js +66 -16
  135. package/hooks/useMediaQuery.d.ts +14 -0
  136. package/hooks/useMediaQuery.js +16 -0
  137. package/hooks/useNow.d.ts +14 -0
  138. package/hooks/useNow.js +35 -0
  139. package/hooks/usePersistedState.d.ts +30 -0
  140. package/hooks/usePersistedState.js +96 -0
  141. package/hooks/useResizable.d.ts +66 -0
  142. package/hooks/useResizable.js +105 -0
  143. package/hooks/useTheme.d.ts +33 -0
  144. package/hooks/useTheme.js +27 -0
  145. package/index.css +1 -1
  146. package/index.d.ts +60 -4
  147. package/index.js +208 -130
  148. package/index.layered.css +1 -1
  149. package/llms.txt +659 -25
  150. package/manifest.json +1797 -76
  151. package/package.json +1 -1
  152. package/recipes/confirm-modal.tsx +65 -53
  153. package/recipes/floating-copy-button.tsx +32 -28
  154. package/utils/formatBytes.d.ts +21 -0
  155. package/utils/formatBytes.js +14 -0
  156. package/utils/index.d.ts +6 -0
  157. package/utils/themeScript.d.ts +17 -0
  158. package/utils/themeScript.js +9 -0
  159. package/utils/timeAgo.d.ts +33 -0
  160. package/utils/timeAgo.js +37 -0
@@ -0,0 +1,53 @@
1
+ import { ComponentPropsWithRef, ReactNode } from 'react';
2
+ export interface EmptyStateClasses {
3
+ root: string;
4
+ icon: string;
5
+ title: string;
6
+ description: string;
7
+ action: string;
8
+ }
9
+ export type EmptyStateVariant = 'empty' | 'error';
10
+ export interface EmptyStateProps extends Omit<ComponentPropsWithRef<'div'>, 'title'> {
11
+ /**
12
+ * `'empty'` for "nothing here yet / no results"; `'error'` for a failed
13
+ * load — sets `role="alert"` and tints the icon with the danger colour.
14
+ * @default 'empty'
15
+ */
16
+ variant?: EmptyStateVariant;
17
+ /**
18
+ * Leading illustration. Defaults to a built-in inline SVG per variant (an
19
+ * inbox tray for `empty`, a warning triangle for `error`). Pass `false` to
20
+ * render no icon. @default built-in per variant
21
+ */
22
+ icon?: ReactNode | false;
23
+ /** Short heading (e.g. "No projects yet"). */
24
+ title?: ReactNode;
25
+ /** One or two sentences under the title. */
26
+ description?: ReactNode;
27
+ /** Slot under the description — typically a `Button` ("Create", "Retry"). */
28
+ action?: ReactNode;
29
+ /** Extra content rendered between the description and the action. */
30
+ children?: ReactNode;
31
+ /** Scales the icon, text and padding. @default 'md' */
32
+ size?: 'sm' | 'md' | 'lg';
33
+ /** Dashed frame around the block (for empty panels / drop targets). @default false */
34
+ bordered?: boolean;
35
+ /** Override class names on internal elements. */
36
+ classes?: Partial<EmptyStateClasses>;
37
+ }
38
+ /**
39
+ * Centered placeholder for empty lists, no-results views and failed loads:
40
+ * icon + title + description + an action slot.
41
+ *
42
+ * @example
43
+ * <EmptyState
44
+ * title="No projects yet"
45
+ * description="Create your first project to get started."
46
+ * action={<Button onClick={create}>New project</Button>}
47
+ * />
48
+ *
49
+ * @example
50
+ * // Load error with retry
51
+ * <EmptyState variant="error" title="Couldn't load projects" action={<Button onClick={refetch}>Retry</Button>} />
52
+ */
53
+ export declare const EmptyState: import('react').ForwardRefExoticComponent<Omit<EmptyStateProps, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,55 @@
1
+ import { jsxs as n, jsx as r } from "react/jsx-runtime";
2
+ import { forwardRef as k } from "react";
3
+ import t from "clsx";
4
+ import o from "./EmptyState.module.scss.js";
5
+ const x = () => /* @__PURE__ */ n("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
6
+ /* @__PURE__ */ r("path", { d: "M3 13h4l2 3h6l2-3h4" }),
7
+ /* @__PURE__ */ r("path", { d: "M5 5h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2z" })
8
+ ] }), y = () => /* @__PURE__ */ n("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
9
+ /* @__PURE__ */ r("path", { d: "M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z" }),
10
+ /* @__PURE__ */ r("path", { d: "M12 9v4" }),
11
+ /* @__PURE__ */ r("path", { d: "M12 17h.01" })
12
+ ] }), N = k(
13
+ ({
14
+ variant: i = "empty",
15
+ icon: a,
16
+ title: l,
17
+ description: c,
18
+ action: h,
19
+ children: s,
20
+ size: m = "md",
21
+ bordered: p = !1,
22
+ classes: e,
23
+ className: v,
24
+ ...u
25
+ }, f) => {
26
+ const d = a === void 0 ? i === "error" ? /* @__PURE__ */ r(y, {}) : /* @__PURE__ */ r(x, {}) : a;
27
+ return /* @__PURE__ */ n(
28
+ "div",
29
+ {
30
+ ref: f,
31
+ role: i === "error" ? "alert" : void 0,
32
+ className: t(
33
+ o.root,
34
+ o[i],
35
+ o[m],
36
+ p && o.bordered,
37
+ e?.root,
38
+ v
39
+ ),
40
+ ...u,
41
+ children: [
42
+ d !== !1 && d != null && /* @__PURE__ */ r("div", { className: t(o.icon, e?.icon), "aria-hidden": "true", children: d }),
43
+ l && /* @__PURE__ */ r("div", { className: t(o.title, e?.title), children: l }),
44
+ c && /* @__PURE__ */ r("div", { className: t(o.description, e?.description), children: c }),
45
+ s,
46
+ h && /* @__PURE__ */ r("div", { className: t(o.action, e?.action), children: h })
47
+ ]
48
+ }
49
+ );
50
+ }
51
+ );
52
+ N.displayName = "EmptyState";
53
+ export {
54
+ N as EmptyState
55
+ };
@@ -0,0 +1,25 @@
1
+ const r = "crk-root--QSMy", o = "crk-sm-X3NZF", t = "crk-title-AfRVx", c = "crk-md-redWw", n = "crk-lg-Lnt1u", s = "crk-error-Y09vt", e = "crk-bordered-aCCLu", i = "crk-icon-ABwaI", d = "crk-description--LJrG", k = "crk-action-7ICV2", l = {
2
+ root: r,
3
+ sm: o,
4
+ title: t,
5
+ md: c,
6
+ lg: n,
7
+ error: s,
8
+ bordered: e,
9
+ icon: i,
10
+ description: d,
11
+ action: k
12
+ };
13
+ export {
14
+ k as action,
15
+ e as bordered,
16
+ l as default,
17
+ d as description,
18
+ s as error,
19
+ i as icon,
20
+ n as lg,
21
+ c as md,
22
+ r as root,
23
+ o as sm,
24
+ t as title
25
+ };
@@ -0,0 +1,2 @@
1
+ export { EmptyState } from './EmptyState';
2
+ export type { EmptyStateProps, EmptyStateClasses, EmptyStateVariant } from './EmptyState';
@@ -1,48 +1,49 @@
1
- import { jsxs as g, jsx as c } from "react/jsx-runtime";
2
- import { useContext as V, useRef as j, useCallback as B, cloneElement as T } from "react";
3
- import { useFormContext as k, useController as q } from "react-hook-form";
1
+ import { jsxs as v, jsx as c } from "react/jsx-runtime";
2
+ import { useContext as D, useRef as j, useCallback as T, cloneElement as k } from "react";
3
+ import { useFormContext as q, useController as w } from "react-hook-form";
4
4
  import n from "clsx";
5
5
  import t from "./Form.module.scss.js";
6
- import { FormFieldDefaultsContext as w } from "./formFieldDefaults.js";
7
- const H = /* @__PURE__ */ new Set([
6
+ import { FormFieldDefaultsContext as H } from "./formFieldDefaults.js";
7
+ const M = /* @__PURE__ */ new Set([
8
8
  "Select",
9
9
  "NativeSelect",
10
10
  "SearchableSelect",
11
11
  "MultiSelect",
12
12
  "Dropdown"
13
13
  ]);
14
- function L({
14
+ function P({
15
15
  name: e,
16
16
  label: f,
17
17
  helperText: d,
18
- required: v,
19
- rules: x,
20
- reserveErrorSpace: y,
18
+ required: x,
19
+ rules: y,
20
+ reserveErrorSpace: S,
21
21
  classes: o,
22
- className: S,
23
- style: N,
22
+ className: N,
23
+ style: C,
24
24
  children: p
25
25
  }) {
26
- const { control: C } = k(), { field: R, fieldState: r } = q({ name: e, control: C, rules: x }), h = V(w), l = y ?? h?.reserveErrorSpace ?? !0, s = h?.classes, m = p.type, E = typeof m == "string" ? "" : m?.displayName ?? m?.name ?? "", F = H.has(E), { ref: b, ...a } = R, u = j(b);
27
- u.current = b;
28
- const $ = B(
26
+ const { control: R } = q(), { field: E, fieldState: r } = w({ name: e, control: R, rules: y }), h = D(H), l = S ?? h?.reserveErrorSpace ?? !0, s = h?.classes, u = p.type, F = typeof u == "string" ? "" : u?.displayName ?? u?.name ?? "", V = M.has(F), { ref: b, ...a } = E, g = typeof a.value == "boolean", m = j(b);
27
+ m.current = b;
28
+ const $ = T(
29
29
  (i) => {
30
30
  if (i) {
31
- const D = i.matches("input, select, textarea, button, [tabindex]") ? i : i.querySelector('input, select, textarea, button, [tabindex]:not([tabindex="-1"])');
32
- u.current(D ?? i);
31
+ const B = i.matches("input, select, textarea, button, [tabindex]") ? i : i.querySelector('input, select, textarea, button, [tabindex]:not([tabindex="-1"])');
32
+ m.current(B ?? i);
33
33
  } else
34
- u.current(null);
34
+ m.current(null);
35
35
  },
36
36
  // eslint-disable-next-line react-hooks/exhaustive-deps
37
37
  []
38
38
  );
39
- return /* @__PURE__ */ g("div", { className: n(t.field, s?.field, o?.field, S), style: N, children: [
40
- f && /* @__PURE__ */ g("label", { className: n(t.label, r.error && t.labelError, s?.label, o?.label), htmlFor: e, children: [
39
+ return /* @__PURE__ */ v("div", { className: n(t.field, s?.field, o?.field, N), style: C, children: [
40
+ f && /* @__PURE__ */ v("label", { className: n(t.label, r.error && t.labelError, s?.label, o?.label), htmlFor: e, children: [
41
41
  f,
42
- v && /* @__PURE__ */ c("span", { className: t.required, children: "*" })
42
+ x && /* @__PURE__ */ c("span", { className: t.required, children: "*" })
43
43
  ] }),
44
- T(p, {
44
+ k(p, {
45
45
  ...a,
46
+ ...g && { value: void 0 },
46
47
  ref: $,
47
48
  id: e,
48
49
  error: !!r.error,
@@ -52,12 +53,12 @@ function L({
52
53
  // Bridge for custom components that use onValueChange/onValuesChange (Select, Dropdown).
53
54
  // Skip for native-input wrappers (Input, Textarea, Checkbox, Radio) so the unknown
54
55
  // handler doesn't leak onto the DOM and trip React's "Unknown event handler" warning.
55
- ...F && {
56
+ ...V && {
56
57
  onValueChange: a.onChange,
57
58
  onValuesChange: a.onChange
58
59
  },
59
60
  // Bridge for Checkbox (expects checked, not value)
60
- checked: typeof a.value == "boolean" ? a.value : void 0
61
+ checked: g ? a.value : void 0
61
62
  }),
62
63
  r.error?.message && /* @__PURE__ */ c("span", { id: `${e}-error`, className: n(t.error, s?.error, o?.error), role: "alert", children: r.error.message }),
63
64
  d && /* @__PURE__ */ c("span", { id: `${e}-helper`, className: n(t.helperText, s?.helperText, o?.helperText), children: d }),
@@ -72,5 +73,5 @@ function L({
72
73
  ] });
73
74
  }
74
75
  export {
75
- L as FormField
76
+ P as FormField
76
77
  };
@@ -0,0 +1,105 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ import { UseZoomPanOptions } from './useZoomPan';
3
+ export interface ImageViewerItem {
4
+ /** Full-size image URL. */
5
+ src: string;
6
+ /** Alt text; also names the dialog while this image is shown. */
7
+ alt?: string;
8
+ /** Thumbnail URL for the strip (defaults to `src`). */
9
+ thumbnail?: string;
10
+ /** Caption rendered under the stage. */
11
+ caption?: ReactNode;
12
+ /** Download URL, or `true` to download `src`. */
13
+ download?: string | boolean;
14
+ }
15
+ export interface ImageViewerClasses {
16
+ root: string;
17
+ backdrop: string;
18
+ toolbar: string;
19
+ counter: string;
20
+ stage: string;
21
+ image: string;
22
+ caption: string;
23
+ nav: string;
24
+ navPrev: string;
25
+ navNext: string;
26
+ thumbnails: string;
27
+ thumbnail: string;
28
+ thumbnailActive: string;
29
+ zoomControls: string;
30
+ }
31
+ export interface ImageViewerLabels {
32
+ /** Dialog name when the current item has no `alt`. @default 'Image viewer' */
33
+ viewer: string;
34
+ close: string;
35
+ previous: string;
36
+ next: string;
37
+ zoomIn: string;
38
+ zoomOut: string;
39
+ reset: string;
40
+ fit: string;
41
+ download: string;
42
+ /** Spinner label while the image loads. @default 'Loading image' */
43
+ loading: string;
44
+ }
45
+ export interface ImageViewerSlideContext {
46
+ index: number;
47
+ /** Always `true` today (only the current slide is mounted); reserved for carousel rendering. */
48
+ active: boolean;
49
+ }
50
+ export interface ImageViewerProps {
51
+ /** Whether the viewer is visible. */
52
+ open: boolean;
53
+ /** Called on close button, Escape, or backdrop click. */
54
+ onClose: () => void;
55
+ /** The gallery. A single item hides the navigation. */
56
+ items: ImageViewerItem[];
57
+ /** Controlled current index. */
58
+ index?: number;
59
+ /** Initial index (uncontrolled). @default 0 */
60
+ defaultIndex?: number;
61
+ /** Fires when the user navigates (arrows, keys, thumbnails, swipe). */
62
+ onIndexChange?: (index: number) => void;
63
+ /** Wrap from the last image to the first. @default true */
64
+ loop?: boolean;
65
+ /** Show "3 / 12" in the toolbar. @default true */
66
+ showCounter?: boolean;
67
+ /** Thumbnail strip under the stage. @default false */
68
+ showThumbnails?: boolean;
69
+ /** −/%/+ and Reset/Fit buttons in the toolbar. @default true */
70
+ showZoomControls?: boolean;
71
+ /** Download button; defaults to showing it when the item has `download`. */
72
+ showDownload?: boolean;
73
+ /** Replace the `<img>` for an item (a video, a PDF frame…). The returned node is zoomed/panned like an image. */
74
+ renderSlide?: (item: ImageViewerItem, ctx: ImageViewerSlideContext) => ReactNode;
75
+ /** Click on the stage outside the image closes the viewer. @default true */
76
+ closeOnBackdrop?: boolean;
77
+ /** Options for the zoom/pan engine (`minScale`, `maxScale`, `step`, `wheel`, `doubleClickToggle`). */
78
+ zoom?: Partial<UseZoomPanOptions>;
79
+ /** Button labels / dialog name. */
80
+ labels?: Partial<ImageViewerLabels>;
81
+ /** Override class names on internal elements. */
82
+ classes?: Partial<ImageViewerClasses>;
83
+ className?: string;
84
+ style?: CSSProperties;
85
+ }
86
+ /**
87
+ * Full-screen lightbox for one or more images: prev/next (arrows, keys,
88
+ * swipe), wheel / pinch / double-click zoom with drag-to-pan, counter,
89
+ * captions, optional thumbnail strip and download. Portals to
90
+ * `document.body`, traps focus, locks body scroll and closes on Escape
91
+ * through the overlay stack (an open menu inside closes first).
92
+ *
93
+ * @example
94
+ * const [open, setOpen] = useState(false);
95
+ * const [index, setIndex] = useState(0);
96
+ * <ImageViewer
97
+ * open={open}
98
+ * onClose={() => setOpen(false)}
99
+ * items={photos.map((p) => ({ src: p.url, alt: p.title, caption: p.title, download: true }))}
100
+ * index={index}
101
+ * onIndexChange={setIndex}
102
+ * showThumbnails
103
+ * />
104
+ */
105
+ export declare const ImageViewer: import('react').ForwardRefExoticComponent<ImageViewerProps & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,201 @@
1
+ import { jsx as e, jsxs as f, Fragment as ce } from "react/jsx-runtime";
2
+ import { forwardRef as de, useState as O, useRef as C, useCallback as P, useEffect as z, useId as ue } from "react";
3
+ import { createPortal as me } from "react-dom";
4
+ import c from "clsx";
5
+ import t from "./ImageViewer.module.scss.js";
6
+ import { useFocusTrap as he } from "../../hooks/useFocusTrap.js";
7
+ import { useEscapeLayer as fe, EscapeLayerProvider as pe } from "../../hooks/useEscapeLayer.js";
8
+ import { useKeyboard as ve } from "../../hooks/useKeyboard.js";
9
+ import { Spinner as be } from "../Spinner/Spinner.js";
10
+ import { useZoomPan as ge } from "./useZoomPan.js";
11
+ const ye = {
12
+ viewer: "Image viewer",
13
+ close: "Close",
14
+ previous: "Previous image",
15
+ next: "Next image",
16
+ zoomIn: "Zoom in",
17
+ zoomOut: "Zoom out",
18
+ reset: "Reset zoom",
19
+ fit: "Fit to screen",
20
+ download: "Download",
21
+ loading: "Loading image"
22
+ }, ke = 60, we = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M5 5l10 10M15 5L5 15" }) }), T = ({ dir: d }) => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: d === "left" ? /* @__PURE__ */ e("path", { d: "M12.5 4.5L7 10l5.5 5.5" }) : /* @__PURE__ */ e("path", { d: "M7.5 4.5L13 10l-5.5 5.5" }) }), Ne = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M10 3v10m0 0l-4-4m4 4l4-4M4 16h12" }) }), xe = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M4 10a6 6 0 1 1 1.8 4.3M4 15v-4h4" }) }), Le = () => /* @__PURE__ */ e("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ e("path", { d: "M3 8V3h5M12 3h5v5M17 12v5h-5M8 17H3v-5" }) }), Ie = de(
23
+ ({
24
+ open: d,
25
+ onClose: y,
26
+ items: m,
27
+ index: R,
28
+ defaultIndex: Z = 0,
29
+ onIndexChange: E,
30
+ loop: v = !0,
31
+ showCounter: H = !0,
32
+ showThumbnails: U = !1,
33
+ showZoomControls: V = !0,
34
+ showDownload: $,
35
+ renderSlide: D,
36
+ closeOnBackdrop: _ = !0,
37
+ zoom: X,
38
+ labels: Y,
39
+ classes: l,
40
+ className: K,
41
+ style: q
42
+ }, b) => {
43
+ const u = { ...ye, ...Y }, n = m.length, k = R !== void 0, [G, J] = O(Z), a = n === 0 ? 0 : Math.min(Math.max(0, k ? R : G), n - 1), s = m[a], B = C(null), Q = (o) => {
44
+ B.current = o, typeof b == "function" ? b(o) : b && (b.current = o);
45
+ }, i = ge(X), { reset: S, scale: j, isPanning: ee } = i, p = P(
46
+ (o) => {
47
+ if (n === 0) return;
48
+ let r = o;
49
+ v ? r = (o % n + n) % n : r = Math.min(Math.max(0, o), n - 1), r !== a && (k || J(r), E?.(r));
50
+ },
51
+ [n, v, a, k, E]
52
+ ), w = v ? n > 1 : a > 0, N = v ? n > 1 : a < n - 1, x = P(() => w && p(a - 1), [w, p, a]), L = P(() => N && p(a + 1), [N, p, a]), [A, I] = O(!1);
53
+ z(() => {
54
+ I(!1), S();
55
+ }, [a, s?.src, S]), z(() => {
56
+ if (!d || n < 2 || typeof Image > "u") return;
57
+ const o = [m[(a + 1) % n], m[(a - 1 + n) % n]];
58
+ for (const r of o) {
59
+ if (!r) continue;
60
+ const h = new Image();
61
+ h.src = r.src;
62
+ }
63
+ }, [d, a, m, n]), he(B, d);
64
+ const te = fe(() => y(), d);
65
+ z(() => {
66
+ if (!d) return;
67
+ const o = document.body.style.overflow;
68
+ return document.body.style.overflow = "hidden", () => {
69
+ document.body.style.overflow = o;
70
+ };
71
+ }, [d]), ve(
72
+ {
73
+ ArrowLeft: x,
74
+ ArrowRight: L,
75
+ "+": i.zoomIn,
76
+ "=": i.zoomIn,
77
+ "-": i.zoomOut,
78
+ 0: i.reset
79
+ },
80
+ { active: d, ignoreEditable: !0 }
81
+ );
82
+ const M = C(null), g = C(!1), oe = (o) => {
83
+ M.current = { x: o.clientX ?? 0, y: o.clientY ?? 0 }, g.current = !1, i.stageProps.onPointerDown(o);
84
+ }, ne = (o) => {
85
+ i.stageProps.onPointerUp(o);
86
+ const r = M.current;
87
+ if (M.current = null, !r) return;
88
+ const h = (o.clientX ?? 0) - r.x, F = (o.clientY ?? 0) - r.y;
89
+ Math.hypot(h, F) >= 5 && (g.current = !0), j === 1 && Math.abs(h) > ke && Math.abs(h) > Math.abs(F) && (h < 0 ? L() : x());
90
+ }, re = (o) => {
91
+ const r = g.current;
92
+ g.current = !1, !(!_ || r) && o.target === o.currentTarget && y();
93
+ }, ae = ue();
94
+ if (!d || n === 0 || !s) return null;
95
+ const ie = $ ?? !!s.download, le = typeof s.download == "string" ? s.download : s.src, W = D ? D(s, { index: a, active: !0 }) : null, se = `${Math.round(j * 100)}%`;
96
+ return me(
97
+ /* @__PURE__ */ e(
98
+ "div",
99
+ {
100
+ ref: Q,
101
+ className: c(t.root, l?.root, K),
102
+ style: q,
103
+ role: "dialog",
104
+ "aria-modal": "true",
105
+ "aria-label": s.alt || u.viewer,
106
+ "data-index": a,
107
+ children: /* @__PURE__ */ f(pe, { value: te, children: [
108
+ /* @__PURE__ */ e("div", { className: c(t.backdrop, l?.backdrop), "aria-hidden": "true" }),
109
+ /* @__PURE__ */ f("div", { className: c(t.toolbar, l?.toolbar), children: [
110
+ H && n > 1 && /* @__PURE__ */ f("span", { className: c(t.counter, l?.counter), "aria-live": "polite", children: [
111
+ a + 1,
112
+ " / ",
113
+ n
114
+ ] }),
115
+ /* @__PURE__ */ e("span", { className: t.spacer }),
116
+ V && /* @__PURE__ */ f("div", { className: c(t.zoomControls, l?.zoomControls), role: "group", "aria-label": "Zoom", children: [
117
+ /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.zoomOut, "aria-label": u.zoomOut, children: "−" }),
118
+ /* @__PURE__ */ e("span", { className: t.zoomValue, "data-testid": "zoom-value", children: se }),
119
+ /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.zoomIn, "aria-label": u.zoomIn, children: "+" }),
120
+ /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.reset, "aria-label": u.reset, children: /* @__PURE__ */ e(xe, {}) }),
121
+ /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: i.fit, "aria-label": u.fit, children: /* @__PURE__ */ e(Le, {}) })
122
+ ] }),
123
+ ie && /* @__PURE__ */ e("a", { className: t.control, href: le, download: !0, "aria-label": u.download, target: "_blank", rel: "noreferrer", children: /* @__PURE__ */ e(Ne, {}) }),
124
+ /* @__PURE__ */ e("button", { type: "button", className: t.control, onClick: y, "aria-label": u.close, children: /* @__PURE__ */ e(we, {}) })
125
+ ] }),
126
+ /* @__PURE__ */ f("div", { className: t.body, children: [
127
+ n > 1 && w && /* @__PURE__ */ e(
128
+ "button",
129
+ {
130
+ type: "button",
131
+ className: c(t.nav, t.navPrev, l?.nav, l?.navPrev),
132
+ onClick: x,
133
+ "aria-label": u.previous,
134
+ children: /* @__PURE__ */ e(T, { dir: "left" })
135
+ }
136
+ ),
137
+ /* @__PURE__ */ e(
138
+ "div",
139
+ {
140
+ className: c(t.stage, ee && t.panning, l?.stage),
141
+ ...i.stageProps,
142
+ onPointerDown: oe,
143
+ onPointerUp: ne,
144
+ onClick: re,
145
+ style: i.stageProps.style,
146
+ "data-testid": "image-viewer-stage",
147
+ children: W ? /* @__PURE__ */ e("div", { ref: i.contentRef, className: c(t.image, l?.image), style: i.contentStyle, children: W }) : /* @__PURE__ */ f(ce, { children: [
148
+ /* @__PURE__ */ e(
149
+ "img",
150
+ {
151
+ ref: i.contentRef,
152
+ className: c(t.image, !A && t.imageLoading, l?.image),
153
+ style: i.contentStyle,
154
+ src: s.src,
155
+ alt: s.alt ?? "",
156
+ draggable: !1,
157
+ onLoad: () => I(!0),
158
+ onError: () => I(!0)
159
+ },
160
+ s.src
161
+ ),
162
+ !A && /* @__PURE__ */ e("span", { className: t.spinner, children: /* @__PURE__ */ e(be, { size: "lg", label: u.loading }) })
163
+ ] })
164
+ }
165
+ ),
166
+ n > 1 && N && /* @__PURE__ */ e(
167
+ "button",
168
+ {
169
+ type: "button",
170
+ className: c(t.nav, t.navNext, l?.nav, l?.navNext),
171
+ onClick: L,
172
+ "aria-label": u.next,
173
+ children: /* @__PURE__ */ e(T, { dir: "right" })
174
+ }
175
+ )
176
+ ] }),
177
+ s.caption && /* @__PURE__ */ e("div", { id: ae, className: c(t.caption, l?.caption), children: s.caption }),
178
+ U && n > 1 && /* @__PURE__ */ e("div", { className: c(t.thumbnails, l?.thumbnails), role: "list", children: m.map((o, r) => /* @__PURE__ */ e(
179
+ "button",
180
+ {
181
+ type: "button",
182
+ role: "listitem",
183
+ className: c(t.thumbnail, r === a && t.thumbnailActive, l?.thumbnail, r === a && l?.thumbnailActive),
184
+ onClick: () => p(r),
185
+ "aria-label": o.alt || `${r + 1}`,
186
+ "aria-current": r === a ? "true" : void 0,
187
+ children: /* @__PURE__ */ e("img", { src: o.thumbnail ?? o.src, alt: "", draggable: !1 })
188
+ },
189
+ `${o.src}-${r}`
190
+ )) })
191
+ ] })
192
+ }
193
+ ),
194
+ document.body
195
+ );
196
+ }
197
+ );
198
+ Ie.displayName = "ImageViewer";
199
+ export {
200
+ Ie as ImageViewer
201
+ };
@@ -0,0 +1,47 @@
1
+ const o = "crk-root-ONPec", n = "crk-backdrop-zT-Q5", c = "crk-toolbar-AnTEv", t = "crk-spacer-w02Ek", a = "crk-counter-VTMp2", r = "crk-zoomControls-7H0yp", s = "crk-zoomValue-SJmdu", e = "crk-control-PyHnZ", i = "crk-body-OJK4N", k = "crk-stage-e0AOa", m = "crk-image-m6tek", l = "crk-panning-KHk5X", b = "crk-imageLoading-jrFiP", p = "crk-spinner-eg9--", u = "crk-nav-Bejfo", v = "crk-navPrev-GAvIZ", g = "crk-navNext-Ly2YK", d = "crk-caption-25w3Q", h = "crk-thumbnails-JZb4b", z = "crk-thumbnail-hzBpT", y = "crk-thumbnailActive-Pfwmf", P = {
2
+ root: o,
3
+ backdrop: n,
4
+ toolbar: c,
5
+ spacer: t,
6
+ counter: a,
7
+ zoomControls: r,
8
+ zoomValue: s,
9
+ control: e,
10
+ body: i,
11
+ stage: k,
12
+ image: m,
13
+ panning: l,
14
+ imageLoading: b,
15
+ spinner: p,
16
+ nav: u,
17
+ navPrev: v,
18
+ navNext: g,
19
+ caption: d,
20
+ thumbnails: h,
21
+ thumbnail: z,
22
+ thumbnailActive: y
23
+ };
24
+ export {
25
+ n as backdrop,
26
+ i as body,
27
+ d as caption,
28
+ e as control,
29
+ a as counter,
30
+ P as default,
31
+ m as image,
32
+ b as imageLoading,
33
+ u as nav,
34
+ g as navNext,
35
+ v as navPrev,
36
+ l as panning,
37
+ o as root,
38
+ t as spacer,
39
+ p as spinner,
40
+ k as stage,
41
+ z as thumbnail,
42
+ y as thumbnailActive,
43
+ h as thumbnails,
44
+ c as toolbar,
45
+ r as zoomControls,
46
+ s as zoomValue
47
+ };
@@ -0,0 +1,4 @@
1
+ export { ImageViewer } from './ImageViewer';
2
+ export type { ImageViewerProps, ImageViewerClasses, ImageViewerItem, ImageViewerLabels, ImageViewerSlideContext, } from './ImageViewer';
3
+ export { useZoomPan } from './useZoomPan';
4
+ export type { UseZoomPanOptions, UseZoomPanResult, ZoomPanState, ZoomPanStageProps } from './useZoomPan';