@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,287 +1,264 @@
1
- import { jsxs as I, Fragment as U, jsx as o } from "react/jsx-runtime";
2
- import { useRef as $, useState as q, useMemo as b, useEffect as le } from "react";
3
- import m from "clsx";
4
- import r from "./CalendarPanel.module.scss.js";
5
- import { weekdayLabels as de, buildCalendarDays as ce, toISODate as x, isSameMonth as W, isSameDay as C, addMonths as F, startOfMonth as G, addDays as g } from "./dateUtils.js";
6
- const z = 100, he = 3, me = 4;
7
- function ve({
8
- viewDate: l,
9
- focusedDate: i,
10
- selected: J,
11
- today: Q,
12
- minDay: p,
13
- maxDay: f,
14
- locale: d,
15
- weekStartsOn: y,
16
- isDisabledDay: S,
17
- onSelect: V,
18
- onViewDateChange: L,
19
- onFocusedDateChange: E,
20
- onEscape: X,
21
- classes: u
22
- }) {
23
- const H = $(null), T = $(null), [c, N] = q("day"), [s, R] = q(0), h = l.getFullYear(), k = l.getMonth(), Z = b(
24
- () => new Intl.DateTimeFormat(d, { month: "long", year: "numeric" }).format(l),
25
- [d, l]
26
- ), D = b(() => new Intl.DateTimeFormat(d, { month: "long" }).format(l), [d, l]), ee = b(() => new Intl.DateTimeFormat(d, { year: "numeric" }).format(l), [d, l]), te = b(() => {
27
- const e = new Intl.DateTimeFormat(d, { month: "short" }), t = new Intl.DateTimeFormat(d, { month: "long" });
28
- return Array.from({ length: 12 }, (a, n) => {
29
- const A = new Date(2023, n, 1);
30
- return { short: e.format(A), long: t.format(A) };
31
- });
32
- }, [d]), w = b(() => {
33
- let e = p ? p.getFullYear() : h - z, t = f ? f.getFullYear() : h + z;
34
- return e = Math.min(e, h), t = Math.max(t, h), Array.from({ length: t - e + 1 }, (a, n) => e + n);
35
- }, [p, f, h]), ne = b(() => de(d, y), [d, y]), re = b(() => ce(l, y), [l, y]), ae = b(() => new Intl.DateTimeFormat(d, { dateStyle: "full" }), [d]), Y = (e) => {
36
- const t = new Date(h, e, 1), a = new Date(h, e + 1, 0);
37
- return !!f && t > f || !!p && a < p;
38
- }, K = (e) => !!f && new Date(e, 0, 1) > f || !!p && new Date(e, 11, 31) < p;
39
- le(() => {
40
- if (c === "day") {
41
- H.current?.querySelector(`[data-date="${x(i)}"]`)?.focus();
42
- return;
43
- }
44
- const e = T.current, t = e?.querySelector("[data-active]");
45
- e && t && (e.scrollTop = t.offsetTop - e.clientHeight / 2 + t.offsetHeight / 2, t.focus());
46
- }, [c, i, s]);
47
- const oe = (e) => {
48
- E(e), W(e, l) || L(G(e));
49
- }, P = (e) => {
50
- S(e) || V(e);
51
- }, _ = (e) => {
52
- if (c === e) {
53
- N("day");
54
- return;
55
- }
56
- R(e === "month" ? k : w.indexOf(h)), N(e);
57
- }, M = (e, t) => {
58
- const a = new Date(e, t + 1, 0).getDate(), n = new Date(e, t, Math.min(i.getDate(), a));
59
- E(n), L(G(n)), N("day");
60
- }, ie = (e) => {
61
- let t = null;
62
- switch (e.key) {
63
- case "ArrowLeft":
64
- t = g(i, -1);
65
- break;
66
- case "ArrowRight":
67
- t = g(i, 1);
68
- break;
69
- case "ArrowUp":
70
- t = g(i, -7);
71
- break;
72
- case "ArrowDown":
73
- t = g(i, 7);
74
- break;
75
- case "Home":
76
- t = g(i, -((i.getDay() - y + 7) % 7));
77
- break;
78
- case "End":
79
- t = g(i, 6 - (i.getDay() - y + 7) % 7);
80
- break;
81
- case "PageUp":
82
- t = F(i, -1);
83
- break;
84
- case "PageDown":
85
- t = F(i, 1);
86
- break;
87
- case "Enter":
88
- case " ":
89
- e.preventDefault(), P(i);
90
- return;
91
- case "Escape":
92
- e.preventDefault(), X();
93
- return;
94
- default:
95
- return;
96
- }
97
- e.preventDefault(), oe(t);
98
- }, j = (e, t, a) => {
99
- let n = s;
100
- switch (e.key) {
101
- case "ArrowLeft":
102
- n = s - 1;
103
- break;
104
- case "ArrowRight":
105
- n = s + 1;
106
- break;
107
- case "ArrowUp":
108
- n = s - a;
109
- break;
110
- case "ArrowDown":
111
- n = s + a;
112
- break;
113
- case "Home":
114
- n = 0;
115
- break;
116
- case "End":
117
- n = t - 1;
118
- break;
119
- case "Enter":
120
- case " ":
121
- e.preventDefault(), c === "month" ? Y(s) || M(h, s) : K(w[s]) || M(w[s], k);
122
- return;
123
- case "Escape":
124
- e.preventDefault(), N("day");
125
- return;
126
- default:
127
- return;
128
- }
129
- e.preventDefault(), R(Math.max(0, Math.min(t - 1, n)));
130
- }, v = c === "year", B = c === "day" ? "month" : "year", O = (e) => L(c === "day" ? F(l, e) : new Date(h + e, k, 1));
131
- return /* @__PURE__ */ I(U, { children: [
132
- /* @__PURE__ */ I("div", { className: m(r.header, u?.header), children: [
133
- /* @__PURE__ */ o(
134
- "button",
135
- {
136
- type: "button",
137
- className: m(r.nav, v && r.navHidden, u?.nav),
138
- onClick: () => O(-1),
139
- "aria-label": `Previous ${B}`,
140
- "aria-hidden": v || void 0,
141
- tabIndex: v ? -1 : void 0,
142
- children: /* @__PURE__ */ o("svg", { viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ o("path", { d: "M7 2L3 6l4 4" }) })
143
- }
144
- ),
145
- /* @__PURE__ */ I("div", { className: r.title, children: [
146
- /* @__PURE__ */ o(
147
- "button",
148
- {
149
- type: "button",
150
- className: r.titleButton,
151
- "aria-label": "Choose month",
152
- "aria-expanded": c === "month",
153
- onClick: () => _("month"),
154
- children: D
155
- }
156
- ),
157
- /* @__PURE__ */ o(
158
- "button",
159
- {
160
- type: "button",
161
- className: r.titleButton,
162
- "aria-label": "Choose year",
163
- "aria-expanded": c === "year",
164
- onClick: () => _("year"),
165
- children: ee
166
- }
167
- ),
168
- /* @__PURE__ */ o("span", { className: r.srOnly, "aria-live": "polite", children: Z })
169
- ] }),
170
- /* @__PURE__ */ o(
171
- "button",
172
- {
173
- type: "button",
174
- className: m(r.nav, v && r.navHidden, u?.nav),
175
- onClick: () => O(1),
176
- "aria-label": `Next ${B}`,
177
- "aria-hidden": v || void 0,
178
- tabIndex: v ? -1 : void 0,
179
- children: /* @__PURE__ */ o("svg", { viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ o("path", { d: "M5 2l4 4-4 4" }) })
180
- }
181
- )
182
- ] }),
183
- c === "month" && // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
184
- /* @__PURE__ */ o(
185
- "div",
186
- {
187
- ref: T,
188
- role: "listbox",
189
- "aria-label": "Month",
190
- className: m(r.options, r.months),
191
- onKeyDown: (e) => j(e, 12, he),
192
- children: te.map((e, t) => {
193
- const a = Y(t), n = t === k;
194
- return /* @__PURE__ */ o(
195
- "button",
196
- {
197
- type: "button",
198
- role: "option",
199
- "aria-selected": n,
200
- "aria-disabled": a || void 0,
201
- "aria-label": e.long,
202
- tabIndex: t === s ? 0 : -1,
203
- "data-active": t === s || void 0,
204
- className: m(r.option, n && r.optionSelected),
205
- onClick: () => !a && M(h, t),
206
- children: e.short
207
- },
208
- t
209
- );
210
- })
211
- }
212
- ),
213
- c === "year" && // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
214
- /* @__PURE__ */ o(
215
- "div",
216
- {
217
- ref: T,
218
- role: "listbox",
219
- "aria-label": "Year",
220
- className: m(r.options, r.years),
221
- onKeyDown: (e) => j(e, w.length, me),
222
- children: w.map((e, t) => {
223
- const a = K(e), n = e === h;
224
- return /* @__PURE__ */ o(
225
- "button",
226
- {
227
- type: "button",
228
- role: "option",
229
- "aria-selected": n,
230
- "aria-disabled": a || void 0,
231
- tabIndex: t === s ? 0 : -1,
232
- "data-active": t === s || void 0,
233
- className: m(r.option, n && r.optionSelected),
234
- onClick: () => !a && M(e, k),
235
- children: e
236
- },
237
- e
238
- );
239
- })
240
- }
241
- ),
242
- c === "day" && /* @__PURE__ */ I(U, { children: [
243
- /* @__PURE__ */ o("div", { className: r.weekdays, "aria-hidden": "true", children: ne.map((e, t) => /* @__PURE__ */ o("span", { className: r.weekday, children: e }, t)) }),
244
- /* @__PURE__ */ o(
245
- "div",
246
- {
247
- ref: H,
248
- role: "grid",
249
- className: m(r.grid, u?.grid),
250
- onKeyDown: ie,
251
- children: re.map((e) => {
252
- const t = !W(e, l), a = C(e, J), n = C(e, Q), A = S(e), se = C(e, i);
253
- return /* @__PURE__ */ o(
254
- "button",
255
- {
256
- type: "button",
257
- role: "gridcell",
258
- "data-date": x(e),
259
- tabIndex: se ? 0 : -1,
260
- className: m(
261
- r.day,
262
- t && r.dayOutside,
263
- n && r.dayToday,
264
- a && r.daySelected,
265
- t && u?.dayOutside,
266
- n && u?.dayToday,
267
- a && u?.daySelected,
268
- u?.day
269
- ),
270
- "aria-selected": a,
271
- "aria-disabled": A || void 0,
272
- "aria-current": n ? "date" : void 0,
273
- "aria-label": ae.format(e),
274
- onClick: () => P(e),
275
- children: e.getDate()
276
- },
277
- x(e)
278
- );
279
- })
280
- }
281
- )
282
- ] })
283
- ] });
1
+ import e from "./CalendarPanel.module.js";
2
+ import { addDays as t, addMonths as n, buildCalendarDays as r, isSameDay as i, isSameMonth as a, startOfMonth as o, toISODate as s, weekdayLabels as c } from "./dateUtils.js";
3
+ import { useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
4
+ import p from "clsx";
5
+ import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
6
+ // src/components/inputs/DatePicker/CalendarPanel.tsx
7
+ var _ = 100, v = 3, y = 4;
8
+ function b({ viewDate: b, focusedDate: x, selected: S, today: C, minDay: w, maxDay: T, locale: E, weekStartsOn: D, isDisabledDay: O, onSelect: k, onViewDateChange: A, onFocusedDateChange: j, onEscape: M, classes: N }) {
9
+ let P = d(null), F = d(null), [I, L] = f("day"), [R, z] = f(0), B = b.getFullYear(), V = b.getMonth(), H = u(() => new Intl.DateTimeFormat(E, {
10
+ month: "long",
11
+ year: "numeric"
12
+ }).format(b), [E, b]), U = u(() => new Intl.DateTimeFormat(E, { month: "long" }).format(b), [E, b]), ee = u(() => new Intl.DateTimeFormat(E, { year: "numeric" }).format(b), [E, b]), te = u(() => {
13
+ let e = new Intl.DateTimeFormat(E, { month: "short" }), t = new Intl.DateTimeFormat(E, { month: "long" });
14
+ return Array.from({ length: 12 }, (n, r) => {
15
+ let i = new Date(2023, r, 1);
16
+ return {
17
+ short: e.format(i),
18
+ long: t.format(i)
19
+ };
20
+ });
21
+ }, [E]), W = u(() => {
22
+ let e = w ? w.getFullYear() : B - _, t = T ? T.getFullYear() : B + _;
23
+ return e = Math.min(e, B), t = Math.max(t, B), Array.from({ length: t - e + 1 }, (t, n) => e + n);
24
+ }, [
25
+ w,
26
+ T,
27
+ B
28
+ ]), ne = u(() => c(E, D), [E, D]), re = u(() => r(b, D), [b, D]), ie = u(() => new Intl.DateTimeFormat(E, { dateStyle: "full" }), [E]), G = (e) => {
29
+ let t = new Date(B, e, 1), n = new Date(B, e + 1, 0);
30
+ return !!T && t > T || !!w && n < w;
31
+ }, K = (e) => !!T && new Date(e, 0, 1) > T || !!w && new Date(e, 11, 31) < w;
32
+ l(() => {
33
+ if (I === "day") {
34
+ P.current?.querySelector(`[data-date="${s(x)}"]`)?.focus();
35
+ return;
36
+ }
37
+ let e = F.current, t = e?.querySelector("[data-active]");
38
+ e && t && (e.scrollTop = t.offsetTop - e.clientHeight / 2 + t.offsetHeight / 2, t.focus());
39
+ }, [
40
+ I,
41
+ x,
42
+ R
43
+ ]);
44
+ let ae = (e) => {
45
+ j(e), a(e, b) || A(o(e));
46
+ }, q = (e) => {
47
+ O(e) || k(e);
48
+ }, J = (e) => {
49
+ I === e ? L("day") : (z(e === "month" ? V : W.indexOf(B)), L(e));
50
+ }, Y = (e, t) => {
51
+ let n = new Date(e, t + 1, 0).getDate(), r = new Date(e, t, Math.min(x.getDate(), n));
52
+ j(r), A(o(r)), L("day");
53
+ }, oe = (e) => {
54
+ let r = null;
55
+ switch (e.key) {
56
+ case "ArrowLeft":
57
+ r = t(x, -1);
58
+ break;
59
+ case "ArrowRight":
60
+ r = t(x, 1);
61
+ break;
62
+ case "ArrowUp":
63
+ r = t(x, -7);
64
+ break;
65
+ case "ArrowDown":
66
+ r = t(x, 7);
67
+ break;
68
+ case "Home":
69
+ r = t(x, -((x.getDay() - D + 7) % 7));
70
+ break;
71
+ case "End":
72
+ r = t(x, 6 - (x.getDay() - D + 7) % 7);
73
+ break;
74
+ case "PageUp":
75
+ r = n(x, -1);
76
+ break;
77
+ case "PageDown":
78
+ r = n(x, 1);
79
+ break;
80
+ case "Enter":
81
+ case " ":
82
+ e.preventDefault(), q(x);
83
+ return;
84
+ case "Escape":
85
+ e.preventDefault(), M();
86
+ return;
87
+ default: return;
88
+ }
89
+ e.preventDefault(), ae(r);
90
+ }, X = (e, t, n) => {
91
+ let r = R;
92
+ switch (e.key) {
93
+ case "ArrowLeft":
94
+ r = R - 1;
95
+ break;
96
+ case "ArrowRight":
97
+ r = R + 1;
98
+ break;
99
+ case "ArrowUp":
100
+ r = R - n;
101
+ break;
102
+ case "ArrowDown":
103
+ r = R + n;
104
+ break;
105
+ case "Home":
106
+ r = 0;
107
+ break;
108
+ case "End":
109
+ r = t - 1;
110
+ break;
111
+ case "Enter":
112
+ case " ":
113
+ e.preventDefault(), I === "month" ? G(R) || Y(B, R) : K(W[R]) || Y(W[R], V);
114
+ return;
115
+ case "Escape":
116
+ e.preventDefault(), L("day");
117
+ return;
118
+ default: return;
119
+ }
120
+ e.preventDefault(), z(Math.max(0, Math.min(t - 1, r)));
121
+ }, Z = I === "year", Q = I === "day" ? "month" : "year", $ = (e) => A(I === "day" ? n(b, e) : new Date(B + e, V, 1));
122
+ return /* @__PURE__ */ g(m, { children: [
123
+ /* @__PURE__ */ g("div", {
124
+ className: p(e.header, N?.header),
125
+ children: [
126
+ /* @__PURE__ */ h("button", {
127
+ type: "button",
128
+ className: p(e.nav, Z && e.navHidden, N?.nav),
129
+ onClick: () => $(-1),
130
+ "aria-label": `Previous ${Q}`,
131
+ "aria-hidden": Z || void 0,
132
+ tabIndex: Z ? -1 : void 0,
133
+ children: /* @__PURE__ */ h("svg", {
134
+ viewBox: "0 0 12 12",
135
+ fill: "none",
136
+ stroke: "currentColor",
137
+ strokeWidth: "1.5",
138
+ strokeLinecap: "round",
139
+ strokeLinejoin: "round",
140
+ "aria-hidden": "true",
141
+ children: /* @__PURE__ */ h("path", { d: "M7 2L3 6l4 4" })
142
+ })
143
+ }),
144
+ /* @__PURE__ */ g("div", {
145
+ className: e.title,
146
+ children: [
147
+ /* @__PURE__ */ h("button", {
148
+ type: "button",
149
+ className: e.titleButton,
150
+ "aria-label": "Choose month",
151
+ "aria-expanded": I === "month",
152
+ onClick: () => J("month"),
153
+ children: U
154
+ }),
155
+ /* @__PURE__ */ h("button", {
156
+ type: "button",
157
+ className: e.titleButton,
158
+ "aria-label": "Choose year",
159
+ "aria-expanded": I === "year",
160
+ onClick: () => J("year"),
161
+ children: ee
162
+ }),
163
+ /* @__PURE__ */ h("span", {
164
+ className: e.srOnly,
165
+ "aria-live": "polite",
166
+ children: H
167
+ })
168
+ ]
169
+ }),
170
+ /* @__PURE__ */ h("button", {
171
+ type: "button",
172
+ className: p(e.nav, Z && e.navHidden, N?.nav),
173
+ onClick: () => $(1),
174
+ "aria-label": `Next ${Q}`,
175
+ "aria-hidden": Z || void 0,
176
+ tabIndex: Z ? -1 : void 0,
177
+ children: /* @__PURE__ */ h("svg", {
178
+ viewBox: "0 0 12 12",
179
+ fill: "none",
180
+ stroke: "currentColor",
181
+ strokeWidth: "1.5",
182
+ strokeLinecap: "round",
183
+ strokeLinejoin: "round",
184
+ "aria-hidden": "true",
185
+ children: /* @__PURE__ */ h("path", { d: "M5 2l4 4-4 4" })
186
+ })
187
+ })
188
+ ]
189
+ }),
190
+ I === "month" && /* @__PURE__ */ h("div", {
191
+ ref: F,
192
+ role: "listbox",
193
+ "aria-label": "Month",
194
+ className: p(e.options, e.months),
195
+ onKeyDown: (e) => X(e, 12, v),
196
+ children: te.map((t, n) => {
197
+ let r = G(n), i = n === V;
198
+ return /* @__PURE__ */ h("button", {
199
+ type: "button",
200
+ role: "option",
201
+ "aria-selected": i,
202
+ "aria-disabled": r || void 0,
203
+ "aria-label": t.long,
204
+ tabIndex: n === R ? 0 : -1,
205
+ "data-active": n === R || void 0,
206
+ className: p(e.option, i && e.optionSelected),
207
+ onClick: () => !r && Y(B, n),
208
+ children: t.short
209
+ }, n);
210
+ })
211
+ }),
212
+ I === "year" && /* @__PURE__ */ h("div", {
213
+ ref: F,
214
+ role: "listbox",
215
+ "aria-label": "Year",
216
+ className: p(e.options, e.years),
217
+ onKeyDown: (e) => X(e, W.length, y),
218
+ children: W.map((t, n) => {
219
+ let r = K(t), i = t === B;
220
+ return /* @__PURE__ */ h("button", {
221
+ type: "button",
222
+ role: "option",
223
+ "aria-selected": i,
224
+ "aria-disabled": r || void 0,
225
+ tabIndex: n === R ? 0 : -1,
226
+ "data-active": n === R || void 0,
227
+ className: p(e.option, i && e.optionSelected),
228
+ onClick: () => !r && Y(t, V),
229
+ children: t
230
+ }, t);
231
+ })
232
+ }),
233
+ I === "day" && /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("div", {
234
+ className: e.weekdays,
235
+ "aria-hidden": "true",
236
+ children: ne.map((t, n) => /* @__PURE__ */ h("span", {
237
+ className: e.weekday,
238
+ children: t
239
+ }, n))
240
+ }), /* @__PURE__ */ h("div", {
241
+ ref: P,
242
+ role: "grid",
243
+ className: p(e.grid, N?.grid),
244
+ onKeyDown: oe,
245
+ children: re.map((t) => {
246
+ let n = !a(t, b), r = i(t, S), o = i(t, C), c = O(t), l = i(t, x);
247
+ return /* @__PURE__ */ h("button", {
248
+ type: "button",
249
+ role: "gridcell",
250
+ "data-date": s(t),
251
+ tabIndex: l ? 0 : -1,
252
+ className: p(e.day, n && e.dayOutside, o && e.dayToday, r && e.daySelected, n && N?.dayOutside, o && N?.dayToday, r && N?.daySelected, N?.day),
253
+ "aria-selected": r,
254
+ "aria-disabled": c || void 0,
255
+ "aria-current": o ? "date" : void 0,
256
+ "aria-label": ie.format(t),
257
+ onClick: () => q(t),
258
+ children: t.getDate()
259
+ }, s(t));
260
+ })
261
+ })] })
262
+ ] });
284
263
  }
