@monolith-forensics/monolith-ui 1.1.29 → 1.1.31
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.js +327 -0
- package/dist/Button/index.js +1 -0
- package/dist/Calendar/Calendar.js +204 -0
- package/dist/Calendar/CalendarStyles.js +164 -0
- package/dist/Calendar/calendarHelpers.js +169 -0
- package/dist/Calendar/index.js +1 -0
- package/dist/CheckBox/CheckBox.js +41 -0
- package/dist/CheckBox/index.js +1 -0
- package/dist/DateInput/DateInput.js +504 -0
- package/dist/DateInput/index.js +1 -0
- package/dist/DropDownMenu/DropDownMenu.js +208 -0
- package/dist/DropDownMenu/index.js +1 -0
- package/dist/Error/Error.js +33 -0
- package/dist/Error/index.js +1 -0
- package/dist/FieldLabel/FieldLabel.js +90 -0
- package/dist/FieldLabel/index.js +1 -0
- package/dist/FileInputField/FileInputField.js +112 -0
- package/dist/FileInputField/index.js +1 -0
- package/dist/Flyout/Flyout.js +106 -0
- package/dist/Flyout/FlyoutHeader.js +7 -0
- package/dist/Flyout/FlyoutTitle.js +8 -0
- package/dist/Flyout/index.js +3 -0
- package/dist/FormSection/FormSection.js +46 -0
- package/dist/FormSection/index.js +1 -0
- package/dist/Grid/Grid.js +13 -0
- package/dist/Grid/index.js +1 -0
- package/dist/IconButton/IconButton.js +25 -0
- package/dist/IconButton/index.js +1 -0
- package/dist/Input/Input.js +144 -0
- package/dist/Input/index.js +1 -0
- package/dist/Modal/Modal.js +105 -0
- package/dist/Modal/index.js +1 -0
- package/dist/MonolithUIProvider/GlobalStyle.js +51 -0
- package/dist/MonolithUIProvider/MonolithUIProvider.js +23 -0
- package/dist/MonolithUIProvider/index.js +3 -0
- package/dist/MonolithUIProvider/useMonolithUITheme.js +10 -0
- package/dist/Pill/Pill.js +147 -0
- package/dist/Pill/index.js +1 -0
- package/dist/SelectBox/SelectBox.js +471 -0
- package/dist/SelectBox/index.js +1 -0
- package/dist/Switch/Switch.js +129 -0
- package/dist/Switch/index.js +1 -0
- package/dist/Table/Table.js +707 -0
- package/dist/Table/index.js +2 -0
- package/dist/TagBox/TagBox.js +585 -0
- package/dist/TagBox/TagBoxStyles.js +107 -0
- package/dist/TagBox/index.js +1 -0
- package/dist/TextArea/TextArea.js +76 -0
- package/dist/TextArea/index.js +1 -0
- package/dist/TextAreaInput/TextAreaInput.js +9 -0
- package/dist/TextAreaInput/index.js +1 -0
- package/dist/TextInput/TextInput.js +26 -0
- package/dist/TextInput/index.js +1 -0
- package/dist/Tooltip/Tooltip.js +25 -0
- package/dist/Tooltip/index.js +1 -0
- package/dist/core/ArrowButton.js +43 -0
- package/dist/core/ClearButton.js +43 -0
- package/dist/core/StyledContent.js +42 -0
- package/dist/core/StyledFloatContainer.js +5 -0
- package/dist/core/Types/Size.js +1 -0
- package/dist/core/Types/Variant.js +1 -0
- package/dist/core/index.js +4 -0
- package/dist/index.js +26 -0
- package/dist/theme/index.js +9 -0
- package/dist/theme/typography.js +57 -0
- package/dist/theme/variants.js +270 -0
- package/package.json +1 -1
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import styled from "styled-components";
|
|
14
|
+
import { useFloating, flip, offset } from "@floating-ui/react";
|
|
15
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
16
|
+
import { Input, Tooltip, FieldLabel, Pill } from "..";
|
|
17
|
+
import { ArrowButton, ClearButton, StyledFloatContainer, StyledContent, } from "../core";
|
|
18
|
+
const StyledInputContainer = styled.div `
|
|
19
|
+
position: relative;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
|
|
22
|
+
user-select: none;
|
|
23
|
+
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: row;
|
|
26
|
+
align-items: center;
|
|
27
|
+
user-select: none;
|
|
28
|
+
|
|
29
|
+
pointer-events: all;
|
|
30
|
+
outline: none;
|
|
31
|
+
|
|
32
|
+
padding: ${({ size }) => size === "xs"
|
|
33
|
+
? "2px 8px"
|
|
34
|
+
: size === "sm"
|
|
35
|
+
? "4px 10px"
|
|
36
|
+
: size === "md"
|
|
37
|
+
? "6px 12px"
|
|
38
|
+
: size === "lg"
|
|
39
|
+
? "7px 14px"
|
|
40
|
+
: size === "xl"
|
|
41
|
+
? "8px 16px"
|
|
42
|
+
: "4px 10px"};
|
|
43
|
+
|
|
44
|
+
border-radius: 5px;
|
|
45
|
+
transition: border 0.1s ease-in-out;
|
|
46
|
+
border: 1px solid
|
|
47
|
+
${({ theme, variant }) => {
|
|
48
|
+
switch (variant) {
|
|
49
|
+
case "filled":
|
|
50
|
+
return "transparent";
|
|
51
|
+
case "outlined":
|
|
52
|
+
return theme.palette.input.border;
|
|
53
|
+
case "text":
|
|
54
|
+
return "transparent";
|
|
55
|
+
default:
|
|
56
|
+
return theme.palette.input.border;
|
|
57
|
+
}
|
|
58
|
+
}};
|
|
59
|
+
font-weight: 500;
|
|
60
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
61
|
+
font-size: ${({ size }) => size === "xs"
|
|
62
|
+
? "12px"
|
|
63
|
+
: size === "sm"
|
|
64
|
+
? "14px"
|
|
65
|
+
: size === "md"
|
|
66
|
+
? "16px"
|
|
67
|
+
: size === "lg"
|
|
68
|
+
? "18px"
|
|
69
|
+
: size === "xl"
|
|
70
|
+
? "20px"
|
|
71
|
+
: "12px"};
|
|
72
|
+
|
|
73
|
+
width: 100%;
|
|
74
|
+
min-height: ${({ size }) => size === "xs"
|
|
75
|
+
? "26px"
|
|
76
|
+
: size === "sm"
|
|
77
|
+
? "30px"
|
|
78
|
+
: size === "md"
|
|
79
|
+
? "36px"
|
|
80
|
+
: size === "lg"
|
|
81
|
+
? "42px"
|
|
82
|
+
: size === "xl"
|
|
83
|
+
? "50px"
|
|
84
|
+
: "26px"};
|
|
85
|
+
|
|
86
|
+
&[data-button-right="true"] {
|
|
87
|
+
padding-right: 36px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
background-color: ${({ theme, variant }) => {
|
|
91
|
+
switch (variant) {
|
|
92
|
+
case "filled":
|
|
93
|
+
return theme.palette.input.background;
|
|
94
|
+
case "outlined":
|
|
95
|
+
return theme.palette.input.background;
|
|
96
|
+
case "text":
|
|
97
|
+
return "transparent";
|
|
98
|
+
default:
|
|
99
|
+
return theme.palette.input.background;
|
|
100
|
+
}
|
|
101
|
+
}};
|
|
102
|
+
|
|
103
|
+
&[readOnly] {
|
|
104
|
+
cursor: pointer;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
& [data-has-space="true"] {
|
|
108
|
+
padding-left: 4px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
& [data-selected="true"] {
|
|
112
|
+
background-color: ${(props) => props.theme.palette.primary.main}50;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
&[data-empty="true"] {
|
|
116
|
+
color: ${(props) => props.theme.palette.input.placeholder};
|
|
117
|
+
div {
|
|
118
|
+
color: ${(props) => props.theme.palette.input.placeholder};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
& [data-default-btn="true"] {
|
|
123
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
124
|
+
div {
|
|
125
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
&[data-open="true"] {
|
|
130
|
+
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&:focus-within {
|
|
134
|
+
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&:focus {
|
|
138
|
+
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
139
|
+
}
|
|
140
|
+
`;
|
|
141
|
+
// styled input with forwardRef
|
|
142
|
+
const StyledInput = styled((_a) => {
|
|
143
|
+
var { className, inputRef } = _a, props = __rest(_a, ["className", "inputRef"]);
|
|
144
|
+
return (_jsx(Input, Object.assign({ ref: inputRef, className: className + " mfTagBox-input" }, props)));
|
|
145
|
+
}) `
|
|
146
|
+
&.mfTagBox-input {
|
|
147
|
+
pointer-events: all;
|
|
148
|
+
outline: none;
|
|
149
|
+
background: transparent;
|
|
150
|
+
flex: 1;
|
|
151
|
+
appearance: none;
|
|
152
|
+
border: 0;
|
|
153
|
+
color: inherit;
|
|
154
|
+
|
|
155
|
+
height: 100%;
|
|
156
|
+
padding: 0px;
|
|
157
|
+
min-height: 0px;
|
|
158
|
+
|
|
159
|
+
min-width: 100px;
|
|
160
|
+
|
|
161
|
+
&:focus {
|
|
162
|
+
border: 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
const GroupTitle = styled((_a) => {
|
|
167
|
+
var { className, children } = _a, props = __rest(_a, ["className", "children"]);
|
|
168
|
+
return (_jsxs("div", Object.assign({ className: className }, props, { children: [_jsx("div", { className: "group-line" }), _jsx("div", { className: "group-label", children: children }), _jsx("div", { className: "group-line" })] })));
|
|
169
|
+
}) `
|
|
170
|
+
display: flex;
|
|
171
|
+
flex-direction: row;
|
|
172
|
+
align-items: center;
|
|
173
|
+
justify-content: space-between;
|
|
174
|
+
gap: 10px;
|
|
175
|
+
|
|
176
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
177
|
+
|
|
178
|
+
padding: ${({ size }) => size === "xs"
|
|
179
|
+
? "2px 8px"
|
|
180
|
+
: size === "sm"
|
|
181
|
+
? "4px 10px"
|
|
182
|
+
: size === "md"
|
|
183
|
+
? "4px 12px"
|
|
184
|
+
: size === "lg"
|
|
185
|
+
? "5px 14px"
|
|
186
|
+
: size === "xl"
|
|
187
|
+
? "6px 16px"
|
|
188
|
+
: "2px 8px"};
|
|
189
|
+
|
|
190
|
+
.group-label {
|
|
191
|
+
white-space: nowrap;
|
|
192
|
+
overflow: hidden;
|
|
193
|
+
text-overflow: ellipsis;
|
|
194
|
+
width: fit-content;
|
|
195
|
+
min-width: fit-content;
|
|
196
|
+
|
|
197
|
+
font-weight: 500;
|
|
198
|
+
|
|
199
|
+
font-size: ${({ size }) => size === "xs"
|
|
200
|
+
? "11px"
|
|
201
|
+
: size === "sm"
|
|
202
|
+
? "13px"
|
|
203
|
+
: size === "md"
|
|
204
|
+
? "15px"
|
|
205
|
+
: size === "lg"
|
|
206
|
+
? "17px"
|
|
207
|
+
: size === "xl"
|
|
208
|
+
? "19px"
|
|
209
|
+
: "11px"};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.group-line {
|
|
213
|
+
border-top: 1px solid ${(props) => props.theme.palette.divider};
|
|
214
|
+
width: 100%;
|
|
215
|
+
}
|
|
216
|
+
`;
|
|
217
|
+
const PillContainer = styled.div `
|
|
218
|
+
display: flex;
|
|
219
|
+
align-items: center;
|
|
220
|
+
gap: 5px;
|
|
221
|
+
flex-wrap: wrap;
|
|
222
|
+
flex-grow: 1;
|
|
223
|
+
|
|
224
|
+
&[data-empty="true"] {
|
|
225
|
+
display: none;
|
|
226
|
+
}
|
|
227
|
+
`;
|
|
228
|
+
const StyledInnerContainer = styled.div `
|
|
229
|
+
display: flex;
|
|
230
|
+
flex-direction: column;
|
|
231
|
+
width: 100%;
|
|
232
|
+
|
|
233
|
+
&[data-button-right="true"] {
|
|
234
|
+
padding-right: 30px;
|
|
235
|
+
}
|
|
236
|
+
`;
|
|
237
|
+
const ExtendedStyledContent = styled(StyledContent) `
|
|
238
|
+
overflow-y: auto;
|
|
239
|
+
`;
|
|
240
|
+
const StyledItem = styled.div `
|
|
241
|
+
line-height: 1;
|
|
242
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
243
|
+
border-radius: 3px;
|
|
244
|
+
display: flex;
|
|
245
|
+
align-items: center;
|
|
246
|
+
min-height: 25px;
|
|
247
|
+
padding: 7px 10px;
|
|
248
|
+
position: relative;
|
|
249
|
+
user-select: none;
|
|
250
|
+
outline: none;
|
|
251
|
+
|
|
252
|
+
cursor: pointer;
|
|
253
|
+
|
|
254
|
+
font-family: "Arial", sans-serif;
|
|
255
|
+
font-size: ${({ size }) => size === "xs"
|
|
256
|
+
? "11px"
|
|
257
|
+
: size === "sm"
|
|
258
|
+
? "13px"
|
|
259
|
+
: size === "md"
|
|
260
|
+
? "15px"
|
|
261
|
+
: size === "lg"
|
|
262
|
+
? "17px"
|
|
263
|
+
: size === "xl"
|
|
264
|
+
? "19px"
|
|
265
|
+
: "11px"};
|
|
266
|
+
|
|
267
|
+
&[data-disabled] {
|
|
268
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
269
|
+
pointer-events: "none";
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
&:hover {
|
|
273
|
+
background-color: ${(props) => props.theme.palette.action.hover};
|
|
274
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
&[data-selected="true"] {
|
|
278
|
+
display: none;
|
|
279
|
+
color: ${(props) => props.theme.palette.primary.main};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
&[data-highlighted="true"] {
|
|
283
|
+
background-color: ${(props) => props.theme.palette.divider};
|
|
284
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
285
|
+
}
|
|
286
|
+
`;
|
|
287
|
+
const TagBox = styled(({ className, data = [], placeholder = "Select tags", arrow = true, defaultValue = [], grouped, searchFn, onChange, onScroll, onSearch, onItemAdded, size = "sm", variant = "outlined", width = "100%", allowCustomValue = false, searchable = false, clearable = false, openOnFocus = true, label, description, required = false, error, loading = false, renderOption, TooltipContent, }) => {
|
|
288
|
+
var _a, _b, _c, _d, _e, _f;
|
|
289
|
+
const isObjectArray = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.hasOwnProperty("label");
|
|
290
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
291
|
+
const [selectedItems, setSelectedItems] = useState(defaultValue);
|
|
292
|
+
const [preSelected, setPreSelected] = useState(null);
|
|
293
|
+
const [customItems, setCustomItems] = useState([]);
|
|
294
|
+
const [searchValue, setSearchValue] = useState("");
|
|
295
|
+
const inputRef = useRef(null);
|
|
296
|
+
const scrollContainerRef = useRef(null);
|
|
297
|
+
const filteredItems = data
|
|
298
|
+
.concat(customItems) // Add custom items to the list
|
|
299
|
+
.filter((item) => {
|
|
300
|
+
const isSelected = !!selectedItems.find((selectedItem) => isObjectArray
|
|
301
|
+
? selectedItem.value === item.value
|
|
302
|
+
: selectedItem === item);
|
|
303
|
+
return !isSelected;
|
|
304
|
+
})
|
|
305
|
+
.filter((item) => {
|
|
306
|
+
const itemValue = (isObjectArray ? item.label : item);
|
|
307
|
+
return itemValue.toLowerCase().includes(searchValue.toLowerCase());
|
|
308
|
+
})
|
|
309
|
+
.sort((a, b) => {
|
|
310
|
+
if (grouped) {
|
|
311
|
+
const aValue = a.group;
|
|
312
|
+
const bValue = b.group;
|
|
313
|
+
return aValue.localeCompare(bValue);
|
|
314
|
+
}
|
|
315
|
+
// return current sort order
|
|
316
|
+
return 0;
|
|
317
|
+
});
|
|
318
|
+
const groupedItems = grouped
|
|
319
|
+
? filteredItems.reduce((acc, item) => {
|
|
320
|
+
if (!item.group) {
|
|
321
|
+
item.group = "Other";
|
|
322
|
+
}
|
|
323
|
+
if (acc[item.group]) {
|
|
324
|
+
acc[item.group].push(item);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
acc[item.group] = [item];
|
|
328
|
+
}
|
|
329
|
+
return acc;
|
|
330
|
+
}, {})
|
|
331
|
+
: {};
|
|
332
|
+
const groups = grouped
|
|
333
|
+
? Object.keys(groupedItems)
|
|
334
|
+
.map((group) => ({
|
|
335
|
+
label: group,
|
|
336
|
+
items: groupedItems[group],
|
|
337
|
+
}))
|
|
338
|
+
.sort((a, b) => a.label.localeCompare(b.label))
|
|
339
|
+
: [];
|
|
340
|
+
const { refs, floatingStyles, update } = useFloating({
|
|
341
|
+
open: isOpen,
|
|
342
|
+
onOpenChange: setIsOpen,
|
|
343
|
+
placement: "bottom-start",
|
|
344
|
+
strategy: "absolute",
|
|
345
|
+
// Handle collisions with the viewport
|
|
346
|
+
middleware: [flip(), offset(5)],
|
|
347
|
+
});
|
|
348
|
+
const toggleOpen = () => {
|
|
349
|
+
setIsOpen((prev) => {
|
|
350
|
+
var _a;
|
|
351
|
+
if (!prev) {
|
|
352
|
+
if (inputRef.current) {
|
|
353
|
+
const inputEl = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current;
|
|
354
|
+
(_a = inputEl === null || inputEl === void 0 ? void 0 : inputEl.focus) === null || _a === void 0 ? void 0 : _a.call(inputEl);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return !prev;
|
|
358
|
+
});
|
|
359
|
+
};
|
|
360
|
+
const handleClear = (e) => {
|
|
361
|
+
e.preventDefault();
|
|
362
|
+
e.stopPropagation();
|
|
363
|
+
if (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current)
|
|
364
|
+
inputRef.current.value = "";
|
|
365
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([]);
|
|
366
|
+
setSelectedItems([]);
|
|
367
|
+
setSearchValue("");
|
|
368
|
+
searchFn === null || searchFn === void 0 ? void 0 : searchFn("");
|
|
369
|
+
setIsOpen(false);
|
|
370
|
+
};
|
|
371
|
+
const handleChangeSelection = useCallback((option) => {
|
|
372
|
+
setSelectedItems((prev) => {
|
|
373
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([...prev, option]);
|
|
374
|
+
return [...prev, option];
|
|
375
|
+
});
|
|
376
|
+
}, [onChange]);
|
|
377
|
+
const handleFocus = () => {
|
|
378
|
+
var _a, _b;
|
|
379
|
+
if (openOnFocus) {
|
|
380
|
+
setIsOpen(true);
|
|
381
|
+
}
|
|
382
|
+
if (searchable) {
|
|
383
|
+
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
384
|
+
}
|
|
385
|
+
else if (allowCustomValue) {
|
|
386
|
+
(_b = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const handleItemClick = (item) => {
|
|
390
|
+
var _a;
|
|
391
|
+
if ((_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.value)
|
|
392
|
+
inputRef.current.value = "";
|
|
393
|
+
setSearchValue("");
|
|
394
|
+
handleChangeSelection(item);
|
|
395
|
+
};
|
|
396
|
+
const handleRemoveItem = (item, index) => {
|
|
397
|
+
setSelectedItems((prev) => {
|
|
398
|
+
const newItems = prev.filter((prevItem, idx) => isObjectArray
|
|
399
|
+
? prevItem.value !== item.value
|
|
400
|
+
: idx !== index);
|
|
401
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newItems);
|
|
402
|
+
return newItems;
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
const handleAddItem = useCallback((newItem) => {
|
|
406
|
+
const existingItem = data.concat(customItems).find((item) => {
|
|
407
|
+
return isObjectArray
|
|
408
|
+
? item.label.toLowerCase() === newItem.toLowerCase()
|
|
409
|
+
: item.toLowerCase() === newItem.toLowerCase();
|
|
410
|
+
});
|
|
411
|
+
if (!existingItem) {
|
|
412
|
+
const newValue = isObjectArray
|
|
413
|
+
? { label: newItem, value: newItem }
|
|
414
|
+
: newItem;
|
|
415
|
+
setCustomItems([...customItems, newValue]);
|
|
416
|
+
handleChangeSelection(newValue);
|
|
417
|
+
onItemAdded === null || onItemAdded === void 0 ? void 0 : onItemAdded(newValue);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
// check if the item is already selected
|
|
421
|
+
const isSelected = !!selectedItems.find((selectedItem) => isObjectArray
|
|
422
|
+
? selectedItem.value ===
|
|
423
|
+
existingItem.value
|
|
424
|
+
: selectedItem === existingItem);
|
|
425
|
+
if (!isSelected) {
|
|
426
|
+
handleChangeSelection(existingItem);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}, [
|
|
430
|
+
onItemAdded,
|
|
431
|
+
isObjectArray,
|
|
432
|
+
data,
|
|
433
|
+
handleChangeSelection,
|
|
434
|
+
selectedItems,
|
|
435
|
+
customItems,
|
|
436
|
+
]);
|
|
437
|
+
const handleKeyDown = (e) => {
|
|
438
|
+
var _a, _b;
|
|
439
|
+
const currentInputValue = (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.value;
|
|
440
|
+
// Escape key
|
|
441
|
+
if (e.key === "Escape") {
|
|
442
|
+
const reference = (_b = refs === null || refs === void 0 ? void 0 : refs.reference) === null || _b === void 0 ? void 0 : _b.current;
|
|
443
|
+
reference === null || reference === void 0 ? void 0 : reference.blur();
|
|
444
|
+
setSearchValue("");
|
|
445
|
+
update();
|
|
446
|
+
setIsOpen(false);
|
|
447
|
+
}
|
|
448
|
+
// Enter key
|
|
449
|
+
if (e.key === "Enter") {
|
|
450
|
+
if (preSelected) {
|
|
451
|
+
handleItemClick(preSelected);
|
|
452
|
+
setPreSelected(null);
|
|
453
|
+
setSearchValue("");
|
|
454
|
+
update();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
else if (currentInputValue &&
|
|
458
|
+
currentInputValue !== "" &&
|
|
459
|
+
allowCustomValue) {
|
|
460
|
+
handleAddItem(currentInputValue);
|
|
461
|
+
inputRef.current.value = "";
|
|
462
|
+
setSearchValue("");
|
|
463
|
+
update();
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
// TODO: decide what to do when user presses enter after typing a search value
|
|
467
|
+
}
|
|
468
|
+
// toggleOpen();
|
|
469
|
+
// setIsOpen(false);
|
|
470
|
+
}
|
|
471
|
+
// Backspace key
|
|
472
|
+
if (e.key === "Backspace" && currentInputValue === "") {
|
|
473
|
+
setSelectedItems((prev) => {
|
|
474
|
+
const newItems = prev.slice(0, prev.length - 1);
|
|
475
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newItems);
|
|
476
|
+
return newItems;
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
// Arrow down
|
|
480
|
+
if (e.key === "ArrowDown") {
|
|
481
|
+
e.preventDefault();
|
|
482
|
+
setPreSelected((prev) => {
|
|
483
|
+
let newItem = filteredItems[0]; // Loop back to the first item
|
|
484
|
+
const index = filteredItems.findIndex((item) => isObjectArray
|
|
485
|
+
? item.value === (prev === null || prev === void 0 ? void 0 : prev.value)
|
|
486
|
+
: item === prev);
|
|
487
|
+
if (index < filteredItems.length - 1) {
|
|
488
|
+
newItem = filteredItems[index + 1];
|
|
489
|
+
}
|
|
490
|
+
return newItem;
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
// Arrow up
|
|
494
|
+
if (e.key === "ArrowUp") {
|
|
495
|
+
e.preventDefault();
|
|
496
|
+
setPreSelected((prev) => {
|
|
497
|
+
let newItem = filteredItems[filteredItems.length - 1]; // Loop back to the last item
|
|
498
|
+
const index = filteredItems.findIndex((item) => isObjectArray
|
|
499
|
+
? item.value === (prev === null || prev === void 0 ? void 0 : prev.value)
|
|
500
|
+
: item === prev);
|
|
501
|
+
if (index > 0) {
|
|
502
|
+
newItem = filteredItems[index - 1];
|
|
503
|
+
}
|
|
504
|
+
return newItem;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
// Tab key
|
|
508
|
+
if (e.key === "Tab") {
|
|
509
|
+
setIsOpen(false);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
// Close on outside click
|
|
513
|
+
useEffect(() => {
|
|
514
|
+
const close = (e) => {
|
|
515
|
+
var _a, _b;
|
|
516
|
+
const target = e.target;
|
|
517
|
+
const referenceElement = (_a = refs === null || refs === void 0 ? void 0 : refs.reference) === null || _a === void 0 ? void 0 : _a.current;
|
|
518
|
+
const floatingElement = (_b = refs === null || refs === void 0 ? void 0 : refs.floating) === null || _b === void 0 ? void 0 : _b.current;
|
|
519
|
+
if (floatingElement && // Check if the floating element exists
|
|
520
|
+
target !== referenceElement && // Check if the target is not the reference (input)
|
|
521
|
+
!referenceElement.contains(target) && // Check if the target is not inside the reference (input)
|
|
522
|
+
!floatingElement.contains(target) // Check if the target is not inside the floating element (content)
|
|
523
|
+
) {
|
|
524
|
+
setIsOpen(false);
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
document.addEventListener("click", close);
|
|
528
|
+
return () => document.removeEventListener("click", close);
|
|
529
|
+
}, [refs.floating, refs.reference]);
|
|
530
|
+
// update when selection changes
|
|
531
|
+
useEffect(() => {
|
|
532
|
+
update();
|
|
533
|
+
}, [selectedItems]);
|
|
534
|
+
const referenceEl = (_b = refs === null || refs === void 0 ? void 0 : refs.reference) === null || _b === void 0 ? void 0 : _b.current;
|
|
535
|
+
const contentWidth = ((_e = (_d = (_c = referenceEl === null || referenceEl === void 0 ? void 0 : referenceEl.getClientRects) === null || _c === void 0 ? void 0 : _c.call(referenceEl)) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.width) || "100%";
|
|
536
|
+
const scrollEl = scrollContainerRef === null || scrollContainerRef === void 0 ? void 0 : scrollContainerRef.current;
|
|
537
|
+
const scrollActive = scrollEl
|
|
538
|
+
? (scrollEl === null || scrollEl === void 0 ? void 0 : scrollEl.scrollHeight) > (scrollEl === null || scrollEl === void 0 ? void 0 : scrollEl.clientHeight)
|
|
539
|
+
: false;
|
|
540
|
+
return (_jsxs("div", { className: className + " mfTagBox", children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInputContainer, { className: "styledInputContainer", ref: refs.setReference, onMouseDown: () => {
|
|
541
|
+
setIsOpen(true);
|
|
542
|
+
handleFocus();
|
|
543
|
+
}, onFocus: handleFocus, size: size, variant: variant, onKeyDown: handleKeyDown, "data-open": isOpen, children: [_jsx(StyledInnerContainer, { size: size, "data-button-right": arrow || clearable, children: _jsxs(PillContainer, { size: size, children: [selectedItems.map((item, index) => (_jsx(Pill, { size: "xs", onRemove: () => handleRemoveItem(item, index), children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (_jsx(_Fragment, { children: (item === null || item === void 0 ? void 0 : item.label) || item })) }, index))), (searchable ||
|
|
544
|
+
allowCustomValue ||
|
|
545
|
+
selectedItems.length === 0) && (_jsx(StyledInput, { inputRef: inputRef, onChange: (e) => {
|
|
546
|
+
if (searchFn !== undefined) {
|
|
547
|
+
searchFn === null || searchFn === void 0 ? void 0 : searchFn(e.target.value);
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
setSearchValue(e.target.value);
|
|
551
|
+
}
|
|
552
|
+
update();
|
|
553
|
+
}, placeholder: placeholder, size: size, readOnly: !(searchable || allowCustomValue) }))] }) }), clearable &&
|
|
554
|
+
(selectedItems.length > 0 || !!((_f = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _f === void 0 ? void 0 : _f.value)) ? (_jsx(ClearButton, { onClick: handleClear })) : arrow ? (_jsx(ArrowButton, { onClick: (e) => {
|
|
555
|
+
e.preventDefault();
|
|
556
|
+
}, onMouseDown: (e) => {
|
|
557
|
+
e.preventDefault();
|
|
558
|
+
e.stopPropagation();
|
|
559
|
+
toggleOpen();
|
|
560
|
+
} })) : null] }), isOpen && (_jsx(StyledFloatContainer, { ref: refs.setFloating, style: floatingStyles, className: "mfFloating", children: _jsx(ExtendedStyledContent, { className: "mfFloatingContent", style: { width: contentWidth, maxWidth: contentWidth }, variant: variant, onScroll: onScroll, "data-scroll-active": scrollActive, "data-empty": filteredItems.length === 0, children: !loading && grouped
|
|
561
|
+
? groups.map((group) => (_jsxs("div", { children: [_jsx(GroupTitle, { size: size, children: group.label }), group.items.map((item, index) => {
|
|
562
|
+
return (_jsx(Tooltip, { content: TooltipContent ? (_jsx(TooltipContent, { data: item.data })) : null, side: "left", children: _jsx(StyledItem, { className: "mfFloatingItem", onClick: (e) => {
|
|
563
|
+
e.preventDefault();
|
|
564
|
+
e.stopPropagation();
|
|
565
|
+
handleItemClick(item);
|
|
566
|
+
}, "data-highlighted": isObjectArray
|
|
567
|
+
? (preSelected === null || preSelected === void 0 ? void 0 : preSelected.value) ===
|
|
568
|
+
item.value
|
|
569
|
+
: preSelected === item, size: size, children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (_jsx(_Fragment, { children: (item === null || item === void 0 ? void 0 : item.label) || item })) }, index) }, index));
|
|
570
|
+
})] }, group.label)))
|
|
571
|
+
: filteredItems.map((item, index) => {
|
|
572
|
+
return (_jsx(Tooltip, { content: TooltipContent ? (_jsx(TooltipContent, { data: item.data })) : null, side: "left", children: _jsx(StyledItem, { className: "mfFloatingItem", onClick: (e) => {
|
|
573
|
+
e.preventDefault();
|
|
574
|
+
e.stopPropagation();
|
|
575
|
+
handleItemClick(item);
|
|
576
|
+
}, "data-highlighted": isObjectArray
|
|
577
|
+
? (preSelected === null || preSelected === void 0 ? void 0 : preSelected.value) ===
|
|
578
|
+
item.value
|
|
579
|
+
: preSelected === item, size: size, children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (_jsx(_Fragment, { children: (item === null || item === void 0 ? void 0 : item.label) || item })) }, index) }, index));
|
|
580
|
+
}) }) }))] }));
|
|
581
|
+
}) `
|
|
582
|
+
position: relative;
|
|
583
|
+
cursor: pointer;
|
|
584
|
+
`;
|
|
585
|
+
export default TagBox;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { XIcon } from "lucide-react";
|
|
3
|
+
export const TagBoxContainer = styled.div `
|
|
4
|
+
width: 100%;
|
|
5
|
+
`;
|
|
6
|
+
export const TagBoxInner = styled.div `
|
|
7
|
+
height: 33px;
|
|
8
|
+
display: flex;
|
|
9
|
+
border: 1px solid ${(props) => props.theme.palette.input.border};
|
|
10
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
11
|
+
outline: none;
|
|
12
|
+
padding: 8px 8px;
|
|
13
|
+
width: 100%;
|
|
14
|
+
background-color: ${(props) => props.theme.palette.input.background};
|
|
15
|
+
border-radius: 5px;
|
|
16
|
+
transition: border 0.1s ease-in-out;
|
|
17
|
+
overflow-x: hidden;
|
|
18
|
+
&:focus {
|
|
19
|
+
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
export const TagsContainer = styled.div `
|
|
23
|
+
display: flex;
|
|
24
|
+
-webkit-box-align: center;
|
|
25
|
+
align-items: center;
|
|
26
|
+
flex-wrap: nowrap;
|
|
27
|
+
margin-left: calc(-5px);
|
|
28
|
+
box-sizing: border-box;
|
|
29
|
+
`;
|
|
30
|
+
export const TagBoxInput = styled.input `
|
|
31
|
+
border: none;
|
|
32
|
+
outline: none;
|
|
33
|
+
width: 100%;
|
|
34
|
+
min-width: 50px;
|
|
35
|
+
background-color: transparent;
|
|
36
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
37
|
+
&:focus {
|
|
38
|
+
border: none;
|
|
39
|
+
outline: none;
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
export const Tag = styled.div `
|
|
43
|
+
display: flex;
|
|
44
|
+
-webkit-box-align: center;
|
|
45
|
+
align-items: center;
|
|
46
|
+
background-color: rgb(26, 27, 30);
|
|
47
|
+
color: rgb(193, 194, 197);
|
|
48
|
+
height: 22px;
|
|
49
|
+
padding-left: 10px;
|
|
50
|
+
padding-right: 0px;
|
|
51
|
+
font-weight: 500;
|
|
52
|
+
font-size: 12px;
|
|
53
|
+
border-radius: 4px;
|
|
54
|
+
cursor: default;
|
|
55
|
+
user-select: none;
|
|
56
|
+
max-width: 120px;
|
|
57
|
+
margin: calc(3px) calc(5px);
|
|
58
|
+
`;
|
|
59
|
+
export const TagText = styled.div `
|
|
60
|
+
display: flex;
|
|
61
|
+
-webkit-box-align: center;
|
|
62
|
+
align-items: center;
|
|
63
|
+
background-color: rgb(26, 27, 30);
|
|
64
|
+
color: rgb(193, 194, 197);
|
|
65
|
+
height: 22px;
|
|
66
|
+
padding-right: 0px;
|
|
67
|
+
font-weight: 500;
|
|
68
|
+
font-size: 12px;
|
|
69
|
+
border-radius: 4px;
|
|
70
|
+
cursor: default;
|
|
71
|
+
user-select: none;
|
|
72
|
+
max-width: 75px;
|
|
73
|
+
white-space: nowrap;
|
|
74
|
+
overflow: hidden;
|
|
75
|
+
text-overflow: ellipsis;
|
|
76
|
+
`;
|
|
77
|
+
export const TagKillButton = styled(XIcon) `
|
|
78
|
+
-webkit-tap-highlight-color: transparent;
|
|
79
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
|
|
80
|
+
Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
appearance: none;
|
|
83
|
+
text-align: left;
|
|
84
|
+
text-decoration: none;
|
|
85
|
+
box-sizing: border-box;
|
|
86
|
+
border: 1px solid transparent;
|
|
87
|
+
background-color: transparent;
|
|
88
|
+
position: relative;
|
|
89
|
+
height: 19px;
|
|
90
|
+
min-height: 19px;
|
|
91
|
+
width: 22px;
|
|
92
|
+
min-width: 19px;
|
|
93
|
+
border-radius: 2px;
|
|
94
|
+
line-height: 1;
|
|
95
|
+
display: flex;
|
|
96
|
+
-webkit-box-align: center;
|
|
97
|
+
align-items: center;
|
|
98
|
+
-webkit-box-pack: center;
|
|
99
|
+
justify-content: center;
|
|
100
|
+
color: rgb(193, 194, 197);
|
|
101
|
+
padding: 0px 3px;
|
|
102
|
+
&:hover {
|
|
103
|
+
color: rgb(255, 255, 255);
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
export const TagBoxOptions = styled.div ``;
|
|
107
|
+
export const TagBoxOption = styled.div ``;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./TagBox";
|