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