285
- export {
286
- ve as CalendarPanel
287
- };
264
+ export { b as CalendarPanel };
@@ -0,0 +1,23 @@
1
+ // src/components/inputs/DatePicker/CalendarPanel.module.scss
2
+ var e = "crk-header-T9XMb", t = "crk-monthLabel-8mRvZ", n = "crk-nav-iAxYo", r = "crk-weekdays-TV4PD", i = "crk-grid--96pQ", a = "crk-weekday--syM1", o = "crk-day-m-HUr", s = "crk-dayOutside-x2kQk", c = "crk-dayToday-qIjS-", l = "crk-daySelected-iA4S4", u = "crk-title-68NVZ", d = "crk-titleButton-9V2YZ", f = "crk-srOnly-4nytm", p = "crk-navHidden-QhiL0", m = "crk-options-b8L5n", h = "crk-months-b-CoG", g = "crk-years-QGvpU", _ = "crk-option-kbY30", v = "crk-optionSelected-as-xo", y = {
3
+ header: e,
4
+ monthLabel: t,
5
+ nav: n,
6
+ weekdays: r,
7
+ grid: i,
8
+ weekday: a,
9
+ day: o,
10
+ dayOutside: s,
11
+ dayToday: c,
12
+ daySelected: l,
13
+ title: u,
14
+ titleButton: d,
15
+ srOnly: f,
16
+ navHidden: p,
17
+ options: m,
18
+ months: h,
19
+ years: g,
20
+ option: _,
21
+ optionSelected: v
22
+ };
23
+ export { o as day, s as dayOutside, l as daySelected, c as dayToday, y as default, i as grid, e as header, t as monthLabel, h as months, n as nav, p as navHidden, _ as option, v as optionSelected, m as options, f as srOnly, u as title, d as titleButton, a as weekday, r as weekdays, g as years };