@overdoser/react-toolkit 0.20.0 → 0.21.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 (273) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/components/Accordion/Accordion.js +160 -177
  4. package/components/Accordion/Accordion.module.js +20 -0
  5. package/components/ActionButton/ActionButton.js +155 -209
  6. package/components/ActionButton/ActionButton.module.js +25 -0
  7. package/components/ActionButton/CopyButton.js +52 -64
  8. package/components/Alert/Alert.js +92 -95
  9. package/components/Alert/Alert.module.js +18 -0
  10. package/components/Avatar/Avatar.js +44 -55
  11. package/components/Avatar/Avatar.module.js +23 -0
  12. package/components/Badge/Badge.js +16 -38
  13. package/components/Badge/Badge.module.js +17 -0
  14. package/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
  15. package/components/Breadcrumbs/Breadcrumbs.js +52 -48
  16. package/components/Breadcrumbs/Breadcrumbs.module.js +10 -0
  17. package/components/Button/Button.js +35 -57
  18. package/components/Button/Button.module.js +25 -0
  19. package/components/Card/Card.js +94 -131
  20. package/components/Card/Card.module.js +35 -0
  21. package/components/Chart/AreaChart.d.ts +1 -1
  22. package/components/Chart/AreaChart.js +248 -249
  23. package/components/Chart/Axis.d.ts +2 -2
  24. package/components/Chart/Axis.js +34 -43
  25. package/components/Chart/BarChart.d.ts +1 -1
  26. package/components/Chart/BarChart.js +307 -348
  27. package/components/Chart/Chart.module.js +32 -0
  28. package/components/Chart/ChartContainer.js +33 -41
  29. package/components/Chart/ChartLegend.d.ts +1 -1
  30. package/components/Chart/ChartLegend.js +31 -30
  31. package/components/Chart/ChartTooltip.d.ts +1 -1
  32. package/components/Chart/ChartTooltip.js +46 -41
  33. package/components/Chart/LineChart.d.ts +1 -1
  34. package/components/Chart/LineChart.js +220 -232
  35. package/components/Chart/PieChart.d.ts +1 -1
  36. package/components/Chart/PieChart.js +224 -240
  37. package/components/Chart/RadarChart.d.ts +1 -1
  38. package/components/Chart/RadarChart.js +166 -215
  39. package/components/Chart/Sparkline.js +73 -68
  40. package/components/Chart/TradingChart.d.ts +1 -1
  41. package/components/Chart/TradingChart.js +804 -701
  42. package/components/Chart/scales.js +28 -35
  43. package/components/Chart/trading/indicators.js +61 -62
  44. package/components/Chart/trading/period.js +46 -68
  45. package/components/Chart/useChartDimensions.js +30 -22
  46. package/components/Chip/Chip.js +98 -141
  47. package/components/Chip/Chip.module.js +32 -0
  48. package/components/CodeBlock/CodeBlock.js +111 -119
  49. package/components/CodeBlock/CodeBlock.module.js +23 -0
  50. package/components/CommandPalette/CommandPalette.js +387 -392
  51. package/components/CommandPalette/CommandPalette.module.js +28 -0
  52. package/components/ConfirmDialog/ConfirmDialog.d.ts +1 -1
  53. package/components/ConfirmDialog/ConfirmDialog.js +184 -199
  54. package/components/ConfirmDialog/ConfirmDialog.module.js +12 -0
  55. package/components/Divider/Divider.js +25 -36
  56. package/components/Divider/Divider.module.js +17 -0
  57. package/components/Draggable/Draggable.d.ts +1 -1
  58. package/components/Draggable/Draggable.js +157 -164
  59. package/components/Draggable/Draggable.module.js +10 -0
  60. package/components/Drawer/Drawer.js +104 -126
  61. package/components/Drawer/Drawer.module.js +66 -0
  62. package/components/Dropdown/Dropdown.js +175 -234
  63. package/components/Dropdown/Dropdown.module.js +29 -0
  64. package/components/Dropdown/DropdownItem.js +55 -58
  65. package/components/Dropdown/DropdownLabel.js +14 -11
  66. package/components/Dropdown/DropdownSeparator.js +12 -10
  67. package/components/Dropdown/dropdownContext.js +4 -5
  68. package/components/Dropdown/useContextMenu.js +27 -17
  69. package/components/Dropzone/Dropzone.js +99 -105
  70. package/components/Dropzone/Dropzone.module.js +12 -0
  71. package/components/EmptyState/EmptyState.js +58 -55
  72. package/components/EmptyState/EmptyState.module.js +14 -0
  73. package/components/Form/Form.d.ts +1 -1
  74. package/components/Form/Form.js +32 -35
  75. package/components/Form/Form.module.js +16 -0
  76. package/components/Form/FormField.d.ts +1 -1
  77. package/components/Form/FormField.js +71 -75
  78. package/components/Form/FormRow.d.ts +1 -1
  79. package/components/Form/FormRow.js +11 -8
  80. package/components/Form/formFieldDefaults.js +4 -5
  81. package/components/ImageViewer/ImageViewer.js +312 -201
  82. package/components/ImageViewer/ImageViewer.module.js +26 -0
  83. package/components/ImageViewer/useZoomPan.js +206 -137
  84. package/components/Kbd/Kbd.js +25 -22
  85. package/components/Kbd/Kbd.module.js +10 -0
  86. package/components/KeyValueList/KeyValueList.js +119 -123
  87. package/components/KeyValueList/KeyValueList.module.js +23 -0
  88. package/components/Link/Link.js +45 -59
  89. package/components/Link/Link.module.js +10 -0
  90. package/components/List/List.js +22 -46
  91. package/components/List/List.module.js +12 -0
  92. package/components/Loader/Loader.js +152 -182
  93. package/components/Loader/Loader.module.js +40 -0
  94. package/components/Modal/Modal.js +93 -105
  95. package/components/Modal/Modal.module.js +18 -0
  96. package/components/PageHeader/PageHeader.js +78 -72
  97. package/components/PageHeader/PageHeader.module.js +23 -0
  98. package/components/Pagination/Pagination.js +63 -84
  99. package/components/Pagination/Pagination.module.js +13 -0
  100. package/components/Pagination/paginationRange.js +15 -22
  101. package/components/Popover/Popover.js +110 -134
  102. package/components/Popover/Popover.module.js +12 -0
  103. package/components/ProgressBar/ProgressBar.d.ts +15 -1
  104. package/components/ProgressBar/ProgressBar.js +57 -90
  105. package/components/ProgressBar/ProgressBar.module.js +29 -0
  106. package/components/RelativeTime/RelativeTime.js +36 -43
  107. package/components/RelativeTime/RelativeTime.module.js +3 -0
  108. package/components/SegmentedControl/SegmentedControl.js +94 -130
  109. package/components/SegmentedControl/SegmentedControl.module.js +21 -0
  110. package/components/Skeleton/Skeleton.js +36 -50
  111. package/components/Skeleton/Skeleton.module.js +15 -0
  112. package/components/Spinner/Spinner.js +25 -25
  113. package/components/Spinner/Spinner.module.js +12 -0
  114. package/components/SplitButton/SplitButton.js +149 -196
  115. package/components/SplitButton/SplitButton.module.js +31 -0
  116. package/components/SplitPane/SplitPane.js +134 -170
  117. package/components/SplitPane/SplitPane.module.js +14 -0
  118. package/components/StatCard/StatCard.js +132 -125
  119. package/components/StatCard/StatCard.module.js +42 -0
  120. package/components/StatusDot/StatusDot.js +28 -39
  121. package/components/StatusDot/StatusDot.module.js +18 -0
  122. package/components/Table/Table.d.ts +1 -1
  123. package/components/Table/Table.js +381 -451
  124. package/components/Table/Table.module.js +42 -0
  125. package/components/Table/useTableSort.js +51 -42
  126. package/components/Tabs/Tabs.js +109 -161
  127. package/components/Tabs/Tabs.module.js +28 -0
  128. package/components/ThemeToggle/ThemeToggle.js +122 -98
  129. package/components/ThemeToggle/ThemeToggle.module.js +13 -0
  130. package/components/Timeline/GanttTimeline.js +357 -318
  131. package/components/Timeline/GanttTimeline.module.js +29 -0
  132. package/components/Timeline/HistoryTimeline.js +486 -450
  133. package/components/Timeline/HistoryTimeline.module.js +31 -0
  134. package/components/Timeline/Timeline.module.js +76 -0
  135. package/components/Timeline/TimelineShared.d.ts +7 -7
  136. package/components/Timeline/TimelineShared.js +288 -279
  137. package/components/Timeline/TraceEventDetails.d.ts +3 -3
  138. package/components/Timeline/TraceEventDetails.js +245 -178
  139. package/components/Timeline/TraceTimeline.js +823 -783
  140. package/components/Timeline/TraceTimeline.module.js +98 -0
  141. package/components/Timeline/historyLayout.js +336 -263
  142. package/components/Timeline/timelineCore.js +208 -183
  143. package/components/Timeline/traceEvent.js +59 -61
  144. package/components/Timeline/traceLayout.js +101 -90
  145. package/components/Timeline/useTimeline.js +76 -79
  146. package/components/Timer/Timer.js +190 -156
  147. package/components/Timer/Timer.module.js +29 -0
  148. package/components/Toast/Toast.d.ts +1 -1
  149. package/components/Toast/Toast.js +128 -128
  150. package/components/Toast/Toast.module.js +37 -0
  151. package/components/Toast/toastStore.js +58 -62
  152. package/components/ToggleIconButton/ToggleIconButton.js +35 -57
  153. package/components/ToggleIconButton/ToggleIconButton.module.js +15 -0
  154. package/components/Tooltip/Tooltip.d.ts +1 -1
  155. package/components/Tooltip/Tooltip.js +76 -85
  156. package/components/Tooltip/Tooltip.module.js +17 -0
  157. package/components/Typography/Typography.js +11 -36
  158. package/components/Typography/Typography.module.js +30 -0
  159. package/components/inputs/Checkbox/Checkbox.js +27 -51
  160. package/components/inputs/Checkbox/Checkbox.module.js +10 -0
  161. package/components/inputs/Checkbox/CheckboxGroup.js +53 -111
  162. package/components/inputs/Checkbox/CheckboxGroup.module.js +17 -0
  163. package/components/inputs/DatePicker/CalendarPanel.d.ts +1 -1
  164. package/components/inputs/DatePicker/CalendarPanel.js +263 -286
  165. package/components/inputs/DatePicker/CalendarPanel.module.js +23 -0
  166. package/components/inputs/DatePicker/DatePicker.js +115 -142
  167. package/components/inputs/DatePicker/DatePicker.module.js +14 -0
  168. package/components/inputs/DatePicker/dateUtils.js +32 -41
  169. package/components/inputs/DateTimePicker/DateTimePicker.js +226 -232
  170. package/components/inputs/DateTimePicker/DateTimePicker.module.js +20 -0
  171. package/components/inputs/DateTimePicker/DateTimeSegments.js +273 -252
  172. package/components/inputs/DateTimePicker/TimeField.d.ts +1 -1
  173. package/components/inputs/DateTimePicker/TimeField.js +131 -132
  174. package/components/inputs/DateTimePicker/timeZoneUtils.js +95 -92
  175. package/components/inputs/Input/Input.js +98 -109
  176. package/components/inputs/Input/Input.module.js +15 -0
  177. package/components/inputs/NumberInput/NumberInput.js +112 -132
  178. package/components/inputs/NumberInput/NumberInput.module.js +14 -0
  179. package/components/inputs/Radio/Radio.js +50 -73
  180. package/components/inputs/Radio/Radio.module.js +9 -0
  181. package/components/inputs/SearchInput/SearchInput.js +98 -115
  182. package/components/inputs/SearchInput/SearchInput.module.js +8 -0
  183. package/components/inputs/Select/Select.js +555 -682
  184. package/components/inputs/Select/Select.module.js +38 -0
  185. package/components/inputs/Slider/Slider.js +97 -128
  186. package/components/inputs/Slider/Slider.module.js +9 -0
  187. package/components/inputs/Switch/Switch.js +11 -8
  188. package/components/inputs/Textarea/Textarea.js +42 -58
  189. package/components/inputs/Textarea/Textarea.module.js +14 -0
  190. package/hooks/useClickOutside.js +17 -14
  191. package/hooks/useDebouncedValue.js +13 -14
  192. package/hooks/useElementSize.js +27 -22
  193. package/hooks/useEscapeLayer.js +28 -29
  194. package/hooks/useFocusTrap.js +27 -38
  195. package/hooks/useKeyboard.js +76 -64
  196. package/hooks/useMediaQuery.js +10 -15
  197. package/hooks/useNow.js +28 -33
  198. package/hooks/usePersistedState.js +98 -94
  199. package/hooks/usePortalPosition.js +25 -19
  200. package/hooks/useResizable.js +106 -104
  201. package/hooks/useTheme.js +28 -23
  202. package/index.css +2 -1
  203. package/index.js +97 -215
  204. package/index.layered.css +2 -3
  205. package/llms.txt +3 -0
  206. package/manifest.json +8 -0
  207. package/package.json +1 -1
  208. package/utils/formatBytes.js +29 -13
  209. package/utils/themeScript.js +6 -8
  210. package/utils/timeAgo.js +59 -32
  211. package/components/Accordion/Accordion.module.scss.js +0 -36
  212. package/components/ActionButton/ActionButton.module.scss.js +0 -47
  213. package/components/Alert/Alert.module.scss.js +0 -33
  214. package/components/Avatar/Avatar.module.scss.js +0 -43
  215. package/components/Badge/Badge.module.scss.js +0 -31
  216. package/components/Breadcrumbs/Breadcrumbs.module.scss.js +0 -17
  217. package/components/Button/Button.module.scss.js +0 -47
  218. package/components/Card/Card.module.scss.js +0 -60
  219. package/components/Chart/Chart.module.scss.js +0 -61
  220. package/components/Chip/Chip.module.scss.js +0 -59
  221. package/components/CodeBlock/CodeBlock.module.scss.js +0 -43
  222. package/components/CommandPalette/CommandPalette.module.scss.js +0 -49
  223. package/components/ConfirmDialog/ConfirmDialog.module.scss.js +0 -21
  224. package/components/Divider/Divider.module.scss.js +0 -31
  225. package/components/Draggable/Draggable.module.scss.js +0 -17
  226. package/components/Drawer/Drawer.module.scss.js +0 -119
  227. package/components/Dropdown/Dropdown.module.scss.js +0 -53
  228. package/components/Dropzone/Dropzone.module.scss.js +0 -21
  229. package/components/EmptyState/EmptyState.module.scss.js +0 -25
  230. package/components/Form/Form.module.scss.js +0 -29
  231. package/components/ImageViewer/ImageViewer.module.scss.js +0 -47
  232. package/components/Kbd/Kbd.module.scss.js +0 -17
  233. package/components/KeyValueList/KeyValueList.module.scss.js +0 -43
  234. package/components/Link/Link.module.scss.js +0 -16
  235. package/components/List/List.module.scss.js +0 -21
  236. package/components/Loader/Loader.module.scss.js +0 -70
  237. package/components/Modal/Modal.module.scss.js +0 -33
  238. package/components/PageHeader/PageHeader.module.scss.js +0 -43
  239. package/components/Pagination/Pagination.module.scss.js +0 -23
  240. package/components/Popover/Popover.module.scss.js +0 -21
  241. package/components/ProgressBar/ProgressBar.module.scss.js +0 -51
  242. package/components/RelativeTime/RelativeTime.module.scss.js +0 -7
  243. package/components/SegmentedControl/SegmentedControl.module.scss.js +0 -39
  244. package/components/Skeleton/Skeleton.module.scss.js +0 -25
  245. package/components/Spinner/Spinner.module.scss.js +0 -20
  246. package/components/SplitButton/SplitButton.module.scss.js +0 -57
  247. package/components/SplitPane/SplitPane.module.scss.js +0 -25
  248. package/components/StatCard/StatCard.module.scss.js +0 -72
  249. package/components/StatusDot/StatusDot.module.scss.js +0 -32
  250. package/components/Table/Table.module.scss.js +0 -81
  251. package/components/Tabs/Tabs.module.scss.js +0 -53
  252. package/components/ThemeToggle/ThemeToggle.module.scss.js +0 -23
  253. package/components/Timeline/GanttTimeline.module.scss.js +0 -55
  254. package/components/Timeline/HistoryTimeline.module.scss.js +0 -59
  255. package/components/Timeline/Timeline.module.scss.js +0 -141
  256. package/components/Timeline/TraceTimeline.module.scss.js +0 -189
  257. package/components/Timer/Timer.module.scss.js +0 -55
  258. package/components/Toast/Toast.module.scss.js +0 -62
  259. package/components/ToggleIconButton/ToggleIconButton.module.scss.js +0 -27
  260. package/components/Tooltip/Tooltip.module.scss.js +0 -30
  261. package/components/Typography/Typography.module.scss.js +0 -53
  262. package/components/inputs/Checkbox/Checkbox.module.scss.js +0 -17
  263. package/components/inputs/Checkbox/CheckboxGroup.module.scss.js +0 -31
  264. package/components/inputs/DatePicker/CalendarPanel.module.scss.js +0 -41
  265. package/components/inputs/DatePicker/DatePicker.module.scss.js +0 -25
  266. package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +0 -37
  267. package/components/inputs/Input/Input.module.scss.js +0 -27
  268. package/components/inputs/NumberInput/NumberInput.module.scss.js +0 -25
  269. package/components/inputs/Radio/Radio.module.scss.js +0 -15
  270. package/components/inputs/SearchInput/SearchInput.module.scss.js +0 -13
  271. package/components/inputs/Select/Select.module.scss.js +0 -73
  272. package/components/inputs/Slider/Slider.module.scss.js +0 -15
  273. package/components/inputs/Textarea/Textarea.module.scss.js +0 -25
