@monolith-forensics/monolith-ui 1.7.1 → 1.8.1-dev.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 (176) hide show
  1. package/dist/BarChart/BarChart.d.ts +3 -0
  2. package/dist/BarChart/BarChart.js +511 -0
  3. package/dist/BarChart/BarChart.lib.d.ts +31 -0
  4. package/dist/BarChart/BarChart.lib.js +136 -0
  5. package/dist/BarChart/BarChart.styled.d.ts +49 -0
  6. package/dist/BarChart/BarChart.styled.js +111 -0
  7. package/dist/BarChart/BarChart.types.d.ts +170 -0
  8. package/dist/BarChart/BarChart.types.js +1 -0
  9. package/dist/BarChart/index.d.ts +3 -0
  10. package/dist/BarChart/index.js +2 -0
  11. package/dist/Button/Button.js +9 -58
  12. package/dist/Calendar/Calendar.d.ts +3 -1
  13. package/dist/Calendar/Calendar.js +134 -33
  14. package/dist/Calendar/CalendarStyles.d.ts +3 -0
  15. package/dist/Calendar/CalendarStyles.js +92 -14
  16. package/dist/Calendar/calendarHelpers.d.ts +5 -1
  17. package/dist/Calendar/calendarHelpers.js +13 -5
  18. package/dist/ChartPrimitives/chartLegend.styled.d.ts +12 -0
  19. package/dist/ChartPrimitives/chartLegend.styled.js +52 -0
  20. package/dist/ChartPrimitives/chartTooltip.styled.d.ts +19 -0
  21. package/dist/ChartPrimitives/chartTooltip.styled.js +61 -0
  22. package/dist/ChartPrimitives/index.d.ts +2 -0
  23. package/dist/ChartPrimitives/index.js +2 -0
  24. package/dist/ChartUtils/chartColors.d.ts +8 -0
  25. package/dist/ChartUtils/chartColors.js +65 -0
  26. package/dist/ChartUtils/chartMath.d.ts +3 -0
  27. package/dist/ChartUtils/chartMath.js +3 -0
  28. package/dist/ChartUtils/index.d.ts +2 -0
  29. package/dist/ChartUtils/index.js +2 -0
  30. package/dist/Charts/BarChart/BarChart.d.ts +5 -0
  31. package/dist/Charts/BarChart/BarChart.js +549 -0
  32. package/dist/Charts/BarChart/BarChart.lib.d.ts +31 -0
  33. package/dist/Charts/BarChart/BarChart.lib.js +136 -0
  34. package/dist/Charts/BarChart/BarChart.styled.d.ts +51 -0
  35. package/dist/Charts/BarChart/BarChart.styled.js +115 -0
  36. package/dist/Charts/BarChart/BarChart.types.d.ts +171 -0
  37. package/dist/Charts/BarChart/BarChart.types.js +1 -0
  38. package/dist/Charts/BarChart/index.d.ts +3 -0
  39. package/dist/Charts/BarChart/index.js +2 -0
  40. package/dist/Charts/ChartPrimitives/ChartExportControl.d.ts +11 -0
  41. package/dist/Charts/ChartPrimitives/ChartExportControl.js +29 -0
  42. package/dist/Charts/ChartPrimitives/chartActions.styled.d.ts +1 -0
  43. package/dist/Charts/ChartPrimitives/chartActions.styled.js +8 -0
  44. package/dist/Charts/ChartPrimitives/chartLegend.styled.d.ts +12 -0
  45. package/dist/Charts/ChartPrimitives/chartLegend.styled.js +52 -0
  46. package/dist/Charts/ChartPrimitives/chartTooltip.styled.d.ts +19 -0
  47. package/dist/Charts/ChartPrimitives/chartTooltip.styled.js +61 -0
  48. package/dist/Charts/ChartPrimitives/index.d.ts +4 -0
  49. package/dist/Charts/ChartPrimitives/index.js +4 -0
  50. package/dist/Charts/ChartUtils/chartColors.d.ts +8 -0
  51. package/dist/Charts/ChartUtils/chartColors.js +65 -0
  52. package/dist/Charts/ChartUtils/chartExport.d.ts +47 -0
  53. package/dist/Charts/ChartUtils/chartExport.js +311 -0
  54. package/dist/Charts/ChartUtils/chartMath.d.ts +3 -0
  55. package/dist/Charts/ChartUtils/chartMath.js +3 -0
  56. package/dist/Charts/ChartUtils/index.d.ts +3 -0
  57. package/dist/Charts/ChartUtils/index.js +3 -0
  58. package/dist/Charts/HeatMap/HeatMap.d.ts +5 -0
  59. package/dist/Charts/HeatMap/HeatMap.js +212 -0
  60. package/dist/Charts/HeatMap/HeatMap.lib.d.ts +30 -0
  61. package/dist/Charts/HeatMap/HeatMap.lib.js +115 -0
  62. package/dist/Charts/HeatMap/HeatMap.styled.d.ts +37 -0
  63. package/dist/Charts/HeatMap/HeatMap.styled.js +91 -0
  64. package/dist/Charts/HeatMap/HeatMap.types.d.ts +80 -0
  65. package/dist/Charts/HeatMap/HeatMap.types.js +1 -0
  66. package/dist/Charts/HeatMap/index.d.ts +3 -0
  67. package/dist/Charts/HeatMap/index.js +2 -0
  68. package/dist/Charts/LineChart/LineChart.d.ts +5 -0
  69. package/dist/Charts/LineChart/LineChart.js +529 -0
  70. package/dist/Charts/LineChart/LineChart.lib.d.ts +24 -0
  71. package/dist/Charts/LineChart/LineChart.lib.js +132 -0
  72. package/dist/Charts/LineChart/LineChart.styled.d.ts +59 -0
  73. package/dist/Charts/LineChart/LineChart.styled.js +147 -0
  74. package/dist/Charts/LineChart/LineChart.types.d.ts +193 -0
  75. package/dist/Charts/LineChart/LineChart.types.js +1 -0
  76. package/dist/Charts/LineChart/index.d.ts +3 -0
  77. package/dist/Charts/LineChart/index.js +2 -0
  78. package/dist/Charts/PieChart/PieChart.d.ts +4 -0
  79. package/dist/Charts/PieChart/PieChart.js +199 -0
  80. package/dist/Charts/PieChart/PieChart.lib.d.ts +5 -0
  81. package/dist/Charts/PieChart/PieChart.lib.js +19 -0
  82. package/dist/Charts/PieChart/PieChart.styled.d.ts +51 -0
  83. package/dist/Charts/PieChart/PieChart.styled.js +163 -0
  84. package/dist/Charts/PieChart/PieChart.types.d.ts +100 -0
  85. package/dist/Charts/PieChart/PieChart.types.js +1 -0
  86. package/dist/Charts/PieChart/index.d.ts +2 -0
  87. package/dist/Charts/PieChart/index.js +1 -0
  88. package/dist/Charts/index.d.ts +5 -0
  89. package/dist/Charts/index.js +4 -0
  90. package/dist/CheckBox/CheckBox.js +2 -16
  91. package/dist/DateInput/DateInput.js +198 -143
  92. package/dist/DropDownMenu/components/MenuComponent.js +2 -1
  93. package/dist/DropDownMenu/components/MenuItem.js +5 -14
  94. package/dist/DropDownMenu/components/MenuItemList.js +7 -24
  95. package/dist/DropDownMenu/components/StyledFloatContainer.js +1 -1
  96. package/dist/FieldLabel/FieldLabel.js +4 -12
  97. package/dist/FileInputField/FileInputField.js +4 -23
  98. package/dist/FormSection/FormSection.js +5 -25
  99. package/dist/HeatMap/HeatMap.d.ts +3 -0
  100. package/dist/HeatMap/HeatMap.js +174 -0
  101. package/dist/HeatMap/HeatMap.lib.d.ts +30 -0
  102. package/dist/HeatMap/HeatMap.lib.js +115 -0
  103. package/dist/HeatMap/HeatMap.styled.d.ts +34 -0
  104. package/dist/HeatMap/HeatMap.styled.js +83 -0
  105. package/dist/HeatMap/HeatMap.types.d.ts +79 -0
  106. package/dist/HeatMap/HeatMap.types.js +1 -0
  107. package/dist/HeatMap/index.d.ts +3 -0
  108. package/dist/HeatMap/index.js +2 -0
  109. package/dist/IconButton/IconButton.js +2 -16
  110. package/dist/Input/Input.js +7 -56
  111. package/dist/LineChart/LineChart.d.ts +3 -0
  112. package/dist/LineChart/LineChart.js +491 -0
  113. package/dist/LineChart/LineChart.lib.d.ts +24 -0
  114. package/dist/LineChart/LineChart.lib.js +132 -0
  115. package/dist/LineChart/LineChart.styled.d.ts +57 -0
  116. package/dist/LineChart/LineChart.styled.js +150 -0
  117. package/dist/LineChart/LineChart.types.d.ts +192 -0
  118. package/dist/LineChart/LineChart.types.js +1 -0
  119. package/dist/LineChart/index.d.ts +3 -0
  120. package/dist/LineChart/index.js +2 -0
  121. package/dist/PieChart/PieChart.d.ts +2 -0
  122. package/dist/PieChart/PieChart.js +161 -0
  123. package/dist/PieChart/PieChart.lib.d.ts +5 -0
  124. package/dist/PieChart/PieChart.lib.js +19 -0
  125. package/dist/PieChart/PieChart.styled.d.ts +49 -0
  126. package/dist/PieChart/PieChart.styled.js +161 -0
  127. package/dist/PieChart/PieChart.types.d.ts +99 -0
  128. package/dist/PieChart/PieChart.types.js +1 -0
  129. package/dist/PieChart/index.d.ts +2 -0
  130. package/dist/PieChart/index.js +1 -0
  131. package/dist/Pill/Pill.js +8 -79
  132. package/dist/Popover/Popover.context.d.ts +2 -1
  133. package/dist/Popover/Popover.js +5 -2
  134. package/dist/Popover/Popover.styles.d.ts +1 -6
  135. package/dist/Popover/Popover.styles.js +11 -28
  136. package/dist/Popover/Popover.transitions.d.ts +4 -2
  137. package/dist/Popover/Popover.transitions.js +23 -49
  138. package/dist/Popover/PopoverDropdown.js +6 -8
  139. package/dist/Popover/PopoverTarget.js +6 -3
  140. package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
  141. package/dist/SegmentedControl/SegmentedControl.utils.js +3 -30
  142. package/dist/SelectBox/SelectBox.js +3 -3
  143. package/dist/SelectBox/select-box.styled-components.d.ts +3 -1
  144. package/dist/SelectBox/select-box.styled-components.js +10 -48
  145. package/dist/SuperDatePicker/SuperDatePicker.d.ts +74 -0
  146. package/dist/SuperDatePicker/SuperDatePicker.js +557 -0
  147. package/dist/SuperDatePicker/index.d.ts +2 -0
  148. package/dist/SuperDatePicker/index.js +2 -0
  149. package/dist/Switch/Switch.d.ts +2 -2
  150. package/dist/Switch/Switch.js +18 -83
  151. package/dist/Table/StateStorage.d.ts +4 -0
  152. package/dist/Table/StateStorage.js +13 -0
  153. package/dist/Table/Table.js +160 -12
  154. package/dist/Table/TableComponents.d.ts +10 -0
  155. package/dist/Table/TableComponents.js +57 -0
  156. package/dist/Table/TableDefaults.d.ts +7 -0
  157. package/dist/Table/TableDefaults.js +7 -0
  158. package/dist/Table/TableProvider.js +263 -71
  159. package/dist/Table/TableRow.js +15 -10
  160. package/dist/Table/types.d.ts +64 -0
  161. package/dist/Tabs/Tab.js +8 -0
  162. package/dist/TagBox/TagBox.js +18 -76
  163. package/dist/TextArea/TextArea.js +4 -23
  164. package/dist/TextInput/TextInput.js +12 -6
  165. package/dist/Utilities/parseTimestamp.js +11 -6
  166. package/dist/core/ArrowButton.d.ts +2 -0
  167. package/dist/core/ArrowButton.js +7 -3
  168. package/dist/core/ClearButton.d.ts +2 -0
  169. package/dist/core/ClearButton.js +7 -3
  170. package/dist/core/controlSizes.d.ts +34 -0
  171. package/dist/core/controlSizes.js +190 -0
  172. package/dist/core/index.d.ts +1 -0
  173. package/dist/core/index.js +1 -0
  174. package/dist/index.d.ts +1 -0
  175. package/dist/index.js +1 -0
  176. package/package.json +5 -1
