@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
@@ -1,131 +1,224 @@
1
- import { jsx as d, jsxs as p } from "react/jsx-runtime";
2
- import { forwardRef as J, useState as K, useRef as v, useId as Q, useEffect as S, useCallback as b } from "react";
3
- import { createPortal as T } from "react-dom";
4
- import o from "clsx";
1
+ import { jsx as u, jsxs as v } from "react/jsx-runtime";
2
+ import { forwardRef as me, useState as $, useRef as E, useId as fe, useCallback as y, useEffect as ee, useLayoutEffect as he } from "react";
3
+ import { createPortal as te } from "react-dom";
4
+ import l from "clsx";
5
5
  import t from "./Dropdown.module.scss.js";
6
- import { useEscapeLayer as U, EscapeLayerProvider as V } from "../../hooks/useEscapeLayer.js";
7
- import { usePortalPosition as X } from "../../hooks/usePortalPosition.js";
8
- const Y = J(
6
+ import { useEscapeLayer as ge, EscapeLayerProvider as pe } from "../../hooks/useEscapeLayer.js";
7
+ import { usePortalPosition as ve } from "../../hooks/usePortalPosition.js";
8
+ import { DropdownMenuContext as ye } from "./dropdownContext.js";
9
+ const ne = '[role="menuitem"]:not(:disabled), [role="menuitemcheckbox"]:not(:disabled)', g = 8, we = me(
9
10
  ({
10
- trigger: k,
11
- children: D,
12
- align: g = "left",
13
- className: j,
14
- style: z,
15
- id: O,
16
- onOpen: y,
17
- onClose: s,
18
- options: i,
19
- placeholder: W = "Select...",
20
- value: L,
21
- onChange: w,
11
+ trigger: A,
12
+ children: re,
13
+ align: L = "left",
14
+ className: O,
15
+ style: K,
16
+ id: W,
17
+ onOpen: z,
18
+ onClose: T,
19
+ options: f,
20
+ placeholder: oe = "Select...",
21
+ value: H,
22
+ onChange: j,
22
23
  error: q = !1,
23
24
  fullWidth: a = !0,
24
- portal: u = !0,
25
- classes: n
26
- }, M) => {
27
- const [r, x] = K(!1), E = v(null), m = v(null), h = v(null), N = Q();
28
- S(() => {
29
- r && m.current && m.current.querySelector('[role="menuitem"]:not(:disabled)')?.focus();
30
- }, [r]);
31
- const c = b(() => {
32
- x(!1), s?.(), h.current?.focus();
33
- }, [s]), A = b(() => {
34
- x((e) => {
35
- const f = !e;
36
- return f ? y?.() : s?.(), f;
37
- });
38
- }, [y, s]), B = b(
25
+ portal: w = !0,
26
+ open: B,
27
+ onOpenChange: _,
28
+ anchor: o,
29
+ classes: i
30
+ }, G) => {
31
+ const [ie, ce] = $(!1), D = B !== void 0, n = D ? B : ie, M = E(n);
32
+ M.current = n;
33
+ const k = E(null), s = E(null), b = E(null), I = fe(), N = o !== void 0, U = N && o !== null, V = !!f || A !== void 0 || !N, x = y(
39
34
  (e) => {
40
- w?.(e), c();
35
+ e !== M.current && (D || ce(e), _?.(e), e ? z?.() : T?.());
41
36
  },
42
- [w, c]
37
+ [D, _, z, T]
43
38
  );
44
- S(() => {
45
- if (!r) return;
46
- const e = (f) => {
47
- const R = f.target;
48
- E.current?.contains(R) || m.current?.contains(R) || c();
39
+ ee(() => {
40
+ n && s.current && s.current.querySelector(ne)?.focus();
41
+ }, [n]);
42
+ const h = y(() => {
43
+ x(!1), b.current?.focus();
44
+ }, [x]), F = y(() => {
45
+ x(!M.current);
46
+ }, [x]), le = y((e) => {
47
+ const m = s.current;
48
+ if (!m) return;
49
+ const r = Array.from(m.querySelectorAll(ne));
50
+ if (r.length === 0) return;
51
+ const d = r.indexOf(document.activeElement), c = (P) => {
52
+ r[(P + r.length) % r.length]?.focus();
53
+ };
54
+ switch (e.key) {
55
+ case "ArrowDown":
56
+ e.preventDefault(), c(d + 1);
57
+ return;
58
+ case "ArrowUp":
59
+ e.preventDefault(), c(d - 1);
60
+ return;
61
+ case "Home":
62
+ e.preventDefault(), c(0);
63
+ return;
64
+ case "End":
65
+ e.preventDefault(), c(r.length - 1);
66
+ return;
67
+ }
68
+ if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && e.key !== " ") {
69
+ const P = e.key.toLowerCase();
70
+ for (let S = 1; S <= r.length; S++) {
71
+ const Z = r[(d + S) % r.length];
72
+ if ((Z.textContent ?? "").trim().toLowerCase().startsWith(P)) {
73
+ e.preventDefault(), Z.focus();
74
+ return;
75
+ }
76
+ }
77
+ }
78
+ }, []), [R, J] = $(null);
79
+ he(() => {
80
+ if (!n || !o || !s.current || typeof window > "u") {
81
+ J(null);
82
+ return;
83
+ }
84
+ const e = s.current.getBoundingClientRect(), m = document.documentElement.clientWidth || window.innerWidth, r = document.documentElement.clientHeight || window.innerHeight;
85
+ let d = o.x, c = o.y;
86
+ d + e.width > m - g && (d = o.x - e.width), c + e.height > r - g && (c = o.y - e.height), d = Math.max(g, Math.min(d, m - g - e.width)), c = Math.max(g, Math.min(c, r - g - e.height)), J({ top: Math.round(c), left: Math.round(d) });
87
+ }, [n, o?.x, o?.y]);
88
+ const de = y(
89
+ (e) => {
90
+ j?.(e), h();
91
+ },
92
+ [j, h]
93
+ );
94
+ ee(() => {
95
+ if (!n) return;
96
+ const e = (m) => {
97
+ const r = m.target;
98
+ k.current?.contains(r) || s.current?.contains(r) || h();
49
99
  };
50
100
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
51
- }, [r, c]);
52
- const C = U(c, r), l = X(h, r && u), I = i?.find((e) => e.value === L)?.label, F = i ? I || W : k, G = i && !I, H = i ? i.map((e) => /* @__PURE__ */ d(
101
+ }, [n, h]);
102
+ const ue = ge(h, n), p = ve(b, n && w && !U), ae = { close: h }, Q = f?.find((e) => e.value === H)?.label, X = f ? Q || oe : A, Y = f && !Q, se = f ? f.map((e) => /* @__PURE__ */ u(
53
103
  "button",
54
104
  {
55
105
  type: "button",
56
106
  role: "menuitem",
57
- className: o(
107
+ className: l(
58
108
  t.item,
59
109
  e.disabled && t.itemDisabled,
60
- e.value === L && t.itemSelected,
61
- n?.item
110
+ e.value === H && t.itemSelected,
111
+ i?.item
62
112
  ),
63
113
  disabled: e.disabled,
64
- onClick: () => B(e.value),
114
+ onClick: () => de(e.value),
65
115
  children: e.label
66
116
  },
67
117
  e.value
68
- )) : D, P = (e) => /* @__PURE__ */ d(
118
+ )) : re, C = (e) => /* @__PURE__ */ u(
69
119
  "div",
70
120
  {
71
- ref: m,
72
- id: N,
73
- className: o(
121
+ ref: s,
122
+ id: I,
123
+ className: l(
74
124
  t.menu,
75
- r && t.menuOpen,
76
- g === "left" ? t.alignLeft : t.alignRight,
77
- !u && a && t.fullWidth,
78
- n?.menu
125
+ n && t.menuOpen,
126
+ L === "left" ? t.alignLeft : t.alignRight,
127
+ !w && a && t.fullWidth,
128
+ i?.menu
79
129
  ),
80
130
  style: e,
81
131
  role: "menu",
82
- children: /* @__PURE__ */ d(V, { value: C, children: H })
132
+ onKeyDown: le,
133
+ children: /* @__PURE__ */ u(pe, { value: ue, children: /* @__PURE__ */ u(ye.Provider, { value: ae, children: se }) })
83
134
  }
84
135
  );
85
- return /* @__PURE__ */ p(
136
+ return N ? /* @__PURE__ */ v(
137
+ "div",
138
+ {
139
+ ref: G,
140
+ className: l(t.root, V && a && t.fullWidth, i?.root, O),
141
+ style: K,
142
+ children: [
143
+ V && /* @__PURE__ */ u("div", { ref: k, style: a ? { width: "100%" } : void 0, children: /* @__PURE__ */ v(
144
+ "button",
145
+ {
146
+ ref: b,
147
+ id: W,
148
+ type: "button",
149
+ className: l(
150
+ t.trigger,
151
+ n && t.triggerOpen,
152
+ q && t.triggerError,
153
+ a && t.fullWidth,
154
+ i?.trigger
155
+ ),
156
+ onClick: F,
157
+ "aria-expanded": n,
158
+ "aria-haspopup": "menu",
159
+ "aria-controls": n ? I : void 0,
160
+ children: [
161
+ /* @__PURE__ */ u("span", { className: l(t.triggerLabel, Y && t.placeholder, i?.triggerLabel), children: X }),
162
+ /* @__PURE__ */ u("span", { className: l(t.chevron, i?.chevron), "aria-hidden": "true" })
163
+ ]
164
+ }
165
+ ) }),
166
+ n && U && typeof document < "u" && te(
167
+ C({
168
+ position: "fixed",
169
+ top: R?.top ?? o.y,
170
+ left: R?.left ?? o.x,
171
+ visibility: R ? void 0 : "hidden",
172
+ zIndex: "var(--crk-z-floating)"
173
+ }),
174
+ document.body
175
+ )
176
+ ]
177
+ }
178
+ ) : /* @__PURE__ */ v(
86
179
  "div",
87
180
  {
88
- ref: M,
89
- className: o(t.root, a && t.fullWidth, n?.root, j),
90
- style: z,
181
+ ref: G,
182
+ className: l(t.root, a && t.fullWidth, i?.root, O),
183
+ style: K,
91
184
  children: [
92
- /* @__PURE__ */ p("div", { ref: E, style: a ? { width: "100%" } : void 0, children: [
93
- /* @__PURE__ */ p(
185
+ /* @__PURE__ */ v("div", { ref: k, style: a ? { width: "100%" } : void 0, children: [
186
+ /* @__PURE__ */ v(
94
187
  "button",
95
188
  {
96
- ref: h,
97
- id: O,
189
+ ref: b,
190
+ id: W,
98
191
  type: "button",
99
- className: o(
192
+ className: l(
100
193
  t.trigger,
101
- r && t.triggerOpen,
194
+ n && t.triggerOpen,
102
195
  q && t.triggerError,
103
196
  a && t.fullWidth,
104
- n?.trigger
197
+ i?.trigger
105
198
  ),
106
- onClick: A,
107
- "aria-expanded": r,
199
+ onClick: F,
200
+ "aria-expanded": n,
108
201
  "aria-haspopup": "menu",
109
- "aria-controls": r ? N : void 0,
202
+ "aria-controls": n ? I : void 0,
110
203
  children: [
111
- /* @__PURE__ */ d("span", { className: o(t.triggerLabel, G && t.placeholder, n?.triggerLabel), children: F }),
112
- /* @__PURE__ */ d("span", { className: o(t.chevron, n?.chevron), "aria-hidden": "true" })
204
+ /* @__PURE__ */ u("span", { className: l(t.triggerLabel, Y && t.placeholder, i?.triggerLabel), children: X }),
205
+ /* @__PURE__ */ u("span", { className: l(t.chevron, i?.chevron), "aria-hidden": "true" })
113
206
  ]
114
207
  }
115
208
  ),
116
- !u && P()
209
+ !w && C()
117
210
  ] }),
118
- u && r && typeof document < "u" && T(
119
- P({
211
+ w && n && typeof document < "u" && te(
212
+ C({
120
213
  position: "fixed",
121
- top: l.top + 4,
122
- left: g === "right" ? void 0 : l.left,
214
+ top: p.top + 4,
215
+ left: L === "right" ? void 0 : p.left,
123
216
  // clientWidth, not innerWidth: `right` on a fixed element is
124
217
  // measured from the viewport edge inside the scrollbar, while
125
218
  // innerWidth includes it — the menu would shift left by the
126
219
  // scrollbar width whenever the page scrolls.
127
- right: g === "right" ? document.documentElement.clientWidth - (l.left + l.width) : void 0,
128
- minWidth: l.width,
220
+ right: L === "right" ? document.documentElement.clientWidth - (p.left + p.width) : void 0,
221
+ minWidth: p.width,
129
222
  zIndex: "var(--crk-z-floating)"
130
223
  }),
131
224
  document.body
@@ -135,7 +228,7 @@ const Y = J(
135
228
  );
136
229
  }
137
230
  );
138
- Y.displayName = "Dropdown";
231
+ we.displayName = "Dropdown";
139
232
  export {
140
- Y as Dropdown
233
+ we as Dropdown
141
234
  };
@@ -1,35 +1,53 @@
1
- const e = "crk-root-an8Cf", r = "crk-fullWidth-S-uVk", t = "crk-trigger-LwPaD", c = "crk-triggerOpen-U4pa9", n = "crk-triggerLabel-QLITs", i = "crk-triggerError-3jlu1", g = "crk-placeholder-fWdch", o = "crk-chevron-jmDNe", l = "crk-menu-fxnKL", s = "crk-menuOpen-HF-Y1", a = "crk-alignLeft-buCDJ", m = "crk-alignRight-05P9w", k = "crk-item-f-Rhh", d = "crk-itemDisabled-L-d6i", h = "crk-itemSelected-Fwmuo", u = {
1
+ const e = "crk-root-an8Cf", t = "crk-fullWidth-S-uVk", r = "crk-trigger-LwPaD", c = "crk-triggerOpen-U4pa9", i = "crk-triggerLabel-QLITs", n = "crk-triggerError-3jlu1", o = "crk-placeholder-fWdch", l = "crk-chevron-jmDNe", m = "crk-menu-fxnKL", s = "crk-menuOpen-HF-Y1", a = "crk-alignLeft-buCDJ", g = "crk-alignRight-05P9w", k = "crk-item-f-Rhh", h = "crk-itemDisabled-L-d6i", d = "crk-itemSelected-Fwmuo", p = "crk-itemDanger-b1A4e", u = "crk-itemChecked-xY5Cf", b = "crk-itemCheck-IZYaJ", f = "crk-itemIcon-3Gh8c", D = "crk-itemLabel-YdjzN", L = "crk-itemDescription-eM-fw", C = "crk-itemShortcut-33qnD", S = "crk-separator-C0jdb", O = "crk-label-Rd7NT", I = {
2
2
  root: e,
3
- fullWidth: r,
4
- trigger: t,
3
+ fullWidth: t,
4
+ trigger: r,
5
5
  triggerOpen: c,
6
- triggerLabel: n,
7
- triggerError: i,
8
- placeholder: g,
9
- chevron: o,
10
- menu: l,
6
+ triggerLabel: i,
7
+ triggerError: n,
8
+ placeholder: o,
9
+ chevron: l,
10
+ menu: m,
11
11
  menuOpen: s,
12
12
  alignLeft: a,
13
- alignRight: m,
13
+ alignRight: g,
14
14
  item: k,
15
- itemDisabled: d,
16
- itemSelected: h
15
+ itemDisabled: h,
16
+ itemSelected: d,
17
+ itemDanger: p,
18
+ itemChecked: u,
19
+ itemCheck: b,
20
+ itemIcon: f,
21
+ itemLabel: D,
22
+ itemDescription: L,
23
+ itemShortcut: C,
24
+ separator: S,
25
+ label: O
17
26
  };
18
27
  export {
19
28
  a as alignLeft,
20
- m as alignRight,
21
- o as chevron,
22
- u as default,
23
- r as fullWidth,
29
+ g as alignRight,
30
+ l as chevron,
31
+ I as default,
32
+ t as fullWidth,
24
33
  k as item,
25
- d as itemDisabled,
26
- h as itemSelected,
27
- l as menu,
34
+ b as itemCheck,
35
+ u as itemChecked,
36
+ p as itemDanger,
37
+ L as itemDescription,
38
+ h as itemDisabled,
39
+ f as itemIcon,
40
+ D as itemLabel,
41
+ d as itemSelected,
42
+ C as itemShortcut,
43
+ O as label,
44
+ m as menu,
28
45
  s as menuOpen,
29
- g as placeholder,
46
+ o as placeholder,
30
47
  e as root,
31
- t as trigger,
32
- i as triggerError,
33
- n as triggerLabel,
48
+ S as separator,
49
+ r as trigger,
50
+ n as triggerError,
51
+ i as triggerLabel,
34
52
  c as triggerOpen
35
53
  };
@@ -1,10 +1,39 @@
1
- import { ComponentPropsWithRef } from 'react';
1
+ import { ComponentPropsWithRef, ReactNode } from 'react';
2
+ import { DropdownClasses } from './Dropdown';
3
+ export type DropdownItemClasses = Partial<Pick<DropdownClasses, 'item' | 'itemIcon' | 'itemLabel' | 'itemDescription' | 'itemShortcut' | 'itemCheck'>>;
2
4
  export interface DropdownItemProps extends ComponentPropsWithRef<'button'> {
3
5
  /** Non-interactive when true. @default false */
4
6
  disabled?: boolean;
7
+ /** Destructive action styling (danger text, danger-light hover). @default false */
8
+ danger?: boolean;
9
+ /** Leading icon slot (fixed width, `aria-hidden`). */
10
+ icon?: ReactNode;
11
+ /** Trailing shortcut hint, e.g. `<Kbd keys={['⌘', 'D']} />`. Hidden from the accessible name. */
12
+ shortcut?: ReactNode;
13
+ /**
14
+ * Makes the item checkable: renders `role="menuitemcheckbox"` with
15
+ * `aria-checked` and a leading check-mark slot that keeps alignment when
16
+ * unchecked. `undefined` = a plain action item.
17
+ */
18
+ checked?: boolean;
19
+ /** Second, muted line under the label. */
20
+ description?: ReactNode;
21
+ /**
22
+ * Close the menu after `onClick` (unless the click was `preventDefault()`ed).
23
+ * @default true for action items, false for checkable items
24
+ */
25
+ closeOnSelect?: boolean;
26
+ /** Override class names on internal elements. */
27
+ classes?: DropdownItemClasses;
5
28
  }
6
29
  /**
7
30
  * Action item rendered inside a `<Dropdown>` (menu mode).
8
- * Renders as a `<button role="menuitem">`; supports all native button props.
31
+ * Renders as a `<button role="menuitem">` (or `menuitemcheckbox` when
32
+ * `checked` is set); supports all native button props.
33
+ *
34
+ * @example
35
+ * <DropdownItem icon={<TrashIcon />} shortcut={<Kbd keys={['⌘', '⌫']} />} danger onClick={remove}>
36
+ * Delete
37
+ * </DropdownItem>
9
38
  */
10
39
  export declare const DropdownItem: import('react').ForwardRefExoticComponent<Omit<DropdownItemProps, "ref"> & import('react').RefAttributes<HTMLButtonElement>>;
@@ -1,31 +1,58 @@
1
- import { jsx as s } from "react/jsx-runtime";
2
- import { forwardRef as i } from "react";
3
- import f from "clsx";
4
- import t from "./Dropdown.module.scss.js";
5
- const n = i(
1
+ import { jsxs as c, jsx as i } from "react/jsx-runtime";
2
+ import { forwardRef as N, useContext as b } from "react";
3
+ import o from "clsx";
4
+ import e from "./Dropdown.module.scss.js";
5
+ import { DropdownMenuContext as w } from "./dropdownContext.js";
6
+ const I = N(
6
7
  ({
7
- disabled: o = !1,
8
- className: m,
9
- children: r,
10
- ...e
11
- }, p) => /* @__PURE__ */ s(
12
- "button",
13
- {
14
- ref: p,
15
- type: "button",
16
- role: "menuitem",
17
- className: f(
18
- t.item,
19
- o && t.itemDisabled,
20
- m
21
- ),
22
- disabled: o,
23
- ...e,
24
- children: r
25
- }
26
- )
8
+ disabled: d = !1,
9
+ danger: u = !1,
10
+ icon: m,
11
+ shortcut: a,
12
+ checked: r,
13
+ description: l,
14
+ closeOnSelect: p,
15
+ classes: t,
16
+ className: h,
17
+ children: f,
18
+ onClick: k,
19
+ ...v
20
+ }, x) => {
21
+ const C = b(w), n = r !== void 0, D = p ?? !n;
22
+ return /* @__PURE__ */ c(
23
+ "button",
24
+ {
25
+ ref: x,
26
+ type: "button",
27
+ role: n ? "menuitemcheckbox" : "menuitem",
28
+ "aria-checked": n ? r : void 0,
29
+ className: o(
30
+ e.item,
31
+ d && e.itemDisabled,
32
+ u && e.itemDanger,
33
+ n && r && e.itemChecked,
34
+ t?.item,
35
+ h
36
+ ),
37
+ disabled: d,
38
+ onClick: (s) => {
39
+ k?.(s), D && !s.defaultPrevented && C?.close();
40
+ },
41
+ ...v,
42
+ children: [
43
+ n && /* @__PURE__ */ i("span", { className: o(e.itemCheck, t?.itemCheck), "aria-hidden": "true", children: r && /* @__PURE__ */ i("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ i("path", { d: "M3 8.5l3 3 7-7" }) }) }),
44
+ m != null && /* @__PURE__ */ i("span", { className: o(e.itemIcon, t?.itemIcon), "aria-hidden": "true", children: m }),
45
+ /* @__PURE__ */ c("span", { className: o(e.itemLabel, t?.itemLabel), children: [
46
+ f,
47
+ l != null && /* @__PURE__ */ i("span", { className: o(e.itemDescription, t?.itemDescription), children: l })
48
+ ] }),
49
+ a != null && /* @__PURE__ */ i("span", { className: o(e.itemShortcut, t?.itemShortcut), "aria-hidden": "true", children: a })
50
+ ]
51
+ }
52
+ );
53
+ }
27
54
  );
28
- n.displayName = "DropdownItem";
55
+ I.displayName = "DropdownItem";
29
56
  export {
30
- n as DropdownItem
57
+ I as DropdownItem
31
58
  };
@@ -0,0 +1,11 @@
1
+ import { ComponentPropsWithRef } from 'react';
2
+ export type DropdownLabelProps = ComponentPropsWithRef<'div'>;
3
+ /**
4
+ * Non-interactive section heading inside a `<Dropdown>` menu
5
+ * (small, uppercase, muted). Skipped by keyboard navigation.
6
+ *
7
+ * @example
8
+ * <DropdownLabel>View</DropdownLabel>
9
+ * <DropdownItem checked={grid} onClick={toggleGrid}>Grid</DropdownItem>
10
+ */
11
+ export declare const DropdownLabel: import('react').ForwardRefExoticComponent<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,11 @@
1
+ import { jsx as a } from "react/jsx-runtime";
2
+ import { forwardRef as l } from "react";
3
+ import p from "clsx";
4
+ import s from "./Dropdown.module.scss.js";
5
+ const t = l(
6
+ ({ className: o, children: r, ...e }, m) => /* @__PURE__ */ a("div", { ref: m, role: "presentation", className: p(s.label, o), ...e, children: r })
7
+ );
8
+ t.displayName = "DropdownLabel";
9
+ export {
10
+ t as DropdownLabel
11
+ };
@@ -0,0 +1,12 @@
1
+ import { ComponentPropsWithRef } from 'react';
2
+ export type DropdownSeparatorProps = ComponentPropsWithRef<'div'>;
3
+ /**
4
+ * Hairline between groups of items inside a `<Dropdown>` menu.
5
+ * Skipped by keyboard navigation.
6
+ *
7
+ * @example
8
+ * <DropdownItem>Rename</DropdownItem>
9
+ * <DropdownSeparator />
10
+ * <DropdownItem danger>Delete</DropdownItem>
11
+ */
12
+ export declare const DropdownSeparator: import('react').ForwardRefExoticComponent<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,11 @@
1
+ import { jsx as p } from "react/jsx-runtime";
2
+ import { forwardRef as t } from "react";
3
+ import e from "clsx";
4
+ import m from "./Dropdown.module.scss.js";
5
+ const s = t(
6
+ ({ className: r, ...o }, a) => /* @__PURE__ */ p("div", { ref: a, role: "separator", className: e(m.separator, r), ...o })
7
+ );
8
+ s.displayName = "DropdownSeparator";
9
+ export {
10
+ s as DropdownSeparator
11
+ };
@@ -0,0 +1,6 @@
1
+ export interface DropdownMenuContextValue {
2
+ /** Close the enclosing menu (after an item was activated). */
3
+ close: () => void;
4
+ }
5
+ /** Provided by `Dropdown` around its menu so items can close it on activation. */
6
+ export declare const DropdownMenuContext: import('react').Context<DropdownMenuContextValue | null>;
@@ -0,0 +1,5 @@
1
+ import { createContext as o } from "react";
2
+ const e = o(null);
3
+ export {
4
+ e as DropdownMenuContext
5
+ };
@@ -1,4 +1,10 @@
1
1
  export { Dropdown } from './Dropdown';
2
- export type { DropdownProps, DropdownClasses, DropdownOption } from './Dropdown';
2
+ export type { DropdownProps, DropdownClasses, DropdownOption, DropdownAnchor } from './Dropdown';
3
3
  export { DropdownItem } from './DropdownItem';
4
- export type { DropdownItemProps } from './DropdownItem';
4
+ export type { DropdownItemProps, DropdownItemClasses } from './DropdownItem';
5
+ export { DropdownSeparator } from './DropdownSeparator';
6
+ export type { DropdownSeparatorProps } from './DropdownSeparator';
7
+ export { DropdownLabel } from './DropdownLabel';
8
+ export type { DropdownLabelProps } from './DropdownLabel';
9
+ export { useContextMenu } from './useContextMenu';
10
+ export type { UseContextMenuResult, ContextMenuAnchor } from './useContextMenu';
@@ -0,0 +1,32 @@
1
+ import { MouseEvent as ReactMouseEvent } from 'react';
2
+ export interface ContextMenuAnchor {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export interface UseContextMenuResult {
7
+ /** Viewport point to pass as `Dropdown`'s `anchor`. */
8
+ anchor: ContextMenuAnchor | null;
9
+ /** Pass as `Dropdown`'s `open`. */
10
+ open: boolean;
11
+ /** Pass as `Dropdown`'s `onOpenChange`. */
12
+ onOpenChange: (open: boolean) => void;
13
+ /** Attach to the element's `onContextMenu`: prevents the native menu and opens at the pointer. */
14
+ onContextMenu: (e: ReactMouseEvent) => void;
15
+ /** Open programmatically at a viewport point. */
16
+ openAt: (point: ContextMenuAnchor) => void;
17
+ /** Close the menu. */
18
+ close: () => void;
19
+ }
20
+ /**
21
+ * State helper for a right-click menu built on `<Dropdown anchor>`.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * const menu = useContextMenu();
26
+ * <div onContextMenu={menu.onContextMenu}>Right-click me</div>
27
+ * <Dropdown anchor={menu.anchor} open={menu.open} onOpenChange={menu.onOpenChange}>
28
+ * <DropdownItem onClick={rename}>Rename</DropdownItem>
29
+ * </Dropdown>
30
+ * ```
31
+ */
32
+ export declare function useContextMenu(): UseContextMenuResult;
@@ -0,0 +1,18 @@
1
+ import { useState as a, useCallback as t, useMemo as f } from "react";
2
+ function x() {
3
+ const [s, p] = a(null), [c, o] = a(!1), n = t((e) => {
4
+ p(e), o(!0);
5
+ }, []), u = t(
6
+ (e) => {
7
+ e.preventDefault(), n({ x: e.clientX, y: e.clientY });
8
+ },
9
+ [n]
10
+ ), l = t(() => o(!1), []), r = t((e) => o(e), []);
11
+ return f(
12
+ () => ({ anchor: s, open: c, onOpenChange: r, onContextMenu: u, openAt: n, close: l }),
13
+ [s, c, r, u, n, l]
14
+ );
15
+ }
16
+ export {
17
+ x as useContextMenu
18
+ };