@@ -1,234 +1,175 @@
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
- import t from "./Dropdown.module.scss.js";
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(
10
- ({
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,
23
- error: q = !1,
24
- fullWidth: a = !0,
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(
34
- (e) => {
35
- e !== M.current && (D || ce(e), _?.(e), e ? z?.() : T?.());
36
- },
37
- [D, _, z, T]
38
- );
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();
99
- };
100
- return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
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(
103
- "button",
104
- {
105
- type: "button",
106
- role: "menuitem",
107
- className: l(
108
- t.item,
109
- e.disabled && t.itemDisabled,
110
- e.value === H && t.itemSelected,
111
- i?.item
112
- ),
113
- disabled: e.disabled,
114
- onClick: () => de(e.value),
115
- children: e.label
116
- },
117
- e.value
118
- )) : re, C = (e) => /* @__PURE__ */ u(
119
- "div",
120
- {
121
- ref: s,
122
- id: I,
123
- className: l(
124
- t.menu,
125
- n && t.menuOpen,
126
- L === "left" ? t.alignLeft : t.alignRight,
127
- !w && a && t.fullWidth,
128
- i?.menu
129
- ),
130
- style: e,
131
- role: "menu",
132
- onKeyDown: le,
133
- children: /* @__PURE__ */ u(pe, { value: ue, children: /* @__PURE__ */ u(ye.Provider, { value: ae, children: se }) })
134
- }
135
- );
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(
179
- "div",
180
- {
181
- ref: G,
182
- className: l(t.root, a && t.fullWidth, i?.root, O),
183
- style: K,
184
- children: [
185
- /* @__PURE__ */ v("div", { ref: k, style: a ? { width: "100%" } : void 0, children: [
186
- /* @__PURE__ */ v(
187
- "button",
188
- {
189
- ref: b,
190
- id: W,
191
- type: "button",
192
- className: l(
193
- t.trigger,
194
- n && t.triggerOpen,
195
- q && t.triggerError,
196
- a && t.fullWidth,
197
- i?.trigger
198
- ),
199
- onClick: F,
200
- "aria-expanded": n,
201
- "aria-haspopup": "menu",
202
- "aria-controls": n ? I : void 0,
203
- children: [
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" })
206
- ]
207
- }
208
- ),
209
- !w && C()
210
- ] }),
211
- w && n && typeof document < "u" && te(
212
- C({
213
- position: "fixed",
214
- top: p.top + 4,
215
- left: L === "right" ? void 0 : p.left,
216
- // clientWidth, not innerWidth: `right` on a fixed element is
217
- // measured from the viewport edge inside the scrollbar, while
218
- // innerWidth includes it — the menu would shift left by the
219
- // scrollbar width whenever the page scrolls.
220
- right: L === "right" ? document.documentElement.clientWidth - (p.left + p.width) : void 0,
221
- minWidth: p.width,
222
- zIndex: "var(--crk-z-floating)"
223
- }),
224
- document.body
225
- )
226
- ]
227
- }
228
- );
229
- }
230
- );
231
- we.displayName = "Dropdown";
232
- export {
233
- we as Dropdown
234
- };
1
+ import e from "./Dropdown.module.js";
2
+ import { EscapeLayerProvider as t, useEscapeLayer as n } from "../../hooks/useEscapeLayer.js";
3
+ import { usePortalPosition as r } from "../../hooks/usePortalPosition.js";
4
+ import { DropdownMenuContext as i } from "./dropdownContext.js";
5
+ import { forwardRef as a, useCallback as o, useEffect as s, useId as ee, useLayoutEffect as te, useRef as c, useState as l } from "react";
6
+ import u from "clsx";
7
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
8
+ import { createPortal as p } from "react-dom";
9
+ // src/components/Dropdown/Dropdown.tsx
10
+ var m = "[role=\"menuitem\"]:not(:disabled), [role=\"menuitemcheckbox\"]:not(:disabled)", h = 8, g = a(({ trigger: a, children: g, align: _ = "left", className: v, style: y, id: b, onOpen: x, onClose: S, options: C, placeholder: ne = "Select...", value: w, onChange: T, error: E = !1, fullWidth: D = !0, portal: O = !0, open: k, onOpenChange: A, anchor: j, classes: M }, N) => {
11
+ let [re, ie] = l(!1), P = k !== void 0, F = P ? k : re, I = c(F);
12
+ I.current = F;
13
+ let L = c(null), R = c(null), z = c(null), B = ee(), V = j !== void 0, H = V && j !== null, U = !!C || a !== void 0 || !V, W = o((e) => {
14
+ e !== I.current && (P || ie(e), A?.(e), e ? x?.() : S?.());
15
+ }, [
16
+ P,
17
+ A,
18
+ x,
19
+ S
20
+ ]);
21
+ s(() => {
22
+ F && R.current && R.current.querySelector(m)?.focus();
23
+ }, [F]);
24
+ let G = o(() => {
25
+ W(!1), z.current?.focus();
26
+ }, [W]), K = o(() => {
27
+ W(!I.current);
28
+ }, [W]), ae = o((e) => {
29
+ let t = R.current;
30
+ if (!t) return;
31
+ let n = Array.from(t.querySelectorAll(m));
32
+ if (n.length === 0) return;
33
+ let r = n.indexOf(document.activeElement), i = (e) => {
34
+ n[(e + n.length) % n.length]?.focus();
35
+ };
36
+ switch (e.key) {
37
+ case "ArrowDown":
38
+ e.preventDefault(), i(r + 1);
39
+ return;
40
+ case "ArrowUp":
41
+ e.preventDefault(), i(r - 1);
42
+ return;
43
+ case "Home":
44
+ e.preventDefault(), i(0);
45
+ return;
46
+ case "End":
47
+ e.preventDefault(), i(n.length - 1);
48
+ return;
49
+ }
50
+ if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && e.key !== " ") {
51
+ let t = e.key.toLowerCase();
52
+ for (let i = 1; i <= n.length; i++) {
53
+ let a = n[(r + i) % n.length];
54
+ if ((a.textContent ?? "").trim().toLowerCase().startsWith(t)) {
55
+ e.preventDefault(), a.focus();
56
+ return;
57
+ }
58
+ }
59
+ }
60
+ }, []), [q, J] = l(null);
61
+ te(() => {
62
+ if (!F || !j || !R.current || typeof window > "u") {
63
+ J(null);
64
+ return;
65
+ }
66
+ let e = R.current.getBoundingClientRect(), t = document.documentElement.clientWidth || window.innerWidth, n = document.documentElement.clientHeight || window.innerHeight, r = j.x, i = j.y;
67
+ r + e.width > t - h && (r = j.x - e.width), i + e.height > n - h && (i = j.y - e.height), r = Math.max(h, Math.min(r, t - h - e.width)), i = Math.max(h, Math.min(i, n - h - e.height)), J({
68
+ top: Math.round(i),
69
+ left: Math.round(r)
70
+ });
71
+ }, [
72
+ F,
73
+ j?.x,
74
+ j?.y
75
+ ]);
76
+ let oe = o((e) => {
77
+ T?.(e), G();
78
+ }, [T, G]);
79
+ s(() => {
80
+ if (!F) return;
81
+ let e = (e) => {
82
+ let t = e.target;
83
+ L.current?.contains(t) || R.current?.contains(t) || G();
84
+ };
85
+ return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
86
+ }, [F, G]);
87
+ let se = n(G, F), Y = r(z, F && O && !H), ce = { close: G }, X = C?.find((e) => e.value === w)?.label, Z = C ? X || ne : a, Q = C && !X, le = C ? C.map((t) => /* @__PURE__ */ d("button", {
88
+ type: "button",
89
+ role: "menuitem",
90
+ className: u(e.item, t.disabled && e.itemDisabled, t.value === w && e.itemSelected, M?.item),
91
+ disabled: t.disabled,
92
+ onClick: () => oe(t.value),
93
+ children: t.label
94
+ }, t.value)) : g, $ = (n) => /* @__PURE__ */ d("div", {
95
+ ref: R,
96
+ id: B,
97
+ className: u(e.menu, F && e.menuOpen, _ === "left" ? e.alignLeft : e.alignRight, !O && D && e.fullWidth, M?.menu),
98
+ style: n,
99
+ role: "menu",
100
+ onKeyDown: ae,
101
+ children: /* @__PURE__ */ d(t, {
102
+ value: se,
103
+ children: /* @__PURE__ */ d(i.Provider, {
104
+ value: ce,
105
+ children: le
106
+ })
107
+ })
108
+ });
109
+ return V ? /* @__PURE__ */ f("div", {
110
+ ref: N,
111
+ className: u(e.root, U && D && e.fullWidth, M?.root, v),
112
+ style: y,
113
+ children: [U && /* @__PURE__ */ d("div", {
114
+ ref: L,
115
+ style: D ? { width: "100%" } : void 0,
116
+ children: /* @__PURE__ */ f("button", {
117
+ ref: z,
118
+ id: b,
119
+ type: "button",
120
+ className: u(e.trigger, F && e.triggerOpen, E && e.triggerError, D && e.fullWidth, M?.trigger),
121
+ onClick: K,
122
+ "aria-expanded": F,
123
+ "aria-haspopup": "menu",
124
+ "aria-controls": F ? B : void 0,
125
+ children: [/* @__PURE__ */ d("span", {
126
+ className: u(e.triggerLabel, Q && e.placeholder, M?.triggerLabel),
127
+ children: Z
128
+ }), /* @__PURE__ */ d("span", {
129
+ className: u(e.chevron, M?.chevron),
130
+ "aria-hidden": "true"
131
+ })]
132
+ })
133
+ }), F && H && typeof document < "u" && p($({
134
+ position: "fixed",
135
+ top: q?.top ?? j.y,
136
+ left: q?.left ?? j.x,
137
+ visibility: q ? void 0 : "hidden",
138
+ zIndex: "var(--crk-z-floating)"
139
+ }), document.body)]
140
+ }) : /* @__PURE__ */ f("div", {
141
+ ref: N,
142
+ className: u(e.root, D && e.fullWidth, M?.root, v),
143
+ style: y,
144
+ children: [/* @__PURE__ */ f("div", {
145
+ ref: L,
146
+ style: D ? { width: "100%" } : void 0,
147
+ children: [/* @__PURE__ */ f("button", {
148
+ ref: z,
149
+ id: b,
150
+ type: "button",
151
+ className: u(e.trigger, F && e.triggerOpen, E && e.triggerError, D && e.fullWidth, M?.trigger),
152
+ onClick: K,
153
+ "aria-expanded": F,
154
+ "aria-haspopup": "menu",
155
+ "aria-controls": F ? B : void 0,
156
+ children: [/* @__PURE__ */ d("span", {
157
+ className: u(e.triggerLabel, Q && e.placeholder, M?.triggerLabel),
158
+ children: Z
159
+ }), /* @__PURE__ */ d("span", {
160
+ className: u(e.chevron, M?.chevron),
161
+ "aria-hidden": "true"
162
+ })]
163
+ }), !O && $()]
164
+ }), O && F && typeof document < "u" && p($({
165
+ position: "fixed",
166
+ top: Y.top + 4,
167
+ left: _ === "right" ? void 0 : Y.left,
168
+ right: _ === "right" ? document.documentElement.clientWidth - (Y.left + Y.width) : void 0,
169
+ minWidth: Y.width,
170
+ zIndex: "var(--crk-z-floating)"
171
+ }), document.body)]
172
+ });
173
+ });
174
+ g.displayName = "Dropdown";
175
+ export { g as Dropdown };
@@ -0,0 +1,29 @@
1
+ // src/components/Dropdown/Dropdown.module.scss
2
+ var e = "crk-root-an8Cf", t = "crk-fullWidth-S-uVk", n = "crk-trigger-LwPaD", r = "crk-triggerOpen-U4pa9", i = "crk-triggerLabel-QLITs", a = "crk-triggerError-3jlu1", o = "crk-placeholder-fWdch", s = "crk-chevron-jmDNe", c = "crk-menu-fxnKL", l = "crk-menuOpen-HF-Y1", u = "crk-menuEnter-F0Yyt", d = "crk-alignLeft-buCDJ", f = "crk-alignRight-05P9w", p = "crk-item-f-Rhh", m = "crk-itemDisabled-L-d6i", h = "crk-itemSelected-Fwmuo", g = "crk-itemDanger-b1A4e", _ = "crk-itemChecked-xY5Cf", v = "crk-itemCheck-IZYaJ", y = "crk-itemIcon-3Gh8c", b = "crk-itemLabel-YdjzN", x = "crk-itemDescription-eM-fw", S = "crk-itemShortcut-33qnD", C = "crk-separator-C0jdb", w = "crk-label-Rd7NT", T = {
3
+ root: e,
4
+ fullWidth: t,
5
+ trigger: n,
6
+ triggerOpen: r,
7
+ triggerLabel: i,
8
+ triggerError: a,
9
+ placeholder: o,
10
+ chevron: s,
11
+ menu: c,
12
+ menuOpen: l,
13
+ menuEnter: u,
14
+ alignLeft: d,
15
+ alignRight: f,
16
+ item: p,
17
+ itemDisabled: m,
18
+ itemSelected: h,
19
+ itemDanger: g,
20
+ itemChecked: _,
21
+ itemCheck: v,
22
+ itemIcon: y,
23
+ itemLabel: b,
24
+ itemDescription: x,
25
+ itemShortcut: S,
26
+ separator: C,
27
+ label: w
28
+ };
29
+ export { d as alignLeft, f as alignRight, s as chevron, T as default, t as fullWidth, p as item, v as itemCheck, _ as itemChecked, g as itemDanger, x as itemDescription, m as itemDisabled, y as itemIcon, b as itemLabel, h as itemSelected, S as itemShortcut, w as label, c as menu, u as menuEnter, l as menuOpen, o as placeholder, e as root, C as separator, n as trigger, a as triggerError, i as triggerLabel, r as triggerOpen };
@@ -1,58 +1,55 @@
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(
7
- ({
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
- }
54
- );
55
- I.displayName = "DropdownItem";
56
- export {
57
- I as DropdownItem
58
- };
1
+ import e from "./Dropdown.module.js";
2
+ import { DropdownMenuContext as t } from "./dropdownContext.js";
3
+ import { forwardRef as n, useContext as r } from "react";
4
+ import i from "clsx";
5
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
6
+ // src/components/Dropdown/DropdownItem.tsx
7
+ var s = n(({ disabled: n = !1, danger: s = !1, icon: c, shortcut: l, checked: u, description: d, closeOnSelect: f, classes: p, className: m, children: h, onClick: g, ..._ }, v) => {
8
+ let y = r(t), b = u !== void 0, x = f ?? !b;
9
+ return /* @__PURE__ */ o("button", {
10
+ ref: v,
11
+ type: "button",
12
+ role: b ? "menuitemcheckbox" : "menuitem",
13
+ "aria-checked": b ? u : void 0,
14
+ className: i(e.item, n && e.itemDisabled, s && e.itemDanger, b && u && e.itemChecked, p?.item, m),
15
+ disabled: n,
16
+ onClick: (e) => {
17
+ g?.(e), x && !e.defaultPrevented && y?.close();
18
+ },
19
+ ..._,
20
+ children: [
21
+ b && /* @__PURE__ */ a("span", {
22
+ className: i(e.itemCheck, p?.itemCheck),
23
+ "aria-hidden": "true",
24
+ children: u && /* @__PURE__ */ a("svg", {
25
+ viewBox: "0 0 16 16",
26
+ fill: "none",
27
+ stroke: "currentColor",
28
+ strokeWidth: "2",
29
+ strokeLinecap: "round",
30
+ strokeLinejoin: "round",
31
+ children: /* @__PURE__ */ a("path", { d: "M3 8.5l3 3 7-7" })
32
+ })
33
+ }),
34
+ c != null && /* @__PURE__ */ a("span", {
35
+ className: i(e.itemIcon, p?.itemIcon),
36
+ "aria-hidden": "true",
37
+ children: c
38
+ }),
39
+ /* @__PURE__ */ o("span", {
40
+ className: i(e.itemLabel, p?.itemLabel),
41
+ children: [h, d != null && /* @__PURE__ */ a("span", {
42
+ className: i(e.itemDescription, p?.itemDescription),
43
+ children: d
44
+ })]
45
+ }),
46
+ l != null && /* @__PURE__ */ a("span", {
47
+ className: i(e.itemShortcut, p?.itemShortcut),
48
+ "aria-hidden": "true",
49
+ children: l
50
+ })
51
+ ]
52
+ });
53
+ });
54
+ s.displayName = "DropdownItem";
55
+ export { s as DropdownItem };
@@ -1,11 +1,14 @@
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
- };
1
+ import e from "./Dropdown.module.js";
2
+ import { forwardRef as t } from "react";
3
+ import n from "clsx";
4
+ import { jsx as r } from "react/jsx-runtime";
5
+ // src/components/Dropdown/DropdownLabel.tsx
6
+ var i = t(({ className: t, children: i, ...a }, o) => /* @__PURE__ */ r("div", {
7
+ ref: o,
8
+ role: "presentation",
9
+ className: n(e.label, t),
10
+ ...a,
11
+ children: i
12
+ }));
13
+ i.displayName = "DropdownLabel";
14
+ export { i as DropdownLabel };
@@ -1,11 +1,13 @@
1
- import { jsx as p } from "react/jsx-runtime";
1
+ import e from "./Dropdown.module.js";
2
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
- };
3
+ import n from "clsx";
4
+ import { jsx as r } from "react/jsx-runtime";
5
+ // src/components/Dropdown/DropdownSeparator.tsx
6
+ var i = t(({ className: t, ...i }, a) => /* @__PURE__ */ r("div", {
7
+ ref: a,
8
+ role: "separator",
9
+ className: n(e.separator, t),
10
+ ...i
11
+ }));
12
+ i.displayName = "DropdownSeparator";
13
+ export { i as DropdownSeparator };
@@ -1,5 +1,4 @@
1
- import { createContext as o } from "react";
2
- const e = o(null);
3
- export {
4
- e as DropdownMenuContext
5
- };
1
+ import { createContext as e } from "react";
2
+ // src/components/Dropdown/dropdownContext.ts
3
+ var t = e(null);
4
+ export { t as DropdownMenuContext };