@@ -0,0 +1,557 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import moment from "moment";
12
+ import { CalendarClock, ChevronDown, ChevronsLeft, ChevronsRight, Loader2Icon, RefreshCw, Search, ZoomIn, ZoomOut, } from "lucide-react";
13
+ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
14
+ import styled, { keyframes } from "styled-components";
15
+ import { Button } from "../Button";
16
+ import DateInput from "../DateInput";
17
+ import Input from "../Input";
18
+ import { Popover } from "../Popover";
19
+ import { SegmentedControl } from "../SegmentedControl";
20
+ import { Switch } from "../Switch";
21
+ import { DEFAULT_CONTROL_SIZE, getControlSizeTokens, } from "../core";
22
+ const UNIT_LABELS = {
23
+ s: "seconds",
24
+ m: "minutes",
25
+ h: "hours",
26
+ d: "days",
27
+ w: "weeks",
28
+ M: "months",
29
+ y: "years",
30
+ };
31
+ const REFRESH_UNIT_LABELS = {
32
+ s: "Seconds",
33
+ m: "Minutes",
34
+ h: "Hours",
35
+ };
36
+ const UNIT_TO_MOMENT = {
37
+ s: "seconds",
38
+ m: "minutes",
39
+ h: "hours",
40
+ d: "days",
41
+ w: "weeks",
42
+ M: "months",
43
+ y: "years",
44
+ };
45
+ const DEFAULT_COMMONLY_USED_RANGES = [
46
+ { start: "now-15m", end: "now", label: "Last 15 minutes" },
47
+ { start: "now-30m", end: "now", label: "Last 30 minutes" },
48
+ { start: "now-1h", end: "now", label: "Last 1 hour" },
49
+ { start: "now-24h", end: "now", label: "Last 24 hours" },
50
+ { start: "now-7d", end: "now", label: "Last 7 days" },
51
+ { start: "now/d", end: "now", label: "Today" },
52
+ { start: "now/w", end: "now", label: "Week to date" },
53
+ { start: "now/M", end: "now", label: "Month to date" },
54
+ { start: "now/y", end: "now", label: "Year to date" },
55
+ { start: "now-1d/d", end: "now-1d/d", label: "Yesterday" },
56
+ ];
57
+ const DATE_MATH_PATTERN = /^now(?:(\+|-)(\d+)(ms|s|m|h|d|w|M|y))?(?:\/(s|m|h|d|w|M|y))?$/;
58
+ const REFRESH_UNIT_TO_MS = {
59
+ s: 1000,
60
+ m: 60 * 1000,
61
+ h: 60 * 60 * 1000,
62
+ };
63
+ const spin = keyframes `
64
+ 100% {
65
+ transform: rotate(360deg);
66
+ }
67
+ `;
68
+ const Root = styled.div `
69
+ display: inline-flex;
70
+ align-items: center;
71
+ gap: 6px;
72
+ max-width: ${({ $width }) => ($width === "restricted" ? "620px" : "none")};
73
+ width: ${({ $width }) => {
74
+ if ($width === "full")
75
+ return "100%";
76
+ if ($width === "restricted")
77
+ return "min(100%, 620px)";
78
+ return "auto";
79
+ }};
80
+ opacity: ${({ $disabled }) => ($disabled ? 0.55 : 1)};
81
+ pointer-events: ${({ $disabled }) => ($disabled ? "none" : "auto")};
82
+ `;
83
+ const ControlButton = styled.button `
84
+ box-sizing: border-box;
85
+ font-family: ${({ theme }) => theme.typography.fontFamily};
86
+ color: ${({ theme }) => theme.palette.text.primary};
87
+ background: ${({ theme, $variant }) => $variant === "text" ? "transparent" : theme.palette.input.background};
88
+ border: 1px solid
89
+ ${({ theme, $variant }) => $variant === "text" ? "transparent" : theme.palette.input.border};
90
+ border-radius: 5px;
91
+ cursor: pointer;
92
+ display: grid;
93
+ grid-template-columns: auto minmax(0, 1fr) auto;
94
+ align-items: center;
95
+ gap: ${({ $size }) => `${getControlSizeTokens($size).iconGap}px`};
96
+ min-height: ${({ $size }) => `${getControlSizeTokens($size).height}px`};
97
+ min-width: ${({ $width }) => $width === "auto" ? "240px" : $width === "full" ? "0" : "360px"};
98
+ width: ${({ $width }) => ($width === "full" ? "100%" : "auto")};
99
+ padding: ${({ $size }) => `0 ${getControlSizeTokens($size).inputPaddingX}px`};
100
+ text-align: left;
101
+ transition:
102
+ border-color 0.15s ease,
103
+ background-color 0.15s ease;
104
+
105
+ &:hover {
106
+ background: ${({ theme }) => theme.palette.action.hover};
107
+ }
108
+
109
+ &:focus-visible {
110
+ outline: 2px solid ${({ theme }) => theme.palette.primary.main};
111
+ outline-offset: 2px;
112
+ }
113
+
114
+ svg {
115
+ color: ${({ theme }) => theme.palette.text.secondary};
116
+ width: ${({ $size }) => `${getControlSizeTokens($size).iconSize}px`};
117
+ height: ${({ $size }) => `${getControlSizeTokens($size).iconSize}px`};
118
+ }
119
+ `;
120
+ const ControlLabel = styled.span `
121
+ display: block;
122
+ min-width: 0;
123
+ overflow: hidden;
124
+ text-overflow: ellipsis;
125
+ white-space: nowrap;
126
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).fontSize}px`};
127
+ `;
128
+ const ControlMeta = styled.span `
129
+ color: ${({ theme, $active }) => $active ? theme.palette.primary.main : theme.palette.text.secondary};
130
+ display: inline-flex;
131
+ align-items: center;
132
+ gap: 4px;
133
+ `;
134
+ const LoadingIcon = styled(Loader2Icon) `
135
+ animation: ${spin} 0.8s linear infinite;
136
+ `;
137
+ const Dropdown = styled.div `
138
+ width: min(680px, calc(100vw - 28px));
139
+ max-height: min(640px, calc(100vh - 80px));
140
+ overflow: auto;
141
+ font-family: ${({ theme }) => theme.typography.fontFamily};
142
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).fontSize}px`};
143
+ `;
144
+ const AutoOnlyDropdown = styled(Dropdown) `
145
+ width: min(360px, calc(100vw - 28px));
146
+ `;
147
+ const Panel = styled.div `
148
+ display: grid;
149
+ gap: 12px;
150
+ padding-top: 12px;
151
+ `;
152
+ const Section = styled.div `
153
+ display: grid;
154
+ gap: 8px;
155
+ `;
156
+ const SectionHeader = styled.div `
157
+ color: ${({ theme }) => theme.palette.text.secondary};
158
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).supportingFontSize}px`};
159
+ font-weight: 700;
160
+ letter-spacing: 0;
161
+ `;
162
+ const RangeGrid = styled.div `
163
+ display: grid;
164
+ grid-template-columns: repeat(2, minmax(0, 1fr));
165
+ gap: 6px;
166
+
167
+ @media (max-width: 520px) {
168
+ grid-template-columns: 1fr;
169
+ }
170
+ `;
171
+ const RangeButton = styled.button `
172
+ border: 1px solid
173
+ ${({ theme, $active }) => $active ? theme.palette.primary.main : theme.palette.divider};
174
+ border-radius: 5px;
175
+ background: ${({ theme, $active }) => $active ? `${theme.palette.primary.main}18` : "transparent"};
176
+ color: ${({ theme }) => theme.palette.text.primary};
177
+ cursor: pointer;
178
+ font-family: ${({ theme }) => theme.typography.fontFamily};
179
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).fontSize}px`};
180
+ min-height: ${({ $size }) => `${getControlSizeTokens($size).height}px`};
181
+ padding: 0 ${({ $size }) => `${getControlSizeTokens($size).inputPaddingX}px`};
182
+ text-align: left;
183
+
184
+ &:hover {
185
+ background: ${({ theme }) => theme.palette.action.hover};
186
+ }
187
+
188
+ &:focus-visible {
189
+ outline: 2px solid ${({ theme }) => theme.palette.primary.main};
190
+ outline-offset: 1px;
191
+ }
192
+ `;
193
+ const FormGrid = styled.div `
194
+ display: grid;
195
+ gap: 10px;
196
+ `;
197
+ const FieldRow = styled.label `
198
+ display: grid;
199
+ gap: 5px;
200
+ color: ${({ theme }) => theme.palette.text.secondary};
201
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).supportingFontSize}px`};
202
+ `;
203
+ const InlineRow = styled.div `
204
+ display: flex;
205
+ align-items: center;
206
+ flex-wrap: wrap;
207
+ gap: 8px;
208
+ `;
209
+ const NativeSelect = styled.select `
210
+ box-sizing: border-box;
211
+ min-height: ${({ $size }) => `${getControlSizeTokens($size).height}px`};
212
+ border-radius: 4px;
213
+ border: 1px solid ${({ theme }) => theme.palette.input.border};
214
+ background: ${({ theme }) => theme.palette.input.background};
215
+ color: ${({ theme }) => theme.palette.text.primary};
216
+ font-family: ${({ theme }) => theme.typography.fontFamily};
217
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).fontSize}px`};
218
+ padding: 0 ${({ $size }) => `${getControlSizeTokens($size).inputPaddingX}px`};
219
+ `;
220
+ const Footer = styled.div `
221
+ display: flex;
222
+ justify-content: flex-end;
223
+ gap: 8px;
224
+ padding-top: 4px;
225
+ `;
226
+ const Hint = styled.div `
227
+ color: ${({ theme }) => theme.palette.text.secondary};
228
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).supportingFontSize}px`};
229
+ `;
230
+ const DisabledDisplay = styled.div `
231
+ color: ${({ theme }) => theme.palette.text.secondary};
232
+ font-size: ${({ $size }) => `${getControlSizeTokens($size).fontSize}px`};
233
+ `;
234
+ const WindowButtonGroup = styled.div `
235
+ display: inline-flex;
236
+ align-items: center;
237
+ gap: 4px;
238
+ `;
239
+ const IconOnly = styled.span `
240
+ display: inline-flex;
241
+ align-items: center;
242
+
243
+ svg {
244
+ width: 14px;
245
+ height: 14px;
246
+ }
247
+ `;
248
+ const parseDateMath = (value, options = {}) => {
249
+ const match = DATE_MATH_PATTERN.exec(value);
250
+ if (!match) {
251
+ const absolute = moment(value);
252
+ return absolute.isValid() ? absolute : null;
253
+ }
254
+ const [, operator, amountText, unit, roundUnit] = match;
255
+ const next = moment();
256
+ if (operator && amountText && unit) {
257
+ const amount = Number(amountText);
258
+ const momentUnit = UNIT_TO_MOMENT[unit];
259
+ if (operator === "+") {
260
+ next.add(amount, momentUnit);
261
+ }
262
+ else {
263
+ next.subtract(amount, momentUnit);
264
+ }
265
+ }
266
+ if (roundUnit) {
267
+ const momentRoundUnit = UNIT_TO_MOMENT[roundUnit];
268
+ return options.roundUp
269
+ ? next.endOf(momentRoundUnit)
270
+ : next.startOf(momentRoundUnit);
271
+ }
272
+ return next;
273
+ };
274
+ const parseRange = (start, end) => ({
275
+ startMoment: parseDateMath(start),
276
+ endMoment: parseDateMath(end, { roundUp: true }),
277
+ });
278
+ const isRangeValid = (start, end) => {
279
+ const { startMoment, endMoment } = parseRange(start, end);
280
+ return Boolean((startMoment === null || startMoment === void 0 ? void 0 : startMoment.isValid()) &&
281
+ (endMoment === null || endMoment === void 0 ? void 0 : endMoment.isValid()) &&
282
+ !startMoment.isAfter(endMoment));
283
+ };
284
+ const toDate = (input) => {
285
+ if (!input)
286
+ return undefined;
287
+ return moment.isMoment(input) ? input.toDate() : input;
288
+ };
289
+ const serializeMoment = (value) => value.milliseconds(0).toISOString();
290
+ const pluralizeUnit = (unit, amount) => {
291
+ const label = UNIT_LABELS[unit];
292
+ return amount === 1 ? label.replace(/s$/, "") : label;
293
+ };
294
+ const getRelativeDescription = (start, end) => {
295
+ const startMatch = /^now-(\d+)(s|m|h|d|w|M|y)$/.exec(start);
296
+ const endMatch = /^now\+(\d+)(s|m|h|d|w|M|y)$/.exec(end);
297
+ if (startMatch && end === "now") {
298
+ const amount = Number(startMatch[1]);
299
+ const unit = startMatch[2];
300
+ return `Last ${amount} ${pluralizeUnit(unit, amount)}`;
301
+ }
302
+ if (start === "now" && endMatch) {
303
+ const amount = Number(endMatch[1]);
304
+ const unit = endMatch[2];
305
+ return `Next ${amount} ${pluralizeUnit(unit, amount)}`;
306
+ }
307
+ return null;
308
+ };
309
+ const getRangeLabel = (start, end, dateFormat, ranges) => {
310
+ const exactMatch = ranges.find((range) => range.start === start && range.end === end);
311
+ if (exactMatch)
312
+ return exactMatch.label;
313
+ const relative = getRelativeDescription(start, end);
314
+ if (relative)
315
+ return relative;
316
+ const { startMoment, endMoment } = parseRange(start, end);
317
+ if (!startMoment || !endMoment)
318
+ return `${start} - ${end}`;
319
+ return `${startMoment.format(dateFormat)} - ${endMoment.format(dateFormat)}`;
320
+ };
321
+ const msToUnitValue = (interval, preferredUnit) => {
322
+ const unit = preferredUnit ||
323
+ (interval % REFRESH_UNIT_TO_MS.h === 0
324
+ ? "h"
325
+ : interval % REFRESH_UNIT_TO_MS.m === 0
326
+ ? "m"
327
+ : "s");
328
+ return {
329
+ unit,
330
+ value: Math.max(1, Math.round(interval / REFRESH_UNIT_TO_MS[unit])),
331
+ };
332
+ };
333
+ const getRefreshInterval = (value, unit, minInterval) => Math.max(minInterval, value * REFRESH_UNIT_TO_MS[unit]);
334
+ const isDisabledConfig = (value) => typeof value === "object" && value !== null && "display" in value;
335
+ export const SuperDatePicker = ({ className, style, start, end, defaultStart = "now-15m", defaultEnd = "now", onTimeChange = () => { }, commonlyUsedRanges = DEFAULT_COMMONLY_USED_RANGES, recentlyUsedRanges = [], customQuickSelectPanels = [], isDisabled = false, isLoading = false, width = "restricted", size = DEFAULT_CONTROL_SIZE, variant = "outlined", compressed = false, showUpdateButton = true, updateButtonProps, quickSelectButtonProps, isQuickSelectOnly = false, isAutoRefreshOnly = false, isPaused = true, refreshInterval = 1000, refreshMinInterval = 0, refreshIntervalUnits, onRefresh, onRefreshChange, showTimeWindowButtons = false, minDate, maxDate, timeZoneDisplay, dateFormat = "MMM D, YYYY HH:mm:ss", "aria-label": ariaLabel = "Date range picker", }) => {
336
+ var _a, _b, _c, _d;
337
+ const resolvedSize = compressed ? "xs" : size;
338
+ const isControlled = useRef(start !== undefined || end !== undefined);
339
+ const disabled = Boolean(isDisabled);
340
+ const [internalStart, setInternalStart] = useState(defaultStart);
341
+ const [internalEnd, setInternalEnd] = useState(defaultEnd);
342
+ const currentStart = start !== null && start !== void 0 ? start : internalStart;
343
+ const currentEnd = end !== null && end !== void 0 ? end : internalEnd;
344
+ const [draftStart, setDraftStart] = useState(currentStart);
345
+ const [draftEnd, setDraftEnd] = useState(currentEnd);
346
+ const [opened, setOpened] = useState(false);
347
+ const [activeTab, setActiveTab] = useState("quick");
348
+ const [relativeAmount, setRelativeAmount] = useState(15);
349
+ const [relativeUnit, setRelativeUnit] = useState("m");
350
+ const [relativeDirection, setRelativeDirection] = useState("last");
351
+ const refreshParts = useMemo(() => msToUnitValue(refreshInterval, refreshIntervalUnits), [refreshInterval, refreshIntervalUnits]);
352
+ const [draftRefreshValue, setDraftRefreshValue] = useState(refreshParts.value);
353
+ const [draftRefreshUnit, setDraftRefreshUnit] = useState(refreshParts.unit);
354
+ const [draftPaused, setDraftPaused] = useState(isPaused);
355
+ const allKnownRanges = useMemo(() => [...commonlyUsedRanges, ...recentlyUsedRanges], [commonlyUsedRanges, recentlyUsedRanges]);
356
+ const displayLabel = useMemo(() => getRangeLabel(currentStart, currentEnd, dateFormat, allKnownRanges), [allKnownRanges, currentEnd, currentStart, dateFormat]);
357
+ const isDraftInvalid = !isRangeValid(draftStart, draftEnd);
358
+ const hasPendingChanges = draftStart !== currentStart || draftEnd !== currentEnd;
359
+ const absoluteDraftStartValue = (_b = (_a = parseDateMath(draftStart)) === null || _a === void 0 ? void 0 : _a.toISOString()) !== null && _b !== void 0 ? _b : draftStart;
360
+ const absoluteDraftEndValue = (_d = (_c = parseDateMath(draftEnd, { roundUp: true })) === null || _c === void 0 ? void 0 : _c.toISOString()) !== null && _d !== void 0 ? _d : draftEnd;
361
+ const disabledDisplay = isDisabledConfig(isDisabled)
362
+ ? isDisabled.display
363
+ : null;
364
+ useEffect(() => {
365
+ setDraftStart(currentStart);
366
+ setDraftEnd(currentEnd);
367
+ }, [currentStart, currentEnd]);
368
+ useEffect(() => {
369
+ setDraftRefreshValue(refreshParts.value);
370
+ setDraftRefreshUnit(refreshParts.unit);
371
+ }, [refreshParts.unit, refreshParts.value]);
372
+ useEffect(() => {
373
+ setDraftPaused(isPaused);
374
+ }, [isPaused]);
375
+ useEffect(() => {
376
+ if (!onRefresh || isPaused || disabled)
377
+ return;
378
+ let cancelled = false;
379
+ let timer;
380
+ const schedule = () => {
381
+ timer = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
382
+ try {
383
+ yield onRefresh({
384
+ start: currentStart,
385
+ end: currentEnd,
386
+ refreshInterval,
387
+ });
388
+ }
389
+ catch (_a) {
390
+ onRefreshChange === null || onRefreshChange === void 0 ? void 0 : onRefreshChange({
391
+ isPaused: true,
392
+ refreshInterval,
393
+ intervalUnits: refreshParts.unit,
394
+ });
395
+ return;
396
+ }
397
+ if (!cancelled)
398
+ schedule();
399
+ }), Math.max(refreshMinInterval, refreshInterval));
400
+ };
401
+ schedule();
402
+ return () => {
403
+ cancelled = true;
404
+ clearTimeout(timer);
405
+ };
406
+ }, [
407
+ currentEnd,
408
+ currentStart,
409
+ disabled,
410
+ isPaused,
411
+ onRefresh,
412
+ onRefreshChange,
413
+ refreshInterval,
414
+ refreshMinInterval,
415
+ refreshParts.unit,
416
+ ]);
417
+ const commitRange = useCallback((nextStart, nextEnd, options = {}) => {
418
+ const isInvalid = !isRangeValid(nextStart, nextEnd);
419
+ if (!isControlled.current && !isInvalid) {
420
+ setInternalStart(nextStart);
421
+ setInternalEnd(nextEnd);
422
+ }
423
+ setDraftStart(nextStart);
424
+ setDraftEnd(nextEnd);
425
+ onTimeChange({
426
+ start: nextStart,
427
+ end: nextEnd,
428
+ isInvalid,
429
+ isQuickSelection: Boolean(options.quickSelection),
430
+ });
431
+ if (options.close) {
432
+ setOpened(false);
433
+ }
434
+ }, [onTimeChange]);
435
+ const handleDraftStartChange = (nextValue) => {
436
+ const nextStart = nextValue || draftStart;
437
+ setDraftStart(nextStart);
438
+ if (showUpdateButton === false) {
439
+ commitRange(nextStart, draftEnd);
440
+ }
441
+ };
442
+ const handleDraftEndChange = (nextValue) => {
443
+ const nextEnd = nextValue || draftEnd;
444
+ setDraftEnd(nextEnd);
445
+ if (showUpdateButton === false) {
446
+ commitRange(draftStart, nextEnd);
447
+ }
448
+ };
449
+ const commitDraft = () => {
450
+ if (isDraftInvalid)
451
+ return;
452
+ commitRange(draftStart, draftEnd, { close: true });
453
+ };
454
+ const handleQuickSelect = (range) => {
455
+ commitRange(range.start, range.end, {
456
+ quickSelection: true,
457
+ close: true,
458
+ });
459
+ };
460
+ const applyRelativeRange = () => {
461
+ const safeAmount = Math.max(1, Math.floor(relativeAmount || 1));
462
+ const nextStart = relativeDirection === "last"
463
+ ? `now-${safeAmount}${relativeUnit}`
464
+ : "now";
465
+ const nextEnd = relativeDirection === "last"
466
+ ? "now"
467
+ : `now+${safeAmount}${relativeUnit}`;
468
+ if (showUpdateButton === false) {
469
+ commitRange(nextStart, nextEnd, { close: true });
470
+ return;
471
+ }
472
+ setDraftStart(nextStart);
473
+ setDraftEnd(nextEnd);
474
+ };
475
+ const applyRefresh = () => {
476
+ onRefreshChange === null || onRefreshChange === void 0 ? void 0 : onRefreshChange({
477
+ isPaused: draftPaused,
478
+ refreshInterval: getRefreshInterval(draftRefreshValue, draftRefreshUnit, refreshMinInterval),
479
+ intervalUnits: draftRefreshUnit,
480
+ });
481
+ };
482
+ const shiftWindow = (direction) => {
483
+ const { startMoment, endMoment } = parseRange(currentStart, currentEnd);
484
+ if (!startMoment || !endMoment)
485
+ return;
486
+ const duration = endMoment.diff(startMoment);
487
+ const amount = direction === "backward" ? -duration : duration;
488
+ commitRange(serializeMoment(startMoment.clone().add(amount, "milliseconds")), serializeMoment(endMoment.clone().add(amount, "milliseconds")));
489
+ };
490
+ const zoomWindow = (direction) => {
491
+ var _a;
492
+ const { startMoment, endMoment } = parseRange(currentStart, currentEnd);
493
+ if (!startMoment || !endMoment)
494
+ return;
495
+ const config = typeof showTimeWindowButtons === "object" ? showTimeWindowButtons : {};
496
+ const zoomFactor = (_a = config.zoomFactor) !== null && _a !== void 0 ? _a : 0.5;
497
+ const duration = endMoment.diff(startMoment);
498
+ const delta = duration * zoomFactor;
499
+ const halfDelta = delta / 2;
500
+ const modifier = direction === "out" ? 1 : -1;
501
+ commitRange(serializeMoment(startMoment.clone().subtract(halfDelta * modifier, "milliseconds")), serializeMoment(endMoment.clone().add(halfDelta * modifier, "milliseconds")));
502
+ };
503
+ const renderUpdateButton = (iconOnly = false) => {
504
+ var _a;
505
+ if (showUpdateButton === false)
506
+ return null;
507
+ return (_jsx(Button, Object.assign({ size: resolvedSize, variant: "contained", color: "primary", disabled: isDraftInvalid || !hasPendingChanges, onClick: commitDraft }, updateButtonProps, { children: iconOnly ? (_jsx(IconOnly, { children: _jsx(Search, {}) })) : ((_a = updateButtonProps === null || updateButtonProps === void 0 ? void 0 : updateButtonProps.children) !== null && _a !== void 0 ? _a : "Update") })));
508
+ };
509
+ const renderQuickRanges = (title, ranges, emptyLabel) => {
510
+ if (ranges.length === 0) {
511
+ return emptyLabel ? _jsx(Hint, { "$size": resolvedSize, children: emptyLabel }) : null;
512
+ }
513
+ return (_jsxs(Section, { children: [_jsx(SectionHeader, { "$size": resolvedSize, children: title }), _jsx(RangeGrid, { children: ranges.map((range) => (_jsx(RangeButton, { type: "button", "$size": resolvedSize, "$active": range.start === currentStart && range.end === currentEnd, onClick: () => handleQuickSelect(range), children: range.label }, `${range.label}-${range.start}-${range.end}`))) })] }));
514
+ };
515
+ const renderQuickPanel = () => (_jsxs(Panel, { children: [renderQuickRanges("Commonly used", commonlyUsedRanges), renderQuickRanges("Recently used", recentlyUsedRanges, "No recently used ranges."), customQuickSelectPanels.map((panel) => (_jsxs(Section, { children: [_jsx(SectionHeader, { "$size": resolvedSize, children: panel.title }), panel.content] }, panel.title))), timeZoneDisplay && _jsx(Hint, { "$size": resolvedSize, children: timeZoneDisplay })] }));
516
+ const renderAbsolutePanel = () => (_jsxs(Panel, { children: [_jsxs(FormGrid, { children: [_jsxs(FieldRow, { "$size": resolvedSize, children: ["Start", _jsx(DateInput, { value: absoluteDraftStartValue, onChange: handleDraftStartChange, size: resolvedSize, format: "YYYY-MM-DD HH:mm:ss", enableCalendar: true, clearable: false, min: toDate(minDate), max: toDate(maxDate) })] }), _jsxs(FieldRow, { "$size": resolvedSize, children: ["End", _jsx(DateInput, { value: absoluteDraftEndValue, onChange: handleDraftEndChange, size: resolvedSize, format: "YYYY-MM-DD HH:mm:ss", enableCalendar: true, clearable: false, min: toDate(minDate), max: toDate(maxDate) })] })] }), isDraftInvalid && (_jsx(Hint, { "$size": resolvedSize, children: "Choose a valid range where start is before end." })), _jsx(Footer, { children: renderUpdateButton() })] }));
517
+ const renderRelativePanel = () => (_jsxs(Panel, { children: [_jsxs(InlineRow, { children: [_jsx(SegmentedControl, { data: [
518
+ { value: "last", label: "Last" },
519
+ { value: "next", label: "Next" },
520
+ ], value: relativeDirection, onChange: (value) => setRelativeDirection(value), size: resolvedSize }), _jsx(Input, { type: "number", min: 1, value: relativeAmount, size: resolvedSize, width: 86, onChange: (event) => setRelativeAmount(Number(event.target.value)) }), _jsx(NativeSelect, { "$size": resolvedSize, value: relativeUnit, onChange: (event) => setRelativeUnit(event.target.value), children: Object.entries(UNIT_LABELS).map(([unit, label]) => (_jsx("option", { value: unit, children: label }, unit))) }), _jsx(Button, { type: "button", size: resolvedSize, variant: "outlined", onClick: applyRelativeRange, children: "Apply" })] }), _jsxs(Hint, { "$size": resolvedSize, children: ["Currently set to ", getRangeLabel(draftStart, draftEnd, dateFormat, allKnownRanges), "."] }), _jsx(Footer, { children: renderUpdateButton() })] }));
521
+ const renderRefreshPanel = () => (_jsxs(Panel, { children: [_jsx(InlineRow, { children: _jsx(Switch, { size: resolvedSize, value: !draftPaused, onChange: (checked) => setDraftPaused(!checked), label: "Refresh" }) }), _jsxs(InlineRow, { children: [_jsx(Input, { type: "number", min: 1, value: draftRefreshValue, size: resolvedSize, width: 90, onChange: (event) => setDraftRefreshValue(Math.max(1, Number(event.target.value))) }), _jsx(NativeSelect, { "$size": resolvedSize, value: draftRefreshUnit, onChange: (event) => setDraftRefreshUnit(event.target.value), children: Object.entries(REFRESH_UNIT_LABELS).map(([unit, label]) => (_jsx("option", { value: unit, children: label }, unit))) }), _jsx(Button, { type: "button", size: resolvedSize, variant: "outlined", onClick: applyRefresh, children: "Apply" })] }), _jsxs(Hint, { "$size": resolvedSize, children: ["Refresh is ", draftPaused ? "paused" : "on", ", interval set to", " ", draftRefreshValue, " ", REFRESH_UNIT_LABELS[draftRefreshUnit].toLowerCase(), "."] })] }));
522
+ const renderDropdownContent = () => {
523
+ if (isAutoRefreshOnly) {
524
+ return _jsx(AutoOnlyDropdown, { "$size": resolvedSize, children: renderRefreshPanel() });
525
+ }
526
+ if (isQuickSelectOnly) {
527
+ return _jsx(Dropdown, { "$size": resolvedSize, children: renderQuickPanel() });
528
+ }
529
+ const tabs = [
530
+ { value: "quick", label: "Quick" },
531
+ { value: "absolute", label: "Absolute" },
532
+ { value: "relative", label: "Relative" },
533
+ ...(onRefreshChange
534
+ ? [{ value: "refresh", label: "Refresh" }]
535
+ : []),
536
+ ];
537
+ return (_jsxs(Dropdown, { "$size": resolvedSize, children: [_jsx(SegmentedControl, { data: tabs, value: activeTab, onChange: setActiveTab, size: resolvedSize, fullWidth: true }), activeTab === "quick" && renderQuickPanel(), activeTab === "absolute" && renderAbsolutePanel(), activeTab === "relative" && renderRelativePanel(), activeTab === "refresh" && renderRefreshPanel()] }));
538
+ };
539
+ const renderTriggerLabel = () => {
540
+ if (disabledDisplay) {
541
+ return _jsx(DisabledDisplay, { "$size": resolvedSize, children: disabledDisplay });
542
+ }
543
+ if (isAutoRefreshOnly) {
544
+ return `Refresh ${isPaused ? "paused" : `every ${refreshParts.value}${refreshParts.unit}`}`;
545
+ }
546
+ if (isQuickSelectOnly) {
547
+ return "Quick select";
548
+ }
549
+ return displayLabel;
550
+ };
551
+ const timeWindowConfig = typeof showTimeWindowButtons === "object" ? showTimeWindowButtons : {};
552
+ const showWindowButtons = Boolean(showTimeWindowButtons) && !isAutoRefreshOnly;
553
+ return (_jsxs(Root, { className: className, style: style, "$width": width, "$disabled": disabled, children: [showWindowButtons && (_jsxs(WindowButtonGroup, { children: [_jsx(Button, { type: "button", size: resolvedSize, variant: "outlined", title: "Move time window backward", onClick: () => shiftWindow("backward"), children: _jsx(IconOnly, { children: _jsx(ChevronsLeft, {}) }) }), timeWindowConfig.showZoomIn && (_jsx(Button, { type: "button", size: resolvedSize, variant: "outlined", title: "Zoom in", onClick: () => zoomWindow("in"), children: _jsx(IconOnly, { children: _jsx(ZoomIn, {}) }) })), _jsx(Button, { type: "button", size: resolvedSize, variant: "outlined", title: "Zoom out", onClick: () => zoomWindow("out"), children: _jsx(IconOnly, { children: _jsx(ZoomOut, {}) }) }), _jsx(Button, { type: "button", size: resolvedSize, variant: "outlined", title: "Move time window forward", onClick: () => shiftWindow("forward"), children: _jsx(IconOnly, { children: _jsx(ChevronsRight, {}) }) })] })), _jsxs(Popover, { opened: opened, onChange: setOpened, disabled: disabled, position: "bottom-start", width: isAutoRefreshOnly ? 360 : undefined, transitionProps: { transition: "pop", duration: 120 }, children: [_jsx(Popover.Target, { children: _jsxs(ControlButton, Object.assign({ type: "button", "$size": resolvedSize, "$width": width, "$variant": variant, "aria-label": ariaLabel }, quickSelectButtonProps, { children: [isAutoRefreshOnly ? _jsx(RefreshCw, {}) : _jsx(CalendarClock, {}), _jsx(ControlLabel, { "$size": resolvedSize, children: renderTriggerLabel() }), _jsx(ControlMeta, { "$active": !isPaused && Boolean(onRefreshChange), children: isLoading ? _jsx(LoadingIcon, {}) : _jsx(ChevronDown, {}) })] })) }), _jsx(Popover.Dropdown, { children: renderDropdownContent() })] }), showUpdateButton === "iconOnly" && !isAutoRefreshOnly
554
+ ? renderUpdateButton(true)
555
+ : null] }));
556
+ };
557
+ export default SuperDatePicker;
@@ -0,0 +1,2 @@
1
+ export { default } from "./SuperDatePicker";
2
+ export * from "./SuperDatePicker";
@@ -0,0 +1,2 @@
1
+ export { default } from "./SuperDatePicker";
2
+ export * from "./SuperDatePicker";
@@ -2,8 +2,8 @@ import { CSSProperties, ReactNode } from "react";
2
2
  import { Size } from "../core";
3
3
  export type SwitchProps = {
4
4
  className?: string;
5
- onChange: (e: any) => void;
6
- size?: Exclude<Size, "xxs">;
5
+ onChange: (checked: boolean) => void;
6
+ size?: Size;
7
7
  label?: string;
8
8
  labelPosition?: "left" | "right";
9
9
  description?: ReactNode;