@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,471 @@
|
|
|
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, FloatingPortal, } from "@floating-ui/react";
|
|
15
|
+
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
16
|
+
import { Input, FieldLabel, Tooltip } from "..";
|
|
17
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
18
|
+
import { StyledContent, StyledFloatContainer, ArrowButton, ClearButton, } from "../core";
|
|
19
|
+
export const StyledInputContainer = styled.div `
|
|
20
|
+
font-family: ${({ theme }) => theme.typography.fontFamily};
|
|
21
|
+
|
|
22
|
+
position: relative;
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: row;
|
|
25
|
+
border: none;
|
|
26
|
+
outline: none;
|
|
27
|
+
height: fit-content;
|
|
28
|
+
|
|
29
|
+
width: ${({ width }) => {
|
|
30
|
+
if (typeof width === "undefined")
|
|
31
|
+
return "100%";
|
|
32
|
+
if (width === null)
|
|
33
|
+
return "100%";
|
|
34
|
+
if (typeof width === "string")
|
|
35
|
+
return width;
|
|
36
|
+
if (typeof width === "number")
|
|
37
|
+
return `${width}px`;
|
|
38
|
+
}};
|
|
39
|
+
`;
|
|
40
|
+
const StyledInnerItemContainer = styled.div `
|
|
41
|
+
overflow-y: auto;
|
|
42
|
+
|
|
43
|
+
&[data-scroll-active="true"] {
|
|
44
|
+
padding-right: 5px;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
const GroupTitle = styled((_a) => {
|
|
48
|
+
var { className, children } = _a, props = __rest(_a, ["className", "children"]);
|
|
49
|
+
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" })] })));
|
|
50
|
+
}) `
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: row;
|
|
53
|
+
align-items: center;
|
|
54
|
+
justify-content: space-between;
|
|
55
|
+
gap: 10px;
|
|
56
|
+
|
|
57
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
58
|
+
|
|
59
|
+
padding: ${({ size }) => size === "xs"
|
|
60
|
+
? "2px 8px"
|
|
61
|
+
: size === "sm"
|
|
62
|
+
? "4px 10px"
|
|
63
|
+
: size === "md"
|
|
64
|
+
? "4px 12px"
|
|
65
|
+
: size === "lg"
|
|
66
|
+
? "5px 14px"
|
|
67
|
+
: size === "xl"
|
|
68
|
+
? "6px 16px"
|
|
69
|
+
: "2px 8px"};
|
|
70
|
+
|
|
71
|
+
.group-label {
|
|
72
|
+
white-space: nowrap;
|
|
73
|
+
overflow: hidden;
|
|
74
|
+
text-overflow: ellipsis;
|
|
75
|
+
width: fit-content;
|
|
76
|
+
min-width: fit-content;
|
|
77
|
+
|
|
78
|
+
font-weight: 500;
|
|
79
|
+
|
|
80
|
+
font-size: ${({ size }) => size === "xs"
|
|
81
|
+
? "11px"
|
|
82
|
+
: size === "sm"
|
|
83
|
+
? "13px"
|
|
84
|
+
: size === "md"
|
|
85
|
+
? "15px"
|
|
86
|
+
: size === "lg"
|
|
87
|
+
? "17px"
|
|
88
|
+
: size === "xl"
|
|
89
|
+
? "19px"
|
|
90
|
+
: "11px"};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.group-line {
|
|
94
|
+
border-top: 1px solid ${(props) => props.theme.palette.divider};
|
|
95
|
+
width: 100%;
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
const ActionMenu = styled.div ``;
|
|
99
|
+
const StyledItem = styled.div `
|
|
100
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
101
|
+
border-radius: 3px;
|
|
102
|
+
display: flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
min-height: 25px;
|
|
105
|
+
padding: 7px 10px;
|
|
106
|
+
position: relative;
|
|
107
|
+
user-select: none;
|
|
108
|
+
outline: none;
|
|
109
|
+
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
|
|
112
|
+
font-family: ${({ theme }) => theme.typography.fontFamily};
|
|
113
|
+
|
|
114
|
+
font-size: ${({ size }) => size === "xs"
|
|
115
|
+
? "11px"
|
|
116
|
+
: size === "sm"
|
|
117
|
+
? "13px"
|
|
118
|
+
: size === "md"
|
|
119
|
+
? "15px"
|
|
120
|
+
: size === "lg"
|
|
121
|
+
? "17px"
|
|
122
|
+
: size === "xl"
|
|
123
|
+
? "19px"
|
|
124
|
+
: "11px"};
|
|
125
|
+
|
|
126
|
+
padding: ${({ size }) => size === "xs"
|
|
127
|
+
? "2px 8px"
|
|
128
|
+
: size === "sm"
|
|
129
|
+
? "4px 10px"
|
|
130
|
+
: size === "md"
|
|
131
|
+
? "4px 12px"
|
|
132
|
+
: size === "lg"
|
|
133
|
+
? "5px 14px"
|
|
134
|
+
: size === "xl"
|
|
135
|
+
? "6px 16px"
|
|
136
|
+
: "2px 8px"};
|
|
137
|
+
|
|
138
|
+
&[data-disabled] {
|
|
139
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
140
|
+
pointer-events: "none";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
&:hover {
|
|
144
|
+
background-color: ${(props) => props.theme.palette.action.hover};
|
|
145
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
&[data-selected="true"] {
|
|
149
|
+
background-color: ${(props) => props.theme.palette.divider};
|
|
150
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
151
|
+
}
|
|
152
|
+
`;
|
|
153
|
+
const SelectBox = styled(({ className, data = [], placeholder = "Select...", arrow = true, onChange, onSearch, searchFn, onScroll, loading, defaultValue, onItemAdded, size = "sm", variant = "outlined", width = "100%", allowCustomValue = false, searchable = false, clearable = false, label, description, required = false, error, openOnFocus = true, renderOption, actionComponent, focused, grouped, TooltipContent, DropDownProps = {}, }) => {
|
|
154
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
155
|
+
const isObjectArray = (_a = Object.keys((data === null || data === void 0 ? void 0 : data[0]) || {})) === null || _a === void 0 ? void 0 : _a.includes("label");
|
|
156
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
157
|
+
const [selected, setSelected] = useState(null);
|
|
158
|
+
const [searchValue, setSearchValue] = useState("");
|
|
159
|
+
const [customItems, setCustomItems] = useState([]);
|
|
160
|
+
const [placement, setPlacement] = useState("bottom-start");
|
|
161
|
+
const [dropDownHeight, setDropDownHeight] = useState(null);
|
|
162
|
+
const inputRef = useRef(null);
|
|
163
|
+
const containerRef = useRef(null);
|
|
164
|
+
const scrollContainerRef = useRef(null);
|
|
165
|
+
const filteredItems = data
|
|
166
|
+
.concat(customItems) // Add custom items to the list
|
|
167
|
+
.filter((item) => {
|
|
168
|
+
const itemValue = (isObjectArray ? item.label : item);
|
|
169
|
+
return itemValue.toLowerCase().includes(searchValue.toLowerCase());
|
|
170
|
+
})
|
|
171
|
+
.sort((a, b) => {
|
|
172
|
+
if (grouped) {
|
|
173
|
+
const aValue = a.group;
|
|
174
|
+
const bValue = b.group;
|
|
175
|
+
return aValue.localeCompare(bValue);
|
|
176
|
+
}
|
|
177
|
+
// return current sort order
|
|
178
|
+
return 0;
|
|
179
|
+
});
|
|
180
|
+
const groupedItems = grouped
|
|
181
|
+
? filteredItems.reduce((acc, item) => {
|
|
182
|
+
if (!item.group) {
|
|
183
|
+
item.group = "Other";
|
|
184
|
+
}
|
|
185
|
+
if (acc[item.group]) {
|
|
186
|
+
acc[item.group].push(item);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
acc[item.group] = [item];
|
|
190
|
+
}
|
|
191
|
+
return acc;
|
|
192
|
+
}, {})
|
|
193
|
+
: {};
|
|
194
|
+
const groups = grouped
|
|
195
|
+
? Object.keys(groupedItems)
|
|
196
|
+
.map((group) => ({
|
|
197
|
+
label: group,
|
|
198
|
+
items: groupedItems[group],
|
|
199
|
+
}))
|
|
200
|
+
.sort((a, b) => a.label.localeCompare(b.label))
|
|
201
|
+
: [];
|
|
202
|
+
const { refs, floatingStyles, update } = useFloating({
|
|
203
|
+
open: isOpen,
|
|
204
|
+
onOpenChange: setIsOpen,
|
|
205
|
+
placement,
|
|
206
|
+
strategy: "absolute",
|
|
207
|
+
// Handle collisions with the viewport
|
|
208
|
+
middleware: [flip(), offset(5)],
|
|
209
|
+
});
|
|
210
|
+
const toggleOpen = () => {
|
|
211
|
+
setIsOpen((prev) => {
|
|
212
|
+
if (!prev) {
|
|
213
|
+
if (inputRef.current) {
|
|
214
|
+
inputRef.current.focus();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return !prev;
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
const handleClear = (e) => {
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
e.stopPropagation();
|
|
223
|
+
if (inputRef.current)
|
|
224
|
+
inputRef.current.value = "";
|
|
225
|
+
handleChangeSelection(null);
|
|
226
|
+
setSelected(null);
|
|
227
|
+
setSearchValue("");
|
|
228
|
+
searchFn === null || searchFn === void 0 ? void 0 : searchFn("");
|
|
229
|
+
update();
|
|
230
|
+
};
|
|
231
|
+
const handleItemClick = (event, item) => {
|
|
232
|
+
event.preventDefault();
|
|
233
|
+
event.stopPropagation();
|
|
234
|
+
handleChangeSelection(item);
|
|
235
|
+
setIsOpen(false);
|
|
236
|
+
};
|
|
237
|
+
const handleChangeSelection = useCallback((option) => {
|
|
238
|
+
setSelected(option);
|
|
239
|
+
onChange === null || onChange === void 0 ? void 0 : onChange((option === null || option === void 0 ? void 0 : option.value) || option, option);
|
|
240
|
+
}, [onChange]);
|
|
241
|
+
const handleAddItem = useCallback((newItem) => {
|
|
242
|
+
const isNewItem = data.every((item) => item.label.toLowerCase() !==
|
|
243
|
+
newItem.toLowerCase());
|
|
244
|
+
if (isNewItem) {
|
|
245
|
+
const newValue = isObjectArray
|
|
246
|
+
? { label: newItem, value: newItem }
|
|
247
|
+
: newItem;
|
|
248
|
+
setCustomItems((prev) => {
|
|
249
|
+
prev.push(newValue);
|
|
250
|
+
return prev;
|
|
251
|
+
});
|
|
252
|
+
handleChangeSelection(newValue);
|
|
253
|
+
onItemAdded === null || onItemAdded === void 0 ? void 0 : onItemAdded(newValue);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
const item = data.find((item) => {
|
|
257
|
+
return isObjectArray
|
|
258
|
+
? item.label.toLowerCase() === newItem.toLowerCase()
|
|
259
|
+
: item.toLowerCase() === newItem.toLowerCase();
|
|
260
|
+
});
|
|
261
|
+
handleChangeSelection(item);
|
|
262
|
+
}
|
|
263
|
+
}, [onItemAdded, isObjectArray, data, handleChangeSelection]);
|
|
264
|
+
const handleKeyDown = (e) => {
|
|
265
|
+
var _a, _b;
|
|
266
|
+
const currentInputValue = (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.value;
|
|
267
|
+
// Escape key
|
|
268
|
+
if (e.key === "Escape") {
|
|
269
|
+
const reference = (_b = refs === null || refs === void 0 ? void 0 : refs.reference) === null || _b === void 0 ? void 0 : _b.current;
|
|
270
|
+
reference === null || reference === void 0 ? void 0 : reference.blur();
|
|
271
|
+
setSearchValue("");
|
|
272
|
+
update();
|
|
273
|
+
setIsOpen(false);
|
|
274
|
+
}
|
|
275
|
+
// Enter key
|
|
276
|
+
if (e.key === "Enter") {
|
|
277
|
+
if (currentInputValue && currentInputValue !== "" && allowCustomValue) {
|
|
278
|
+
handleAddItem(currentInputValue);
|
|
279
|
+
setSearchValue("");
|
|
280
|
+
update();
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// TODO: decide what to do when user presses enter after typing a search value
|
|
284
|
+
}
|
|
285
|
+
toggleOpen();
|
|
286
|
+
// setIsOpen(false);
|
|
287
|
+
}
|
|
288
|
+
// Arrow down
|
|
289
|
+
if (e.key === "ArrowDown") {
|
|
290
|
+
e.preventDefault();
|
|
291
|
+
setSelected((prev) => {
|
|
292
|
+
let newItem = filteredItems[0]; // Loop back to the first item
|
|
293
|
+
const index = filteredItems.findIndex((item) => isObjectArray
|
|
294
|
+
? item.value === (prev === null || prev === void 0 ? void 0 : prev.value)
|
|
295
|
+
: item === prev);
|
|
296
|
+
if (index < filteredItems.length - 1) {
|
|
297
|
+
newItem = filteredItems[index + 1];
|
|
298
|
+
}
|
|
299
|
+
onChange === null || onChange === void 0 ? void 0 : onChange((newItem === null || newItem === void 0 ? void 0 : newItem.value) || newItem, newItem);
|
|
300
|
+
return newItem;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
// Arrow up
|
|
304
|
+
if (e.key === "ArrowUp") {
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
setSelected((prev) => {
|
|
307
|
+
let newItem = filteredItems[filteredItems.length - 1]; // Loop back to the last item
|
|
308
|
+
const index = filteredItems.findIndex((item) => isObjectArray
|
|
309
|
+
? item.value === (prev === null || prev === void 0 ? void 0 : prev.value)
|
|
310
|
+
: item === prev);
|
|
311
|
+
if (index > 0) {
|
|
312
|
+
newItem = filteredItems[index - 1];
|
|
313
|
+
}
|
|
314
|
+
onChange === null || onChange === void 0 ? void 0 : onChange((newItem === null || newItem === void 0 ? void 0 : newItem.value) || newItem, newItem);
|
|
315
|
+
return newItem;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
// Tab key
|
|
319
|
+
if (e.key === "Tab") {
|
|
320
|
+
if (allowCustomValue && currentInputValue && currentInputValue !== "") {
|
|
321
|
+
handleAddItem(currentInputValue);
|
|
322
|
+
setSearchValue("");
|
|
323
|
+
}
|
|
324
|
+
else if (!selected) {
|
|
325
|
+
// clear input
|
|
326
|
+
if (inputRef.current) {
|
|
327
|
+
inputRef.current.value = "";
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
setSearchValue("");
|
|
331
|
+
setIsOpen(false);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const handleOnChange = (e) => {
|
|
335
|
+
// Simulate clear event when the input is changed to an empty string
|
|
336
|
+
if (e.target.value === "") {
|
|
337
|
+
handleClear(e);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (searchFn !== undefined) {
|
|
341
|
+
searchFn === null || searchFn === void 0 ? void 0 : searchFn(e.target.value);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
setSearchValue(e.target.value);
|
|
345
|
+
update();
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const debouncedHandleOnChange = useDebouncedCallback(handleOnChange, 300);
|
|
349
|
+
const handleFocus = () => {
|
|
350
|
+
if (openOnFocus) {
|
|
351
|
+
setIsOpen(true);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
// Close on outside click
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
const close = (e) => {
|
|
357
|
+
var _a, _b;
|
|
358
|
+
const target = e.target;
|
|
359
|
+
const referenceElement = (_a = refs === null || refs === void 0 ? void 0 : refs.reference) === null || _a === void 0 ? void 0 : _a.current;
|
|
360
|
+
const floatingElement = (_b = refs === null || refs === void 0 ? void 0 : refs.floating) === null || _b === void 0 ? void 0 : _b.current;
|
|
361
|
+
if (floatingElement && // Check if the floating element exists
|
|
362
|
+
target !== referenceElement && // Check if the target is not the reference (input)
|
|
363
|
+
!referenceElement.contains(target) && // Check if the target is not inside the reference (input)
|
|
364
|
+
!floatingElement.contains(target) // Check if the target is not inside the floating element (content)
|
|
365
|
+
) {
|
|
366
|
+
setIsOpen(false);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
document.addEventListener("click", close);
|
|
370
|
+
return () => document.removeEventListener("click", close);
|
|
371
|
+
}, [refs.floating, refs.reference]);
|
|
372
|
+
// Handle default value
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
if (defaultValue) {
|
|
375
|
+
const isOption = defaultValue.value !== undefined;
|
|
376
|
+
const searchPattern = isOption
|
|
377
|
+
? defaultValue.value
|
|
378
|
+
: defaultValue;
|
|
379
|
+
setSelected(data.find((item) => isObjectArray
|
|
380
|
+
? item.value === searchPattern
|
|
381
|
+
: item === searchPattern) || null);
|
|
382
|
+
}
|
|
383
|
+
}, [data, defaultValue, isObjectArray]);
|
|
384
|
+
// handle input value change
|
|
385
|
+
useEffect(() => {
|
|
386
|
+
if (inputRef.current) {
|
|
387
|
+
if (!selected) {
|
|
388
|
+
inputRef.current.value = "";
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
inputRef.current.value = isObjectArray
|
|
392
|
+
? selected.label
|
|
393
|
+
: selected;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}, [selected]);
|
|
397
|
+
// handle scroll item into view
|
|
398
|
+
useEffect(() => {
|
|
399
|
+
var _a, _b;
|
|
400
|
+
const item = (_b = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector) === null || _b === void 0 ? void 0 : _b.call(_a, ".mfFloatingItem[data-selected=true]");
|
|
401
|
+
if (item) {
|
|
402
|
+
item.scrollIntoView({ block: "nearest" });
|
|
403
|
+
}
|
|
404
|
+
}, [selected]);
|
|
405
|
+
// make calls to onSearch callback
|
|
406
|
+
useEffect(() => {
|
|
407
|
+
if (searchable) {
|
|
408
|
+
update();
|
|
409
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch(searchValue);
|
|
410
|
+
}
|
|
411
|
+
}, [searchValue]);
|
|
412
|
+
const referenceEl = (_b = refs === null || refs === void 0 ? void 0 : refs.reference) === null || _b === void 0 ? void 0 : _b.current;
|
|
413
|
+
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%";
|
|
414
|
+
const scrollEl = scrollContainerRef === null || scrollContainerRef === void 0 ? void 0 : scrollContainerRef.current;
|
|
415
|
+
const scrollActive = scrollEl
|
|
416
|
+
? (scrollEl === null || scrollEl === void 0 ? void 0 : scrollEl.scrollHeight) > (scrollEl === null || scrollEl === void 0 ? void 0 : scrollEl.clientHeight)
|
|
417
|
+
: false;
|
|
418
|
+
// get height between bottom of the floating container and the bottom of the viewport
|
|
419
|
+
const bottomHeight = window.innerHeight - ((_f = referenceEl === null || referenceEl === void 0 ? void 0 : referenceEl.getBoundingClientRect()) === null || _f === void 0 ? void 0 : _f.bottom) - 10;
|
|
420
|
+
// get height between top of the floating container and the top of the viewport
|
|
421
|
+
const topHeight = (((_g = referenceEl === null || referenceEl === void 0 ? void 0 : referenceEl.getBoundingClientRect()) === null || _g === void 0 ? void 0 : _g.top) -
|
|
422
|
+
10);
|
|
423
|
+
useEffect(() => {
|
|
424
|
+
if (bottomHeight < 250) {
|
|
425
|
+
setPlacement("top-start");
|
|
426
|
+
setDropDownHeight(topHeight);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
setPlacement("bottom-start");
|
|
430
|
+
setDropDownHeight(bottomHeight);
|
|
431
|
+
}
|
|
432
|
+
return () => {
|
|
433
|
+
setPlacement("bottom-start");
|
|
434
|
+
setDropDownHeight(bottomHeight);
|
|
435
|
+
};
|
|
436
|
+
}, [topHeight, bottomHeight, isOpen]);
|
|
437
|
+
return (_jsxs("div", { className: className, children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInputContainer, { ref: refs.setReference, onMouseDown: () => setIsOpen(true), width: width, onKeyDown: handleKeyDown, "data-open": isOpen, children: [_jsx(Input, { ref: inputRef, onChange: debouncedHandleOnChange, onFocus: handleFocus, autoFocus: focused, placeholder: placeholder, size: size, readOnly: !searchable, "data-button-right": arrow || clearable }), clearable && (selected || !!((_h = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _h === void 0 ? void 0 : _h.value)) ? (_jsx(ClearButton, { className: "input-btn", onClick: handleClear })) : arrow ? (_jsx(ArrowButton, { onClick: (e) => {
|
|
438
|
+
e.preventDefault();
|
|
439
|
+
// e.stopPropagation();
|
|
440
|
+
}, onMouseDown: (e) => {
|
|
441
|
+
e.preventDefault();
|
|
442
|
+
e.stopPropagation();
|
|
443
|
+
toggleOpen();
|
|
444
|
+
} })) : null] }), isOpen && (_jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(StyledFloatContainer, { ref: (ref) => {
|
|
445
|
+
containerRef.current = ref;
|
|
446
|
+
refs.setFloating(ref);
|
|
447
|
+
}, style: floatingStyles, className: "mfFloating", children: _jsxs(StyledContent, Object.assign({ className: "mfFloatingContent", style: {
|
|
448
|
+
width: contentWidth,
|
|
449
|
+
maxWidth: contentWidth,
|
|
450
|
+
maxHeight: DropDownProps.autoHeight
|
|
451
|
+
? (dropDownHeight || 250) - 10
|
|
452
|
+
: "",
|
|
453
|
+
}, variant: variant, "data-empty": filteredItems.length === 0 }, DropDownProps, { children: [actionComponent && _jsx(ActionMenu, { children: actionComponent }), _jsxs(StyledInnerItemContainer, { ref: scrollContainerRef, "data-scroll-active": scrollActive, onScroll: onScroll, children: [loading && _jsx("div", { children: "Loading..." }), !loading && grouped
|
|
454
|
+
? groups.map((group, index) => (_jsxs("div", { children: [_jsx(GroupTitle, { size: size, children: group.label }), group.items.map((item, index) => {
|
|
455
|
+
return (_jsx(Tooltip, { content: TooltipContent ? (_jsx(TooltipContent, { data: item.data })) : null, side: "left", children: _jsx(StyledItem, { className: "mfFloatingItem", onClick: (e) => handleItemClick(e, item), "data-selected": isObjectArray
|
|
456
|
+
? (selected === null || selected === void 0 ? void 0 : selected.value) ===
|
|
457
|
+
item.value
|
|
458
|
+
: selected === 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));
|
|
459
|
+
})] }, group.label)))
|
|
460
|
+
: filteredItems.map((item, index) => {
|
|
461
|
+
return (_jsx(Tooltip, { content: TooltipContent ? (_jsx(TooltipContent, { data: item.data })) : null, side: "left", children: _jsx(StyledItem, { className: "mfFloatingItem", onClick: (e) => handleItemClick(e, item), "data-selected": isObjectArray
|
|
462
|
+
? (selected === null || selected === void 0 ? void 0 : selected.value) ===
|
|
463
|
+
(item === null || item === void 0 ? void 0 : item.value)
|
|
464
|
+
: selected === 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));
|
|
465
|
+
})] })] })) }) }))] }));
|
|
466
|
+
}) `
|
|
467
|
+
position: relative;
|
|
468
|
+
cursor: pointer;
|
|
469
|
+
width: 100%;
|
|
470
|
+
`;
|
|
471
|
+
export default SelectBox;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./SelectBox";
|
|
@@ -0,0 +1,129 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
13
|
+
import styled from "styled-components";
|
|
14
|
+
import * as RadixSwitch from "@radix-ui/react-switch";
|
|
15
|
+
import { FieldLabel } from "..";
|
|
16
|
+
const StyledRoot = styled(RadixSwitch.Root) `
|
|
17
|
+
all: unset;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
|
|
20
|
+
height: ${({ size }) => size === "xs"
|
|
21
|
+
? "10px"
|
|
22
|
+
: size === "sm"
|
|
23
|
+
? "16px"
|
|
24
|
+
: size === "md"
|
|
25
|
+
? "22px"
|
|
26
|
+
: size === "lg"
|
|
27
|
+
? "28px"
|
|
28
|
+
: size === "xl"
|
|
29
|
+
? "32px"
|
|
30
|
+
: "16px"};
|
|
31
|
+
|
|
32
|
+
width: ${({ size }) => size === "xs"
|
|
33
|
+
? "26px"
|
|
34
|
+
: size === "sm"
|
|
35
|
+
? "35px"
|
|
36
|
+
: size === "md"
|
|
37
|
+
? "28px"
|
|
38
|
+
: size === "lg"
|
|
39
|
+
? "34px"
|
|
40
|
+
: size === "xl"
|
|
41
|
+
? "70px"
|
|
42
|
+
: "26px"};
|
|
43
|
+
|
|
44
|
+
background-color: ${({ theme }) => theme.name === "DARK" ? "#383838" : "#e3e3e3"};
|
|
45
|
+
transition: background-color 100ms;
|
|
46
|
+
border-radius: 9999px;
|
|
47
|
+
border: 1px solid
|
|
48
|
+
${({ theme }) => theme.name === "DARK" ? theme.palette.input.border : "#e3e3e3"};
|
|
49
|
+
position: relative;
|
|
50
|
+
padding: ${({ size }) => size === "xs"
|
|
51
|
+
? "2px"
|
|
52
|
+
: size === "sm"
|
|
53
|
+
? "2px"
|
|
54
|
+
: size === "md"
|
|
55
|
+
? "28px"
|
|
56
|
+
: size === "lg"
|
|
57
|
+
? "34px"
|
|
58
|
+
: size === "xl"
|
|
59
|
+
? "2px 4px"
|
|
60
|
+
: "2px"};
|
|
61
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
62
|
+
|
|
63
|
+
&[data-state="checked"] {
|
|
64
|
+
background-color: ${({ theme }) => theme.palette.primary.main};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// disabled styleing
|
|
68
|
+
:disabled {
|
|
69
|
+
pointer-events: none;
|
|
70
|
+
opacity: 0.5;
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
const StyledThumb = styled(RadixSwitch.Thumb) `
|
|
74
|
+
display: block;
|
|
75
|
+
width: ${({ size }) => size === "xs"
|
|
76
|
+
? "9px"
|
|
77
|
+
: size === "sm"
|
|
78
|
+
? "14px"
|
|
79
|
+
: size === "md"
|
|
80
|
+
? "22px"
|
|
81
|
+
: size === "lg"
|
|
82
|
+
? "28px"
|
|
83
|
+
: size === "xl"
|
|
84
|
+
? "28px"
|
|
85
|
+
: "14px"};
|
|
86
|
+
|
|
87
|
+
height: ${({ size }) => size === "xs"
|
|
88
|
+
? "9px"
|
|
89
|
+
: size === "sm"
|
|
90
|
+
? "14px"
|
|
91
|
+
: size === "md"
|
|
92
|
+
? "22px"
|
|
93
|
+
: size === "lg"
|
|
94
|
+
? "28px"
|
|
95
|
+
: size === "xl"
|
|
96
|
+
? "28px"
|
|
97
|
+
: "14px"};
|
|
98
|
+
|
|
99
|
+
background-color: white;
|
|
100
|
+
border: none;
|
|
101
|
+
border-radius: 9999px;
|
|
102
|
+
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
|
|
103
|
+
transition: transform 100ms;
|
|
104
|
+
will-change: transform;
|
|
105
|
+
|
|
106
|
+
&[data-state="checked"] {
|
|
107
|
+
transform: ${({ size }) => size === "xs"
|
|
108
|
+
? "translateX(17px)"
|
|
109
|
+
: size === "sm"
|
|
110
|
+
? "translateX(20px)"
|
|
111
|
+
: size === "md"
|
|
112
|
+
? "translateX(26px)"
|
|
113
|
+
: size === "lg"
|
|
114
|
+
? "translateX(32px)"
|
|
115
|
+
: size === "xl"
|
|
116
|
+
? "translateX(42px)"
|
|
117
|
+
: "translateX(17px)"};
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
const Switch = styled((_a) => {
|
|
121
|
+
var { className, onChange, size = "xs", label, labelPosition = "right", description, error, required, disabled = false, defaultValue, value, style = {} } = _a, other = __rest(_a, ["className", "onChange", "size", "label", "labelPosition", "description", "error", "required", "disabled", "defaultValue", "value", "style"]);
|
|
122
|
+
return (_jsxs("div", { className: className, children: [label && labelPosition === "left" && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsx(StyledRoot, Object.assign({ size: size, className: "SwitchRoot", onCheckedChange: onChange, defaultChecked: defaultValue, checked: value, disabled: disabled, style: style }, other, { children: _jsx(StyledThumb, { size: size, className: "SwitchThumb" }) })), label && labelPosition === "right" && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label }))] }));
|
|
123
|
+
}) `
|
|
124
|
+
display: flex;
|
|
125
|
+
flex-direction: row;
|
|
126
|
+
align-items: center;
|
|
127
|
+
gap: 10px;
|
|
128
|
+
`;
|
|
129
|
+
export default Switch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Switch";
|