@monolith-forensics/monolith-ui 1.0.12 → 1.1.1
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.
- package/dist/Button/Button.d.ts +19 -0
- package/dist/Button/Button.js +332 -0
- package/dist/Button/index.d.ts +2 -0
- package/dist/Button/index.js +8 -0
- package/dist/Calendar/Calendar.d.ts +15 -0
- package/dist/Calendar/Calendar.js +232 -0
- package/dist/Calendar/CalendarStyles.d.ts +36 -0
- package/{src/components → dist}/Calendar/CalendarStyles.js +32 -52
- package/dist/Calendar/calendarHelpers.d.ts +53 -0
- package/dist/Calendar/calendarHelpers.js +181 -0
- package/dist/Calendar/index.d.ts +1 -0
- package/dist/Calendar/index.js +8 -0
- package/dist/CheckBox/CheckBox.d.ts +11 -0
- package/dist/CheckBox/CheckBox.js +34 -0
- package/dist/CheckBox/index.d.ts +1 -0
- package/dist/CheckBox/index.js +8 -0
- package/dist/DateInput/DateInput.d.ts +24 -0
- package/dist/DateInput/DateInput.js +511 -0
- package/dist/DateInput/index.d.ts +1 -0
- package/dist/DateInput/index.js +8 -0
- package/dist/DropDownMenu/DropDownMenu.d.ts +36 -0
- package/dist/DropDownMenu/DropDownMenu.js +212 -0
- package/dist/DropDownMenu/index.d.ts +1 -0
- package/dist/DropDownMenu/index.js +8 -0
- package/dist/Error/Error.d.ts +4 -0
- package/dist/Error/Error.js +38 -0
- package/dist/Error/index.d.ts +1 -0
- package/dist/Error/index.js +8 -0
- package/dist/FieldLabel/FieldLabel.d.ts +19 -0
- package/dist/FieldLabel/FieldLabel.js +119 -0
- package/dist/FieldLabel/index.js +8 -0
- package/dist/FileInputField/FileInputField.d.ts +18 -0
- package/dist/FileInputField/FileInputField.js +116 -0
- package/dist/FileInputField/index.d.ts +1 -0
- package/dist/FileInputField/index.js +8 -0
- package/dist/Flyout/Flyout.d.ts +10 -0
- package/dist/Flyout/Flyout.js +111 -0
- package/dist/Flyout/FlyoutHeader.d.ts +5 -0
- package/dist/Flyout/FlyoutHeader.js +12 -0
- package/dist/Flyout/FlyoutTitle.d.ts +2 -0
- package/dist/Flyout/FlyoutTitle.js +13 -0
- package/dist/Flyout/index.d.ts +3 -0
- package/dist/Flyout/index.js +12 -0
- package/dist/FormSection/FormSection.d.ts +9 -0
- package/dist/FormSection/FormSection.js +51 -0
- package/dist/FormSection/index.d.ts +1 -0
- package/dist/FormSection/index.js +8 -0
- package/dist/Grid/Grid.d.ts +6 -0
- package/dist/Grid/Grid.js +15 -0
- package/dist/Grid/index.d.ts +1 -0
- package/dist/Grid/index.js +8 -0
- package/dist/IconButton/IconButton.d.ts +5 -0
- package/dist/IconButton/IconButton.js +30 -0
- package/dist/IconButton/index.d.ts +1 -0
- package/dist/IconButton/index.js +8 -0
- package/dist/Input/Input.d.ts +21 -0
- package/dist/Input/Input.js +148 -0
- package/dist/Input/index.js +8 -0
- package/dist/Modal/Modal.d.ts +14 -0
- package/dist/Modal/Modal.js +134 -0
- package/dist/Modal/index.d.ts +1 -0
- package/dist/Modal/index.js +8 -0
- package/dist/Pill/Pill.d.ts +11 -0
- package/dist/Pill/Pill.js +146 -0
- package/dist/Pill/index.js +8 -0
- package/dist/SelectBox/SelectBox.d.ts +45 -0
- package/dist/SelectBox/SelectBox.js +469 -0
- package/dist/SelectBox/index.d.ts +1 -0
- package/dist/SelectBox/index.js +8 -0
- package/dist/Switch/Switch.d.ts +18 -0
- package/dist/Switch/Switch.js +157 -0
- package/dist/Switch/index.d.ts +1 -0
- package/dist/Switch/index.js +8 -0
- package/dist/TagBox/TagBox.d.ts +38 -0
- package/dist/TagBox/TagBox.js +440 -0
- package/dist/TagBox/TagBoxStyles.d.ts +11 -0
- package/dist/TagBox/TagBoxStyles.js +113 -0
- package/dist/TagBox/index.d.ts +1 -0
- package/dist/TagBox/index.js +8 -0
- package/dist/TextArea/TextArea.d.ts +16 -0
- package/dist/TextArea/TextArea.js +80 -0
- package/dist/TextArea/index.js +8 -0
- package/dist/TextAreaInput/TextAreaInput.d.ts +12 -0
- package/dist/TextAreaInput/TextAreaInput.js +23 -0
- package/dist/TextAreaInput/index.js +8 -0
- package/dist/TextInput/TextInput.d.ts +12 -0
- package/dist/TextInput/TextInput.js +30 -0
- package/dist/TextInput/index.js +8 -0
- package/dist/Tooltip/Tooltip.d.ts +12 -0
- package/dist/Tooltip/Tooltip.js +53 -0
- package/dist/Tooltip/index.d.ts +1 -0
- package/dist/Tooltip/index.js +8 -0
- package/dist/core/ArrowButton.d.ts +6 -0
- package/dist/core/ArrowButton.js +48 -0
- package/dist/core/ClearButton.d.ts +6 -0
- package/dist/core/ClearButton.js +48 -0
- package/dist/core/StyledContent.d.ts +7 -0
- package/dist/core/StyledContent.js +46 -0
- package/dist/core/StyledFloatContainer.d.ts +2 -0
- package/dist/core/StyledFloatContainer.js +10 -0
- package/dist/core/Types/Size.d.ts +2 -0
- package/dist/core/Types/Size.js +2 -0
- package/dist/core/Types/Variant.d.ts +2 -0
- package/dist/core/Types/Variant.js +2 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +14 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +51 -0
- package/package.json +15 -20
- package/.gitattributes +0 -2
- package/rollup.config.js +0 -10
- package/src/components/ArrowButton/ArrowButton.tsx +0 -54
- package/src/components/ArrowButton/index.tsx +0 -1
- package/src/components/Button/Button.tsx +0 -278
- package/src/components/Button/index.ts +0 -1
- package/src/components/Calendar/Calendar.js +0 -365
- package/src/components/Calendar/calendarHelpers.js +0 -194
- package/src/components/DateInput/DateInput.js +0 -583
- package/src/components/FieldLabel/FieldLabel.tsx +0 -152
- package/src/components/FileInputField/FileInputField.js +0 -171
- package/src/components/Input/Input.tsx +0 -141
- package/src/components/Pill/Pill.tsx +0 -144
- package/src/components/SelectBox/SelectBox.js +0 -543
- package/src/components/TagBox/TagBox.js +0 -563
- package/src/components/TextArea/TextArea.tsx +0 -70
- package/src/components/TextAreaInput/TextAreaInput.tsx +0 -48
- package/src/components/TextInput/TextInput.tsx +0 -50
- package/src/components/core/index.js +0 -16
- package/src/components/index.ts +0 -7
- package/src/components/theme/breakpoints.js +0 -11
- package/src/components/theme/components.js +0 -140
- package/src/components/theme/index.js +0 -77
- package/src/components/theme/shadows.js +0 -33
- package/src/components/theme/typography.js +0 -58
- package/src/components/theme/variants.js +0 -235
- package/src/index.ts +0 -1
- package/tsconfig.json +0 -109
- /package/{src/components/FieldLabel/index.ts → dist/FieldLabel/index.d.ts} +0 -0
- /package/{src/components/Input/index.tsx → dist/Input/index.d.ts} +0 -0
- /package/{src/components/Pill/index.ts → dist/Pill/index.d.ts} +0 -0
- /package/{src/components/TextArea/index.ts → dist/TextArea/index.d.ts} +0 -0
- /package/{src/components/TextAreaInput/index.ts → dist/TextAreaInput/index.d.ts} +0 -0
- /package/{src/components/TextInput/index.tsx → dist/TextInput/index.d.ts} +0 -0
|
@@ -1,583 +0,0 @@
|
|
|
1
|
-
import moment from "moment";
|
|
2
|
-
import { useFloating, flip, offset } from "@floating-ui/react";
|
|
3
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
import styled from "styled-components";
|
|
5
|
-
import FieldLabel from "../FieldLabel/FieldLabel.js";
|
|
6
|
-
import Calendar from "../Calendar/Calendar.js";
|
|
7
|
-
import {
|
|
8
|
-
ArrowButton,
|
|
9
|
-
ClearButton,
|
|
10
|
-
StyledContent,
|
|
11
|
-
StyledFloatContainer,
|
|
12
|
-
} from "../SelectBox/SelectBox.js";
|
|
13
|
-
|
|
14
|
-
const StyledInputContainer = styled.div`
|
|
15
|
-
position: relative;
|
|
16
|
-
|
|
17
|
-
caret-color: transparent;
|
|
18
|
-
user-select: none;
|
|
19
|
-
|
|
20
|
-
display: flex;
|
|
21
|
-
flex-direction: row;
|
|
22
|
-
align-items: center;
|
|
23
|
-
user-select: none;
|
|
24
|
-
|
|
25
|
-
pointer-events: all;
|
|
26
|
-
outline: none;
|
|
27
|
-
|
|
28
|
-
border-radius: 5px;
|
|
29
|
-
transition: border 0.1s ease-in-out;
|
|
30
|
-
border: 1px solid
|
|
31
|
-
${({ theme, variant }) => {
|
|
32
|
-
switch (variant) {
|
|
33
|
-
case "filled":
|
|
34
|
-
return "transparent";
|
|
35
|
-
case "outlined":
|
|
36
|
-
return theme.palette.input.border;
|
|
37
|
-
case "text":
|
|
38
|
-
return "transparent";
|
|
39
|
-
default:
|
|
40
|
-
return theme.palette.input.border;
|
|
41
|
-
}
|
|
42
|
-
}};
|
|
43
|
-
font-weight: 500;
|
|
44
|
-
color: ${(props) => props.theme.palette.text.primary};
|
|
45
|
-
font-size: ${({ size }) =>
|
|
46
|
-
size === "xs"
|
|
47
|
-
? "11px"
|
|
48
|
-
: size === "sm"
|
|
49
|
-
? "13px"
|
|
50
|
-
: size === "md"
|
|
51
|
-
? "15px"
|
|
52
|
-
: size === "lg"
|
|
53
|
-
? "17px"
|
|
54
|
-
: size === "xl"
|
|
55
|
-
? "19px"
|
|
56
|
-
: "11px"};
|
|
57
|
-
|
|
58
|
-
width: 100%;
|
|
59
|
-
height: ${({ size }) =>
|
|
60
|
-
size === "xs"
|
|
61
|
-
? "26px"
|
|
62
|
-
: size === "sm"
|
|
63
|
-
? "30px"
|
|
64
|
-
: size === "md"
|
|
65
|
-
? "36px"
|
|
66
|
-
: size === "lg"
|
|
67
|
-
? "42px"
|
|
68
|
-
: size === "xl"
|
|
69
|
-
? "50px"
|
|
70
|
-
: "26px"};
|
|
71
|
-
|
|
72
|
-
padding: ${({ size }) =>
|
|
73
|
-
size === "xs"
|
|
74
|
-
? "0px 8px"
|
|
75
|
-
: size === "sm"
|
|
76
|
-
? "0px 10px"
|
|
77
|
-
: size === "md"
|
|
78
|
-
? "0px 12px"
|
|
79
|
-
: size === "lg"
|
|
80
|
-
? "0px 14px"
|
|
81
|
-
: size === "xl"
|
|
82
|
-
? "0px 16px"
|
|
83
|
-
: "0px 8px"};
|
|
84
|
-
|
|
85
|
-
&[data-button-right="true"] {
|
|
86
|
-
padding-right: 36px;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
background-color: ${({ theme, variant }) => {
|
|
90
|
-
switch (variant) {
|
|
91
|
-
case "filled":
|
|
92
|
-
return theme.palette.input.background;
|
|
93
|
-
case "outlined":
|
|
94
|
-
return theme.palette.input.background;
|
|
95
|
-
case "text":
|
|
96
|
-
return "transparent";
|
|
97
|
-
default:
|
|
98
|
-
return theme.palette.input.background;
|
|
99
|
-
}
|
|
100
|
-
}};
|
|
101
|
-
|
|
102
|
-
&[readOnly] {
|
|
103
|
-
cursor: pointer;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
& [data-has-space="true"] {
|
|
107
|
-
padding-left: 4px;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
& [data-selected="true"] {
|
|
111
|
-
background-color: ${(props) => props.theme.palette.primary.main}50;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
&[data-empty="true"] {
|
|
115
|
-
color: ${(props) => props.theme.palette.input.placeholder};
|
|
116
|
-
div {
|
|
117
|
-
color: ${(props) => props.theme.palette.input.placeholder};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
& [data-default-btn="true"] {
|
|
122
|
-
color: ${(props) => props.theme.palette.text.secondary};
|
|
123
|
-
div {
|
|
124
|
-
color: ${(props) => props.theme.palette.text.secondary};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
&:focus {
|
|
129
|
-
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
130
|
-
}
|
|
131
|
-
`;
|
|
132
|
-
|
|
133
|
-
const InputSegment = styled.div`
|
|
134
|
-
user-select: none;
|
|
135
|
-
display: flex;
|
|
136
|
-
flex-direction: row;
|
|
137
|
-
align-items: center;
|
|
138
|
-
pointer-events: all;
|
|
139
|
-
outline: none;
|
|
140
|
-
border: none;
|
|
141
|
-
padding: 0;
|
|
142
|
-
|
|
143
|
-
height: ${({ size }) =>
|
|
144
|
-
size === "xs"
|
|
145
|
-
? "22px"
|
|
146
|
-
: size === "sm"
|
|
147
|
-
? "26px"
|
|
148
|
-
: size === "md"
|
|
149
|
-
? "32px"
|
|
150
|
-
: size === "lg"
|
|
151
|
-
? "38px"
|
|
152
|
-
: size === "xl"
|
|
153
|
-
? "46px"
|
|
154
|
-
: "22px"};
|
|
155
|
-
|
|
156
|
-
height: 100%;
|
|
157
|
-
|
|
158
|
-
background-color: transparent;
|
|
159
|
-
color: ${(props) => props.theme.palette.text.primary};
|
|
160
|
-
|
|
161
|
-
::placeholder {
|
|
162
|
-
font-size: ${({ size }) =>
|
|
163
|
-
size === "xs"
|
|
164
|
-
? "10px"
|
|
165
|
-
: size === "sm"
|
|
166
|
-
? "12px"
|
|
167
|
-
: size === "md"
|
|
168
|
-
? "14px"
|
|
169
|
-
: size === "lg"
|
|
170
|
-
? "16px"
|
|
171
|
-
: size === "xl"
|
|
172
|
-
? "18px"
|
|
173
|
-
: "10px"};
|
|
174
|
-
}
|
|
175
|
-
`;
|
|
176
|
-
|
|
177
|
-
function parseTimestamp(timestamp, format, utc = false) {
|
|
178
|
-
// Define patterns to identify datetime components and their placeholders
|
|
179
|
-
const patterns = [
|
|
180
|
-
{ pattern: "YYYY", placeholder: "YYYY", type: "year", momentType: "year" },
|
|
181
|
-
{ pattern: "MM", placeholder: "MM", type: "month", momentType: "month" },
|
|
182
|
-
{ pattern: "DD", placeholder: "DD", type: "day", momentType: "date" },
|
|
183
|
-
{ pattern: "HH", placeholder: "HH", type: "hour", momentType: "hour" },
|
|
184
|
-
{ pattern: "h", placeholder: "h", type: "hour", momentType: "hour" },
|
|
185
|
-
{ pattern: "mm", placeholder: "mm", type: "minute", momentType: "minute" },
|
|
186
|
-
{ pattern: "ss", placeholder: "ss", type: "second", momentType: "second" },
|
|
187
|
-
{
|
|
188
|
-
pattern: "SSS",
|
|
189
|
-
placeholder: "SSS",
|
|
190
|
-
type: "millisecond",
|
|
191
|
-
moment: "millisecond",
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
pattern: "A",
|
|
195
|
-
placeholder: "AM/PM",
|
|
196
|
-
type: "meridiem",
|
|
197
|
-
momentType: "meridiem",
|
|
198
|
-
},
|
|
199
|
-
{ pattern: "Z", placeholder: "Z", type: "timezone", moment: "timezone" },
|
|
200
|
-
];
|
|
201
|
-
|
|
202
|
-
// Helper function to split format into datetime components and separators
|
|
203
|
-
function splitFormat(format) {
|
|
204
|
-
return format.split(/(YYYY|MM|DD|HH|h|mm|ss|SSS|Z)/).filter((s) => s);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Helper function to match segments to their placeholders and types
|
|
208
|
-
function matchSegment(segment) {
|
|
209
|
-
const pattern = patterns.find((p) => p.pattern === segment);
|
|
210
|
-
return pattern
|
|
211
|
-
? pattern
|
|
212
|
-
: { pattern: segment, placeholder: segment, type: "separator" };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const segments = splitFormat(format).map((segment, i) => {
|
|
216
|
-
const { pattern, placeholder, type, momentType } = matchSegment(segment);
|
|
217
|
-
const value = timestamp
|
|
218
|
-
? utc === true
|
|
219
|
-
? moment.utc(timestamp).format(pattern)
|
|
220
|
-
: moment(timestamp).format(pattern)
|
|
221
|
-
: placeholder;
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
value,
|
|
225
|
-
text: value,
|
|
226
|
-
placeholder,
|
|
227
|
-
type,
|
|
228
|
-
momentType,
|
|
229
|
-
index: i,
|
|
230
|
-
};
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
return segments;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const DateInput = styled(
|
|
237
|
-
({
|
|
238
|
-
className,
|
|
239
|
-
defaultValue,
|
|
240
|
-
format = "YYYY-MM-DD HH:mm:ss",
|
|
241
|
-
label = null,
|
|
242
|
-
description = null,
|
|
243
|
-
arrow = true,
|
|
244
|
-
size = "sm",
|
|
245
|
-
variant = "outlined",
|
|
246
|
-
clearable = false,
|
|
247
|
-
required = false,
|
|
248
|
-
onChange = () => {},
|
|
249
|
-
min = null,
|
|
250
|
-
max = null,
|
|
251
|
-
error = false,
|
|
252
|
-
width = null,
|
|
253
|
-
enableCalendar = false,
|
|
254
|
-
utc = false,
|
|
255
|
-
closeOnSelect = true,
|
|
256
|
-
}) => {
|
|
257
|
-
const [value, setValue] = useState(defaultValue);
|
|
258
|
-
const [selectedSegment, setSelectedSegment] = useState(null);
|
|
259
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
260
|
-
|
|
261
|
-
// Check if format is date only and does not include time
|
|
262
|
-
const isDateOnly = format.match(/(HH|h|mm|ss|SSS|A|Z)/) === null;
|
|
263
|
-
|
|
264
|
-
const mainRef = useRef(null);
|
|
265
|
-
|
|
266
|
-
const typedKeys = useRef("");
|
|
267
|
-
|
|
268
|
-
const { refs, floatingStyles } = useFloating({
|
|
269
|
-
open: isOpen,
|
|
270
|
-
onOpenChange: setIsOpen,
|
|
271
|
-
placement: "bottom-start",
|
|
272
|
-
strategy: "absolute",
|
|
273
|
-
// Handle collisions with the viewport
|
|
274
|
-
middleware: [flip(), offset(5)],
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
const segments = useMemo(
|
|
278
|
-
() =>
|
|
279
|
-
parseTimestamp(value ? moment(value).toISOString() : null, format, utc),
|
|
280
|
-
[value, format]
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
const checkValidRange = (value) => {
|
|
284
|
-
if (min && moment(value).isBefore(min)) return false;
|
|
285
|
-
if (max && moment(value).isAfter(max)) return false;
|
|
286
|
-
return true;
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
const toggleOpen = () => {
|
|
290
|
-
setIsOpen((prev) => {
|
|
291
|
-
return !prev;
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
const handleClear = (e) => {
|
|
296
|
-
e.preventDefault();
|
|
297
|
-
e.stopPropagation();
|
|
298
|
-
|
|
299
|
-
setValue(null);
|
|
300
|
-
onChange?.(null);
|
|
301
|
-
setIsOpen(false);
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
const handleSegmentClick = (e, segment) => {
|
|
305
|
-
e.stopPropagation();
|
|
306
|
-
e.preventDefault();
|
|
307
|
-
if (segment.type === "separator") return;
|
|
308
|
-
mainRef.current.querySelector("div[data-type='input']").focus();
|
|
309
|
-
setSelectedSegment(segment);
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
const handleContainerClick = (e) => {
|
|
313
|
-
e.stopPropagation();
|
|
314
|
-
e.preventDefault();
|
|
315
|
-
mainRef.current.querySelector("div[data-type='input']").focus();
|
|
316
|
-
toggleOpen();
|
|
317
|
-
setIsOpen(true);
|
|
318
|
-
setSelectedSegment(segments[0]);
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
const nextSegment = () => {
|
|
322
|
-
setSelectedSegment((prev) => {
|
|
323
|
-
const next = segments[prev.index + 2];
|
|
324
|
-
return next || prev;
|
|
325
|
-
});
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const prevSegment = () => {
|
|
329
|
-
setSelectedSegment((prev) => {
|
|
330
|
-
const next = segments[prev.index - 2];
|
|
331
|
-
return next || prev;
|
|
332
|
-
});
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
// prevent click and drag selection
|
|
336
|
-
const handleMouseDown = (e) => {
|
|
337
|
-
e.preventDefault();
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const handleKeyDown = (e) => {
|
|
341
|
-
if (!selectedSegment) return;
|
|
342
|
-
// tab
|
|
343
|
-
if (e.key === "Tab") {
|
|
344
|
-
setSelectedSegment(null);
|
|
345
|
-
setIsOpen(false);
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
// Right Arrow
|
|
349
|
-
if (e.key === "ArrowRight") {
|
|
350
|
-
e.preventDefault();
|
|
351
|
-
|
|
352
|
-
setSelectedSegment((prev) => {
|
|
353
|
-
const next = segments[prev.index + 2];
|
|
354
|
-
return next || prev;
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
// Left Arrow
|
|
358
|
-
if (e.key === "ArrowLeft") {
|
|
359
|
-
e.preventDefault();
|
|
360
|
-
setSelectedSegment((prev) => {
|
|
361
|
-
const next = segments[prev.index - 2];
|
|
362
|
-
return next || prev;
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// Up Arrow
|
|
367
|
-
if (e.key === "ArrowUp") {
|
|
368
|
-
e.preventDefault();
|
|
369
|
-
|
|
370
|
-
setValue((prev) => {
|
|
371
|
-
let newValue = prev
|
|
372
|
-
? moment(prev).add(1, selectedSegment.type).toISOString()
|
|
373
|
-
: moment().toISOString();
|
|
374
|
-
if (!checkValidRange(newValue)) return prev;
|
|
375
|
-
if (isDateOnly) {
|
|
376
|
-
newValue = moment(newValue).format("YYYY-MM-DD");
|
|
377
|
-
}
|
|
378
|
-
onChange?.(newValue);
|
|
379
|
-
return newValue;
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// Down Arrow
|
|
384
|
-
if (e.key === "ArrowDown") {
|
|
385
|
-
e.preventDefault();
|
|
386
|
-
|
|
387
|
-
setValue((prev) => {
|
|
388
|
-
let newValue = prev
|
|
389
|
-
? moment(prev).subtract(1, selectedSegment.type).toISOString()
|
|
390
|
-
: moment().toISOString();
|
|
391
|
-
if (!checkValidRange(newValue)) return prev;
|
|
392
|
-
|
|
393
|
-
if (isDateOnly) {
|
|
394
|
-
newValue = moment(newValue).format("YYYY-MM-DD");
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
onChange?.(newValue);
|
|
398
|
-
return newValue;
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// only allow numbers
|
|
403
|
-
if (e.key.match(/[0-9]/)) {
|
|
404
|
-
e.preventDefault();
|
|
405
|
-
const segmentLength = selectedSegment.text.length;
|
|
406
|
-
|
|
407
|
-
typedKeys.current += e.key;
|
|
408
|
-
let tempValue = typedKeys.current;
|
|
409
|
-
|
|
410
|
-
if (
|
|
411
|
-
["month", "day"].includes(selectedSegment.type) &&
|
|
412
|
-
Array.from(tempValue).every((c) => c === "0")
|
|
413
|
-
) {
|
|
414
|
-
tempValue = "01";
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
setValue((prev) => {
|
|
418
|
-
const newValue = moment(prev)
|
|
419
|
-
.set(
|
|
420
|
-
selectedSegment.momentType,
|
|
421
|
-
parseInt(tempValue, 10) -
|
|
422
|
-
(selectedSegment.type === "month" ? 1 : 0)
|
|
423
|
-
)
|
|
424
|
-
.toISOString();
|
|
425
|
-
if (!checkValidRange(newValue)) return prev;
|
|
426
|
-
onChange?.(newValue);
|
|
427
|
-
return newValue;
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
if (typedKeys.current.length === segmentLength) {
|
|
431
|
-
nextSegment();
|
|
432
|
-
typedKeys.current = "";
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
e.preventDefault();
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
// Close on outside click
|
|
440
|
-
useEffect(() => {
|
|
441
|
-
const close = (e) => {
|
|
442
|
-
if (
|
|
443
|
-
refs.floating.current && // Check if the floating element exists
|
|
444
|
-
e.target !== refs.reference.current && // Check if the target is not the reference (input)
|
|
445
|
-
!refs.reference.current.contains(e.target) && // Check if the target is not inside the reference (input)
|
|
446
|
-
!refs.floating.current.contains(e.target) // Check if the target is not inside the floating element (content)
|
|
447
|
-
) {
|
|
448
|
-
setIsOpen(false);
|
|
449
|
-
}
|
|
450
|
-
setSelectedSegment(null); // clear selected segment when clicked outside component
|
|
451
|
-
};
|
|
452
|
-
document.addEventListener("click", close);
|
|
453
|
-
return () => document.removeEventListener("click", close);
|
|
454
|
-
}, [refs.floating]);
|
|
455
|
-
|
|
456
|
-
// const contentWidth =
|
|
457
|
-
// refs?.reference?.current?.getClientRects?.()?.[0]?.width || "100%";
|
|
458
|
-
|
|
459
|
-
return (
|
|
460
|
-
<div>
|
|
461
|
-
{label && (
|
|
462
|
-
<FieldLabel
|
|
463
|
-
error={error}
|
|
464
|
-
asterisk={required}
|
|
465
|
-
size={size}
|
|
466
|
-
description={description}
|
|
467
|
-
>
|
|
468
|
-
{label}
|
|
469
|
-
</FieldLabel>
|
|
470
|
-
)}
|
|
471
|
-
<StyledInputContainer
|
|
472
|
-
ref={(ref) => {
|
|
473
|
-
mainRef.current = ref;
|
|
474
|
-
refs.setReference(ref);
|
|
475
|
-
}}
|
|
476
|
-
onClick={handleContainerClick}
|
|
477
|
-
onMouseDown={handleMouseDown}
|
|
478
|
-
onKeyDown={handleKeyDown}
|
|
479
|
-
onFocus={(e) => {
|
|
480
|
-
e.preventDefault();
|
|
481
|
-
setSelectedSegment(segments[0]);
|
|
482
|
-
}}
|
|
483
|
-
data-empty={!value}
|
|
484
|
-
role="textbox"
|
|
485
|
-
size={size}
|
|
486
|
-
variant={variant}
|
|
487
|
-
width={width}
|
|
488
|
-
data-button-right={arrow || clearable}
|
|
489
|
-
>
|
|
490
|
-
{segments.map((segment, i) => {
|
|
491
|
-
if (segment.type === "separator") {
|
|
492
|
-
return (
|
|
493
|
-
<div
|
|
494
|
-
className="separator"
|
|
495
|
-
key={i}
|
|
496
|
-
tabIndex={-1}
|
|
497
|
-
onClick={(e) => {
|
|
498
|
-
e.preventDefault();
|
|
499
|
-
e.stopPropagation();
|
|
500
|
-
}}
|
|
501
|
-
onFocus={(e) => e.preventDefault()}
|
|
502
|
-
onPointerDown={(e) => e.preventDefault()}
|
|
503
|
-
data-type="separator"
|
|
504
|
-
data-identifier={segment.type}
|
|
505
|
-
data-has-space={segment.text.includes(" ")}
|
|
506
|
-
data-placeholder={segment.placeholder}
|
|
507
|
-
data-value={segment.value}
|
|
508
|
-
>
|
|
509
|
-
{segment.text}
|
|
510
|
-
</div>
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
return (
|
|
514
|
-
<InputSegment
|
|
515
|
-
className={"input"}
|
|
516
|
-
contentEditable
|
|
517
|
-
suppressContentEditableWarning
|
|
518
|
-
key={i}
|
|
519
|
-
tabIndex={i === 0 ? 0 : -1}
|
|
520
|
-
onClick={(e) => handleSegmentClick(e, segment)}
|
|
521
|
-
data-type="input"
|
|
522
|
-
size={size}
|
|
523
|
-
data-identifier={segment.type}
|
|
524
|
-
data-has-space={segment.text.includes(" ")}
|
|
525
|
-
data-placeholder={segment.placeholder}
|
|
526
|
-
data-value={segment.value}
|
|
527
|
-
data-selected={selectedSegment?.index === segment.index}
|
|
528
|
-
>
|
|
529
|
-
{value ? segment.text : segment.placeholder}
|
|
530
|
-
</InputSegment>
|
|
531
|
-
);
|
|
532
|
-
})}
|
|
533
|
-
{utc && <div style={{ marginLeft: 5 }}>UTC</div>}
|
|
534
|
-
{clearable && value ? (
|
|
535
|
-
<ClearButton onClick={handleClear} />
|
|
536
|
-
) : arrow ? (
|
|
537
|
-
<ArrowButton />
|
|
538
|
-
) : null}
|
|
539
|
-
</StyledInputContainer>
|
|
540
|
-
{enableCalendar && isOpen && (
|
|
541
|
-
<StyledFloatContainer ref={refs.setFloating} style={floatingStyles}>
|
|
542
|
-
<StyledContent maxDropdownHeight="fit-content">
|
|
543
|
-
<div>
|
|
544
|
-
<Calendar
|
|
545
|
-
key={1}
|
|
546
|
-
date={moment(value).toDate()}
|
|
547
|
-
clearable={false}
|
|
548
|
-
min={min}
|
|
549
|
-
max={max}
|
|
550
|
-
// hourFormat={hourFormat}
|
|
551
|
-
onDateChanged={(date) => {
|
|
552
|
-
setValue((prev) => {
|
|
553
|
-
// make copy of prev variable
|
|
554
|
-
const oldValue = moment(prev).toISOString();
|
|
555
|
-
|
|
556
|
-
const result = `${moment(date).format(
|
|
557
|
-
"YYYY-MM-DD"
|
|
558
|
-
)}T${moment(prev || undefined).format("HH:mm:ss")}`;
|
|
559
|
-
|
|
560
|
-
let isoResult = moment(result).toISOString();
|
|
561
|
-
|
|
562
|
-
if (!checkValidRange(result)) return oldValue;
|
|
563
|
-
|
|
564
|
-
if (isDateOnly) {
|
|
565
|
-
isoResult = moment(result).format("YYYY-MM-DD");
|
|
566
|
-
}
|
|
567
|
-
onChange?.(isoResult);
|
|
568
|
-
setIsOpen(closeOnSelect ? false : true);
|
|
569
|
-
return isoResult;
|
|
570
|
-
});
|
|
571
|
-
}}
|
|
572
|
-
includeTime={false}
|
|
573
|
-
/>
|
|
574
|
-
</div>
|
|
575
|
-
</StyledContent>
|
|
576
|
-
</StyledFloatContainer>
|
|
577
|
-
)}
|
|
578
|
-
</div>
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
)``;
|
|
582
|
-
|
|
583
|
-
export default DateInput;
|