@monolith-forensics/monolith-ui 1.2.91 → 1.2.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Button/Button.d.ts +1 -0
- package/dist/Button/Button.js +3 -2
- package/dist/Calendar/CalendarStyles.d.ts +5 -15
- package/dist/Calendar/calendarHelpers.d.ts +1 -1
- package/dist/CheckBox/CheckBox.js +6 -4
- package/dist/DateInput/DateInput.d.ts +5 -3
- package/dist/DateInput/DateInput.js +41 -25
- package/dist/DropDownMenu/DropDownMenu.d.ts +2 -45
- package/dist/DropDownMenu/DropDownMenu.js +9 -315
- package/dist/DropDownMenu/components/Menu.d.ts +2 -0
- package/dist/DropDownMenu/components/Menu.js +11 -0
- package/dist/DropDownMenu/components/MenuComponent.d.ts +2 -0
- package/dist/DropDownMenu/components/MenuComponent.js +117 -0
- package/dist/DropDownMenu/components/MenuContext.d.ts +7 -0
- package/dist/DropDownMenu/components/MenuContext.js +8 -0
- package/dist/DropDownMenu/components/MenuItem.d.ts +7 -0
- package/dist/DropDownMenu/components/MenuItem.js +99 -0
- package/dist/DropDownMenu/components/MenuItemList.d.ts +18 -0
- package/dist/DropDownMenu/components/MenuItemList.js +92 -0
- package/dist/DropDownMenu/components/SearchInput.d.ts +1 -0
- package/dist/DropDownMenu/components/SearchInput.js +4 -0
- package/dist/DropDownMenu/components/StyledContent.d.ts +2 -0
- package/dist/DropDownMenu/components/StyledContent.js +42 -0
- package/dist/DropDownMenu/components/StyledFloatContainer.d.ts +1 -0
- package/dist/DropDownMenu/components/StyledFloatContainer.js +5 -0
- package/dist/DropDownMenu/components/StyledInnerItemContainer.d.ts +1 -0
- package/dist/DropDownMenu/components/StyledInnerItemContainer.js +9 -0
- package/dist/DropDownMenu/components/index.d.ts +9 -0
- package/dist/DropDownMenu/components/index.js +9 -0
- package/dist/DropDownMenu/index.d.ts +1 -1
- package/dist/DropDownMenu/index.js +1 -0
- package/dist/DropDownMenu/types.d.ts +52 -0
- package/dist/FieldLabel/FieldLabel.d.ts +1 -1
- package/dist/FileViewer/FileViewer.d.ts +13 -0
- package/dist/FileViewer/FileViewer.js +180 -0
- package/dist/FileViewer/index.d.ts +1 -0
- package/dist/FileViewer/index.js +1 -0
- package/dist/FileViewer/viewers/CodeViewer.d.ts +6 -0
- package/dist/FileViewer/viewers/CodeViewer.js +106 -0
- package/dist/FileViewer/viewers/ImageViewer.d.ts +6 -0
- package/dist/FileViewer/viewers/ImageViewer.js +58 -0
- package/dist/FileViewer/viewers/OfficeViewer.d.ts +5 -0
- package/dist/FileViewer/viewers/OfficeViewer.js +70 -0
- package/dist/FileViewer/viewers/PdfViewer.d.ts +8 -0
- package/dist/FileViewer/viewers/PdfViewer.js +63 -0
- package/dist/FileViewer/viewers/PlainTextViewer.d.ts +4 -0
- package/dist/FileViewer/viewers/PlainTextViewer.js +62 -0
- package/dist/FileViewer/viewers/VideoViewer.d.ts +6 -0
- package/dist/FileViewer/viewers/VideoViewer.js +30 -0
- package/dist/FileViewer/viewers/index.d.ts +6 -0
- package/dist/FileViewer/viewers/index.js +6 -0
- package/dist/FormSection/FormSection.d.ts +10 -2
- package/dist/FormSection/FormSection.js +43 -8
- package/dist/IconButton/IconButton.d.ts +1 -3
- package/dist/Input/Input.js +5 -0
- package/dist/MonolithUIProvider/GlobalStyle.d.ts +1 -1
- package/dist/MonolithUIProvider/GlobalStyle.js +1 -1
- package/dist/MonolithUIProvider/MonolithUIProvider.d.ts +2 -2
- package/dist/MonolithUIProvider/MonolithUIProvider.js +8 -3
- package/dist/MonolithUIProvider/index.d.ts +2 -2
- package/dist/MonolithUIProvider/index.js +2 -2
- package/dist/MonolithUIProvider/useMonolithUITheme.d.ts +1 -2
- package/dist/MonolithUIProvider/useMonolithUITheme.js +1 -2
- package/dist/Pill/Pill.d.ts +2 -1
- package/dist/Pill/Pill.js +2 -2
- package/dist/QueryFilter/DefaultOperators.d.ts +2 -3
- package/dist/QueryFilter/DefaultOperators.js +2 -3
- package/dist/QueryFilter/QueryFilter.d.ts +2 -3
- package/dist/QueryFilter/QueryFilter.js +126 -49
- package/dist/QueryFilter/index.d.ts +4 -2
- package/dist/QueryFilter/index.js +4 -2
- package/dist/QueryFilter/types.d.ts +12 -8
- package/dist/QueryFilter/useFilterHelper.d.ts +20 -0
- package/dist/QueryFilter/useFilterHelper.js +61 -0
- package/dist/QueryFilter/useQueryFilter.d.ts +1 -2
- package/dist/QueryFilter/useQueryFilter.js +5 -2
- package/dist/RichTextEditor/Components/BubbleMenu.d.ts +3 -4
- package/dist/RichTextEditor/Components/BubbleMenu.js +29 -26
- package/dist/RichTextEditor/Components/ColorPicker.d.ts +4 -0
- package/dist/RichTextEditor/Components/ColorPicker.js +37 -0
- package/dist/RichTextEditor/Components/index.d.ts +1 -0
- package/dist/RichTextEditor/Components/index.js +1 -0
- package/dist/RichTextEditor/RichTextEditor.d.ts +2 -3
- package/dist/RichTextEditor/RichTextEditor.js +83 -86
- package/dist/RichTextEditor/Toolbar/ControlsGroup.d.ts +1 -3
- package/dist/RichTextEditor/Toolbar/Toolbar.d.ts +1 -1
- package/dist/RichTextEditor/Toolbar/Toolbar.js +10 -14
- package/dist/SelectBox/SelectBox.d.ts +1 -1
- package/dist/SelectBox/SelectBox.js +133 -92
- package/dist/SelectBox/types.d.ts +8 -5
- package/dist/Switch/Switch.js +4 -4
- package/dist/Table/ActionButton.d.ts +1 -3
- package/dist/Table/ActionCell.d.ts +1 -3
- package/dist/Table/SelectionCell.d.ts +1 -3
- package/dist/Table/StaticRows.d.ts +2 -2
- package/dist/Table/Table.d.ts +1 -2
- package/dist/Table/Table.js +9 -13
- package/dist/Table/TableComponents.d.ts +2 -6
- package/dist/Table/TableComponents.js +0 -5
- package/dist/Table/TableHeader.js +8 -2
- package/dist/Table/TableMenu/TableMenu.js +12 -10
- package/dist/Table/TableProvider.js +36 -30
- package/dist/Table/TableRow.js +5 -2
- package/dist/Table/VirtualIzedRows.d.ts +2 -2
- package/dist/Table/VirtualIzedRows.js +12 -10
- package/dist/Table/index.d.ts +1 -2
- package/dist/Table/index.js +1 -2
- package/dist/Table/types.d.ts +23 -3
- package/dist/TagBox/TagBox.d.ts +1 -1
- package/dist/TagBox/TagBox.js +180 -92
- package/dist/TagBox/TagBoxStyles.d.ts +1 -3
- package/dist/TagBox/types.d.ts +4 -2
- package/dist/TextArea/TextArea.d.ts +1 -3
- package/dist/Tooltip/Tooltip.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/theme/getTheme.d.ts +1 -1
- package/package.json +11 -5
- package/dist/RichTextEditor/Components/DefaultColorIcon.d.ts +0 -4
- package/dist/RichTextEditor/Components/DefaultColorIcon.js +0 -7
- package/dist/Table/Column.d.ts +0 -3
- package/dist/Table/Column.js +0 -5
|
@@ -1,284 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { FloatingFocusManager, FloatingList, FloatingNode, FloatingPortal, FloatingTree, autoUpdate, flip, offset, safePolygon, shift, useClick, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useHover, useInteractions, useListItem, useListNavigation, useMergeRefs, useRole, useTypeahead, } from "@floating-ui/react";
|
|
14
|
-
import React, { forwardRef, useRef, useState, } from "react";
|
|
15
|
-
import styled from "styled-components";
|
|
16
|
-
import { Button, Tooltip, CheckBox, Input } from "..";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
17
3
|
import { useDebouncedCallback } from "use-debounce";
|
|
18
|
-
import {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
outline: none;
|
|
22
|
-
`;
|
|
23
|
-
const StyledInnerItemContainer = styled.div `
|
|
24
|
-
display: flex;
|
|
25
|
-
flex-direction: column;
|
|
26
|
-
flex: 1 1 auto;
|
|
27
|
-
overflow: hidden;
|
|
28
|
-
`;
|
|
29
|
-
const MenuScrollContainer = styled.div `
|
|
30
|
-
overflow-y: auto;
|
|
31
|
-
|
|
32
|
-
&[data-scroll-active="true"] {
|
|
33
|
-
padding-right: 5px;
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
const SearchInput = forwardRef((props, ref) => _jsx(Input, Object.assign({ ref: ref, style: { marginBottom: 8 } }, props)));
|
|
37
|
-
const MenuItem = styled(React.forwardRef((_a, forwardedRef) => {
|
|
38
|
-
var { label, children, disabled, multiselect } = _a, props = __rest(_a, ["label", "children", "disabled", "multiselect"]);
|
|
39
|
-
const menu = React.useContext(MenuContext);
|
|
40
|
-
const item = useListItem({ label: disabled ? null : label });
|
|
41
|
-
const tree = useFloatingTree();
|
|
42
|
-
const isActive = item.index === menu.activeIndex;
|
|
43
|
-
return (_jsx(Button, Object.assign({}, props, { ref: useMergeRefs([item.ref, forwardedRef]), type: "button", role: "menuitem", tabIndex: isActive ? 0 : -1, disabled: disabled }, menu.getItemProps({
|
|
44
|
-
onClick(event) {
|
|
45
|
-
var _a;
|
|
46
|
-
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
47
|
-
tree === null || tree === void 0 ? void 0 : tree.events.emit("click");
|
|
48
|
-
},
|
|
49
|
-
onFocus(event) {
|
|
50
|
-
var _a;
|
|
51
|
-
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
52
|
-
menu.setHasFocusInside(true);
|
|
53
|
-
},
|
|
54
|
-
}), { children: label || children })));
|
|
55
|
-
})) `
|
|
56
|
-
&.MenuItem {
|
|
57
|
-
color: ${(props) => props.theme.palette.text.primary};
|
|
58
|
-
border-radius: 3px;
|
|
59
|
-
display: flex;
|
|
60
|
-
flex-direction: row;
|
|
61
|
-
gap: 5px;
|
|
62
|
-
align-items: center;
|
|
63
|
-
min-height: 25px;
|
|
64
|
-
width: 100%;
|
|
65
|
-
min-width: fit-content;
|
|
66
|
-
height: auto;
|
|
67
|
-
position: relative;
|
|
68
|
-
user-select: none;
|
|
69
|
-
outline: none;
|
|
70
|
-
|
|
71
|
-
border: none;
|
|
72
|
-
|
|
73
|
-
white-space: nowrap;
|
|
74
|
-
overflow: hidden;
|
|
75
|
-
text-overflow: ellipsis;
|
|
76
|
-
|
|
77
|
-
cursor: pointer;
|
|
78
|
-
text-decoration: none;
|
|
79
|
-
|
|
80
|
-
font-weight: normal;
|
|
81
|
-
letter-spacing: normal;
|
|
82
|
-
|
|
83
|
-
font-size: ${({ size }) => size === "xs"
|
|
84
|
-
? "11px"
|
|
85
|
-
: size === "sm"
|
|
86
|
-
? "13px"
|
|
87
|
-
: size === "md"
|
|
88
|
-
? "15px"
|
|
89
|
-
: size === "lg"
|
|
90
|
-
? "17px"
|
|
91
|
-
: size === "xl"
|
|
92
|
-
? "19px"
|
|
93
|
-
: "11px"};
|
|
94
|
-
|
|
95
|
-
padding: ${({ size }) => size === "xs"
|
|
96
|
-
? "2px 8px"
|
|
97
|
-
: size === "sm"
|
|
98
|
-
? "4px 10px"
|
|
99
|
-
: size === "md"
|
|
100
|
-
? "4px 12px"
|
|
101
|
-
: size === "lg"
|
|
102
|
-
? "5px 14px"
|
|
103
|
-
: size === "xl"
|
|
104
|
-
? "6px 16px"
|
|
105
|
-
: "2px 8px"};
|
|
106
|
-
|
|
107
|
-
&[data-disabled] {
|
|
108
|
-
color: ${(props) => props.theme.palette.text.secondary};
|
|
109
|
-
pointer-events: "none";
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
&:hover {
|
|
113
|
-
background-color: ${(props) => props.theme.palette.action.hover};
|
|
114
|
-
color: ${(props) => props.theme.palette.text.primary};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
&:active {
|
|
118
|
-
translate: none;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
.button-label {
|
|
122
|
-
display: flex;
|
|
123
|
-
flex-direction: row;
|
|
124
|
-
gap: 5px;
|
|
125
|
-
align-items: center;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
`;
|
|
129
|
-
const StyledContent = styled.div `
|
|
130
|
-
position: relative;
|
|
131
|
-
display: flex;
|
|
132
|
-
flex-direction: column;
|
|
133
|
-
box-sizing: border-box;
|
|
134
|
-
overflow-y: hidden;
|
|
135
|
-
overflow-x: hidden;
|
|
136
|
-
|
|
137
|
-
min-width: 150px;
|
|
138
|
-
max-width: 400px;
|
|
139
|
-
max-height: ${({ maxDropdownHeight }) => Number.isInteger(maxDropdownHeight)
|
|
140
|
-
? `${maxDropdownHeight}px`
|
|
141
|
-
: maxDropdownHeight || "250px"};
|
|
142
|
-
|
|
143
|
-
background-color: ${(props) => props.theme.palette.background.default};
|
|
144
|
-
background-color: ${({ theme, variant }) => {
|
|
145
|
-
switch (variant) {
|
|
146
|
-
case "filled":
|
|
147
|
-
return theme.palette.input.background;
|
|
148
|
-
case "outlined":
|
|
149
|
-
return theme.palette.input.background;
|
|
150
|
-
case "text":
|
|
151
|
-
return "transparent";
|
|
152
|
-
default:
|
|
153
|
-
return theme.palette.input.background;
|
|
154
|
-
}
|
|
155
|
-
}};
|
|
156
|
-
|
|
157
|
-
border-radius: 5px;
|
|
158
|
-
border: 1px solid ${(props) => props.theme.palette.divider};
|
|
159
|
-
outline: none;
|
|
160
|
-
padding: 5px;
|
|
161
|
-
animation-duration: 400ms;
|
|
162
|
-
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
|
|
163
|
-
will-change: transform, opacity;
|
|
164
|
-
|
|
165
|
-
&[data-empty="true"] {
|
|
166
|
-
display: none;
|
|
167
|
-
}
|
|
168
|
-
`;
|
|
169
|
-
const MenuContext = React.createContext({
|
|
170
|
-
getItemProps: () => ({}),
|
|
171
|
-
activeIndex: null,
|
|
172
|
-
setActiveIndex: () => { },
|
|
173
|
-
setHasFocusInside: () => { },
|
|
174
|
-
isOpen: false,
|
|
175
|
-
});
|
|
176
|
-
const MenuComponent = React.forwardRef((_a, forwardedRef) => {
|
|
177
|
-
var { children, label, arrow, size, buttonSize, variant, buttonProps, buttonRender, multiselect } = _a, props = __rest(_a, ["children", "label", "arrow", "size", "buttonSize", "variant", "buttonProps", "buttonRender", "multiselect"]);
|
|
178
|
-
const [isOpen, setIsOpen] = React.useState(false);
|
|
179
|
-
const [hasFocusInside, setHasFocusInside] = React.useState(false);
|
|
180
|
-
const [activeIndex, setActiveIndex] = React.useState(null);
|
|
181
|
-
const elementsRef = React.useRef([]);
|
|
182
|
-
const labelsRef = React.useRef([]);
|
|
183
|
-
const parent = React.useContext(MenuContext);
|
|
184
|
-
const tree = useFloatingTree();
|
|
185
|
-
const nodeId = useFloatingNodeId();
|
|
186
|
-
const parentId = useFloatingParentNodeId();
|
|
187
|
-
const item = useListItem();
|
|
188
|
-
const isNested = parentId != null;
|
|
189
|
-
const { floatingStyles, refs, context } = useFloating({
|
|
190
|
-
nodeId,
|
|
191
|
-
open: isOpen,
|
|
192
|
-
onOpenChange: setIsOpen,
|
|
193
|
-
placement: isNested ? "right-start" : "bottom-start",
|
|
194
|
-
middleware: [
|
|
195
|
-
offset({
|
|
196
|
-
mainAxis: isNested ? 0 : 2,
|
|
197
|
-
alignmentAxis: isNested ? -4 : 0,
|
|
198
|
-
}),
|
|
199
|
-
flip(),
|
|
200
|
-
shift(),
|
|
201
|
-
],
|
|
202
|
-
whileElementsMounted: autoUpdate,
|
|
203
|
-
});
|
|
204
|
-
const hover = useHover(context, {
|
|
205
|
-
enabled: isNested,
|
|
206
|
-
delay: { open: 75 },
|
|
207
|
-
handleClose: safePolygon({ blockPointerEvents: true }),
|
|
208
|
-
});
|
|
209
|
-
const click = useClick(context, {
|
|
210
|
-
event: "click",
|
|
211
|
-
toggle: !isNested,
|
|
212
|
-
ignoreMouse: isNested,
|
|
213
|
-
});
|
|
214
|
-
const role = useRole(context, { role: "menu" });
|
|
215
|
-
const dismiss = useDismiss(context, { bubbles: true });
|
|
216
|
-
const listNavigation = useListNavigation(context, {
|
|
217
|
-
listRef: elementsRef,
|
|
218
|
-
activeIndex,
|
|
219
|
-
nested: isNested,
|
|
220
|
-
onNavigate: setActiveIndex,
|
|
221
|
-
});
|
|
222
|
-
const typeahead = useTypeahead(context, {
|
|
223
|
-
listRef: labelsRef,
|
|
224
|
-
onMatch: isOpen ? setActiveIndex : undefined,
|
|
225
|
-
activeIndex,
|
|
226
|
-
});
|
|
227
|
-
const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([hover, click, role, dismiss]);
|
|
228
|
-
// Event emitter allows you to communicate across tree components.
|
|
229
|
-
// This effect closes all menus when an item gets clicked anywhere
|
|
230
|
-
// in the tree.
|
|
231
|
-
React.useEffect(() => {
|
|
232
|
-
if (!tree)
|
|
233
|
-
return;
|
|
234
|
-
function handleTreeClick() {
|
|
235
|
-
if (!multiselect) {
|
|
236
|
-
setIsOpen(false);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
function onSubMenuOpen(event) {
|
|
240
|
-
if (event.nodeId !== nodeId && event.parentId === parentId) {
|
|
241
|
-
setIsOpen(false);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
tree.events.on("click", handleTreeClick);
|
|
245
|
-
tree.events.on("menuopen", onSubMenuOpen);
|
|
246
|
-
return () => {
|
|
247
|
-
tree.events.off("click", handleTreeClick);
|
|
248
|
-
tree.events.off("menuopen", onSubMenuOpen);
|
|
249
|
-
};
|
|
250
|
-
}, [tree, nodeId, parentId]);
|
|
251
|
-
React.useEffect(() => {
|
|
252
|
-
if (isOpen && tree) {
|
|
253
|
-
tree.events.emit("menuopen", { parentId, nodeId });
|
|
254
|
-
}
|
|
255
|
-
}, [tree, isOpen, nodeId, parentId]);
|
|
256
|
-
return (_jsxs(FloatingNode, { id: nodeId, children: [_jsx(MenuItem, Object.assign({ ref: useMergeRefs([refs.setReference, item.ref, forwardedRef]), tabIndex: !isNested ? undefined : parent.activeIndex === item.index ? 0 : -1, role: isNested ? "menuitem" : undefined, className: isNested ? `MenuItem` : "mfui-DropDownMenu RootMenu", "data-open": isOpen ? "" : undefined, "data-nested": isNested ? "" : undefined, "data-focus-inside": hasFocusInside ? "" : undefined }, getReferenceProps(parent.getItemProps(Object.assign(Object.assign({}, props), { onFocus(event) {
|
|
257
|
-
var _a;
|
|
258
|
-
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
259
|
-
setHasFocusInside(false);
|
|
260
|
-
parent.setHasFocusInside(true);
|
|
261
|
-
} }))), { rightSection: arrow ? (_jsx(ChevronDownIcon, { size: 12 })) : isNested ? (_jsx(ChevronRightIcon, { size: 12 })) : null, size: buttonSize, variant: variant, selected: isOpen }, buttonProps, { children: label })), _jsx(MenuContext.Provider, { value: {
|
|
262
|
-
activeIndex,
|
|
263
|
-
setActiveIndex,
|
|
264
|
-
getItemProps,
|
|
265
|
-
setHasFocusInside,
|
|
266
|
-
isOpen,
|
|
267
|
-
}, children: _jsx(FloatingList, { elementsRef: elementsRef, labelsRef: labelsRef, children: isOpen && (_jsx(FloatingPortal, { children: _jsx(FloatingFocusManager, { context: context, modal: false, initialFocus: isNested ? -1 : 0, returnFocus: !isNested, children: _jsx(StyledFloatContainer, Object.assign({ ref: refs.setFloating, className: "Menu", style: floatingStyles }, getFloatingProps(), { children: _jsx(StyledContent, { className: "mfFloatingContent", children: children }) })) }) })) }) })] }));
|
|
268
|
-
});
|
|
269
|
-
export const Menu = React.forwardRef((props, ref) => {
|
|
270
|
-
const parentId = useFloatingParentNodeId();
|
|
271
|
-
if (parentId === null) {
|
|
272
|
-
return (_jsx(FloatingTree, { children: _jsx(MenuComponent, Object.assign({}, props, { ref: ref })) }));
|
|
273
|
-
}
|
|
274
|
-
return _jsx(MenuComponent, Object.assign({}, props, { ref: ref }));
|
|
275
|
-
});
|
|
276
|
-
const DropDownMenu = ({ data, children, defaultValue, variant, arrow, size, searchable, loading, onScroll, multiselect, renderOption, onItemSelect, onChange, buttonProps, TooltipContent, }) => {
|
|
277
|
-
var _a, _b, _c;
|
|
4
|
+
import { Menu, MenuItemList, SearchInput, StyledInnerItemContainer, } from "./components";
|
|
5
|
+
const DropDownMenu = ({ data, children, defaultValue, variant, arrow, size, searchable, loading, onScroll, multiselect, renderOption, onItemSelect, onChange, buttonProps, TooltipContent, dropDownProps, }) => {
|
|
6
|
+
var _a;
|
|
278
7
|
const isObjectArray = (_a = Object.keys((data === null || data === void 0 ? void 0 : data[0]) || {})) === null || _a === void 0 ? void 0 : _a.includes("label");
|
|
279
8
|
const [selected, setSelected] = useState(defaultValue || []);
|
|
280
9
|
const [searchValue, setSearchValue] = useState("");
|
|
281
|
-
const scrollContainerRef = useRef(null);
|
|
282
10
|
const searchInputRef = useRef(null);
|
|
283
11
|
const handleSearch = useDebouncedCallback((e) => {
|
|
284
12
|
setSearchValue(e.target.value);
|
|
@@ -299,43 +27,9 @@ const DropDownMenu = ({ data, children, defaultValue, variant, arrow, size, sear
|
|
|
299
27
|
return newSelected;
|
|
300
28
|
});
|
|
301
29
|
};
|
|
302
|
-
const
|
|
303
|
-
(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
.filter((item) => {
|
|
307
|
-
var _a, _b, _c;
|
|
308
|
-
if (!searchable)
|
|
309
|
-
return true;
|
|
310
|
-
if (isObjectArray) {
|
|
311
|
-
return (((_a = item === null || item === void 0 ? void 0 : item.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(searchValue.toLowerCase())) ||
|
|
312
|
-
((_b = item === null || item === void 0 ? void 0 : item.value) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(searchValue.toLowerCase())));
|
|
313
|
-
}
|
|
314
|
-
return (_c = item.toLowerCase) === null || _c === void 0 ? void 0 : _c.call(item).includes(searchValue.toLowerCase());
|
|
315
|
-
})
|
|
316
|
-
.map((item, index) => {
|
|
317
|
-
const isSelected = !!(selected === null || selected === void 0 ? void 0 : selected.find((s) => isObjectArray ? (s === null || s === void 0 ? void 0 : s.value) === (item === null || item === void 0 ? void 0 : item.value) : s === item));
|
|
318
|
-
if (item.items) {
|
|
319
|
-
return (_jsx(DropDownMenu, { data: item.items, children: item.label }));
|
|
320
|
-
}
|
|
321
|
-
return (_jsx(Tooltip, { content: TooltipContent ? (_jsx(TooltipContent, { data: item.data })) : null, side: "left", children: _jsxs(MenuItem, { className: "MenuItem", "data-selected": isSelected, leftSection: multiselect && (_jsx(CheckBox, { value: isSelected, size: size, onChange: (newValue) => {
|
|
322
|
-
var _a;
|
|
323
|
-
newValue
|
|
324
|
-
? handleAddItem(item)
|
|
325
|
-
: handleRemoveItem(item);
|
|
326
|
-
(_a = item === null || item === void 0 ? void 0 : item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, item);
|
|
327
|
-
} })), multiselect: multiselect, size: size, onClick: (e) => {
|
|
328
|
-
var _a;
|
|
329
|
-
e.preventDefault();
|
|
330
|
-
e.stopPropagation();
|
|
331
|
-
if (multiselect) {
|
|
332
|
-
isSelected
|
|
333
|
-
? handleRemoveItem(item)
|
|
334
|
-
: handleAddItem(item);
|
|
335
|
-
}
|
|
336
|
-
onItemSelect === null || onItemSelect === void 0 ? void 0 : onItemSelect(item);
|
|
337
|
-
(_a = item === null || item === void 0 ? void 0 : item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, item);
|
|
338
|
-
}, children: [(item === null || item === void 0 ? void 0 : item.leftSection) || null, _jsx(_Fragment, { children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (item === null || item === void 0 ? void 0 : item.label) || item }), (item === null || item === void 0 ? void 0 : item.rightSection) || null] }, index) }, index));
|
|
339
|
-
}) })] }) }));
|
|
30
|
+
const handleMenuClose = () => {
|
|
31
|
+
setSearchValue("");
|
|
32
|
+
};
|
|
33
|
+
return (_jsx(Menu, { label: children, arrow: arrow, buttonSize: size, variant: variant, multiselect: multiselect, buttonProps: buttonProps, onMenuClose: handleMenuClose, dropDownProps: dropDownProps, children: _jsxs(StyledInnerItemContainer, { children: [loading && _jsx("div", { children: "Loading..." }), searchable && (_jsx(SearchInput, { ref: searchInputRef, variant: "outlined", size: size, placeholder: "Search", defaultValue: searchValue, onChange: handleSearch })), !loading && (_jsx(MenuItemList, { menuItems: data, searchable: searchable, searchValue: searchValue, isObjectArray: isObjectArray, selected: selected, TooltipContent: TooltipContent, multiselect: multiselect, size: size, handleAddItem: handleAddItem, handleRemoveItem: handleRemoveItem, onItemSelect: onItemSelect, renderOption: renderOption, onScroll: onScroll }))] }) }));
|
|
340
34
|
};
|
|
341
35
|
export default DropDownMenu;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { FloatingTree, useFloatingParentNodeId } from "@floating-ui/react";
|
|
4
|
+
import { MenuComponent } from "./MenuComponent";
|
|
5
|
+
export const Menu = forwardRef((props, ref) => {
|
|
6
|
+
const parentId = useFloatingParentNodeId();
|
|
7
|
+
if (parentId === null) {
|
|
8
|
+
return (_jsx(FloatingTree, { children: _jsx(MenuComponent, Object.assign({}, props, { ref: ref })) }));
|
|
9
|
+
}
|
|
10
|
+
return _jsx(MenuComponent, Object.assign({}, props, { ref: ref }));
|
|
11
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
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 { forwardRef, useContext, useEffect, useRef, useState } from "react";
|
|
14
|
+
import { autoUpdate, flip, FloatingFocusManager, FloatingList, FloatingNode, FloatingPortal, offset, safePolygon, shift, useClick, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useHover, useInteractions, useListItem, useListNavigation, useMergeRefs, useRole, useTypeahead, } from "@floating-ui/react";
|
|
15
|
+
import { ChevronDownIcon, ChevronRightIcon } from "lucide-react";
|
|
16
|
+
import { MenuContext } from "./MenuContext";
|
|
17
|
+
import { StyledFloatContainer } from "./StyledFloatContainer";
|
|
18
|
+
import { StyledContent } from "./StyledContent";
|
|
19
|
+
import { MenuItem } from "./MenuItem";
|
|
20
|
+
export const MenuComponent = forwardRef((_a, forwardedRef) => {
|
|
21
|
+
var { children, label, arrow, size, buttonSize, variant, buttonProps, buttonRender, multiselect, onMenuClose, dropDownProps } = _a, props = __rest(_a, ["children", "label", "arrow", "size", "buttonSize", "variant", "buttonProps", "buttonRender", "multiselect", "onMenuClose", "dropDownProps"]);
|
|
22
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
23
|
+
const [hasFocusInside, setHasFocusInside] = useState(false);
|
|
24
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
25
|
+
const elementsRef = useRef([]);
|
|
26
|
+
const labelsRef = useRef([]);
|
|
27
|
+
const parent = useContext(MenuContext);
|
|
28
|
+
const tree = useFloatingTree();
|
|
29
|
+
const nodeId = useFloatingNodeId();
|
|
30
|
+
const parentId = useFloatingParentNodeId();
|
|
31
|
+
const item = useListItem();
|
|
32
|
+
const isNested = parentId != null;
|
|
33
|
+
const { floatingStyles, refs, context } = useFloating({
|
|
34
|
+
nodeId,
|
|
35
|
+
open: isOpen,
|
|
36
|
+
onOpenChange: setIsOpen,
|
|
37
|
+
placement: isNested ? "right-start" : "bottom-start",
|
|
38
|
+
middleware: [
|
|
39
|
+
offset({
|
|
40
|
+
mainAxis: isNested ? 0 : 2,
|
|
41
|
+
alignmentAxis: isNested ? -4 : 0,
|
|
42
|
+
}),
|
|
43
|
+
flip(),
|
|
44
|
+
shift(),
|
|
45
|
+
],
|
|
46
|
+
whileElementsMounted: autoUpdate,
|
|
47
|
+
});
|
|
48
|
+
const hover = useHover(context, {
|
|
49
|
+
enabled: isNested,
|
|
50
|
+
delay: { open: 75 },
|
|
51
|
+
handleClose: safePolygon({ blockPointerEvents: true }),
|
|
52
|
+
});
|
|
53
|
+
const click = useClick(context, {
|
|
54
|
+
event: "click",
|
|
55
|
+
toggle: true,
|
|
56
|
+
ignoreMouse: false,
|
|
57
|
+
});
|
|
58
|
+
const role = useRole(context, { role: "menu" });
|
|
59
|
+
const dismiss = useDismiss(context, { bubbles: true });
|
|
60
|
+
const listNavigation = useListNavigation(context, {
|
|
61
|
+
listRef: elementsRef,
|
|
62
|
+
activeIndex,
|
|
63
|
+
nested: isNested,
|
|
64
|
+
onNavigate: setActiveIndex,
|
|
65
|
+
});
|
|
66
|
+
const typeahead = useTypeahead(context, {
|
|
67
|
+
listRef: labelsRef,
|
|
68
|
+
onMatch: isOpen ? setActiveIndex : undefined,
|
|
69
|
+
activeIndex,
|
|
70
|
+
});
|
|
71
|
+
const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([hover, click, role, dismiss]);
|
|
72
|
+
// Event emitter allows you to communicate across tree components.
|
|
73
|
+
// This effect closes all menus when an item gets clicked anywhere
|
|
74
|
+
// in the tree.
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!tree)
|
|
77
|
+
return;
|
|
78
|
+
function handleTreeClick(event) {
|
|
79
|
+
if (!multiselect && !event.nested) {
|
|
80
|
+
setIsOpen(false);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function onSubMenuOpen(event) {
|
|
84
|
+
if (event.nodeId !== nodeId && event.parentId === parentId) {
|
|
85
|
+
setIsOpen(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
tree.events.on("click", handleTreeClick);
|
|
89
|
+
tree.events.on("menuopen", onSubMenuOpen);
|
|
90
|
+
return () => {
|
|
91
|
+
tree.events.off("click", handleTreeClick);
|
|
92
|
+
tree.events.off("menuopen", onSubMenuOpen);
|
|
93
|
+
};
|
|
94
|
+
}, [tree, nodeId, parentId]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (isOpen && tree) {
|
|
97
|
+
tree.events.emit("menuopen", { parentId, nodeId });
|
|
98
|
+
}
|
|
99
|
+
}, [tree, isOpen, nodeId, parentId]);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!isOpen) {
|
|
102
|
+
onMenuClose === null || onMenuClose === void 0 ? void 0 : onMenuClose();
|
|
103
|
+
}
|
|
104
|
+
}, [isOpen]);
|
|
105
|
+
return (_jsxs(FloatingNode, { id: nodeId, children: [_jsx(MenuItem, Object.assign({ ref: useMergeRefs([refs.setReference, item.ref, forwardedRef]), tabIndex: !isNested ? undefined : parent.activeIndex === item.index ? 0 : -1, role: isNested ? "menuitem" : undefined, className: isNested ? `MenuItem` : "mfui-DropDownMenu RootMenu", "data-open": isOpen ? "" : undefined, "data-nested": isNested ? "" : undefined, "data-focus-inside": hasFocusInside ? "" : undefined }, getReferenceProps(parent.getItemProps(Object.assign(Object.assign({}, props), { onFocus(event) {
|
|
106
|
+
var _a;
|
|
107
|
+
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
108
|
+
setHasFocusInside(false);
|
|
109
|
+
parent.setHasFocusInside(true);
|
|
110
|
+
} }))), { rightSection: arrow ? (_jsx(ChevronDownIcon, { size: 12 })) : isNested ? (_jsx(ChevronRightIcon, { size: 12 })) : null, size: buttonSize, variant: variant, selected: isOpen, nested: isNested }, buttonProps, { children: label })), _jsx(MenuContext.Provider, { value: {
|
|
111
|
+
activeIndex,
|
|
112
|
+
setActiveIndex,
|
|
113
|
+
getItemProps,
|
|
114
|
+
setHasFocusInside,
|
|
115
|
+
isOpen,
|
|
116
|
+
}, children: _jsx(FloatingList, { elementsRef: elementsRef, labelsRef: labelsRef, children: isOpen && (_jsx(FloatingPortal, { children: _jsx(FloatingFocusManager, { context: context, modal: false, initialFocus: isNested ? -1 : 0, returnFocus: !isNested, children: _jsx(StyledFloatContainer, Object.assign({ ref: refs.setFloating, className: "Menu", style: floatingStyles }, getFloatingProps(), { children: _jsx(StyledContent, Object.assign({ className: "mfFloatingContent" }, dropDownProps, { children: children })) })) }) })) }) })] }));
|
|
117
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const MenuContext: import("react").Context<{
|
|
2
|
+
getItemProps: (userProps?: React.HTMLProps<HTMLElement>) => Record<string, unknown>;
|
|
3
|
+
activeIndex: number | null;
|
|
4
|
+
setActiveIndex: React.Dispatch<React.SetStateAction<number | null>>;
|
|
5
|
+
setHasFocusInside: React.Dispatch<React.SetStateAction<boolean>>;
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MenuProps } from "../types";
|
|
2
|
+
import { ButtonProps } from "../../Button";
|
|
3
|
+
export declare const MenuItem: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<MenuProps & ButtonProps & {
|
|
4
|
+
multiselect?: boolean;
|
|
5
|
+
} & import("react").ButtonHTMLAttributes<HTMLButtonElement> & import("react").RefAttributes<unknown>, never>> & string & Omit<import("react").ForwardRefExoticComponent<MenuProps & ButtonProps & {
|
|
6
|
+
multiselect?: boolean;
|
|
7
|
+
} & import("react").ButtonHTMLAttributes<HTMLButtonElement> & import("react").RefAttributes<unknown>>, keyof import("react").Component<any, {}, any>>;
|
|
@@ -0,0 +1,99 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef, useContext } from "react";
|
|
14
|
+
import styled from "styled-components";
|
|
15
|
+
import Button from "../../Button";
|
|
16
|
+
import { useFloatingTree, useListItem, useMergeRefs } from "@floating-ui/react";
|
|
17
|
+
import { MenuContext } from "./MenuContext";
|
|
18
|
+
import Tooltip from "../../Tooltip";
|
|
19
|
+
export const MenuItem = styled(forwardRef((_a, forwardedRef) => {
|
|
20
|
+
var { label, children, disabled, multiselect, TooltipContent, itemData, nested } = _a, props = __rest(_a, ["label", "children", "disabled", "multiselect", "TooltipContent", "itemData", "nested"]);
|
|
21
|
+
const menu = useContext(MenuContext);
|
|
22
|
+
const item = useListItem({ label: disabled ? null : label });
|
|
23
|
+
const tree = useFloatingTree();
|
|
24
|
+
const isActive = item.index === menu.activeIndex;
|
|
25
|
+
return (_jsx(Tooltip, { content: TooltipContent ? _jsx(TooltipContent, { data: itemData }) : null, side: "left", children: _jsx(Button, Object.assign({}, props, { ref: useMergeRefs([item.ref, forwardedRef]), type: "button", role: "menuitem", tabIndex: isActive ? 0 : -1, disabled: disabled, justify: "start" }, menu.getItemProps({
|
|
26
|
+
onClick(event) {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
29
|
+
tree === null || tree === void 0 ? void 0 : tree.events.emit("click", { nested });
|
|
30
|
+
},
|
|
31
|
+
onFocus(event) {
|
|
32
|
+
var _a;
|
|
33
|
+
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
34
|
+
menu.setHasFocusInside(true);
|
|
35
|
+
},
|
|
36
|
+
}), { children: label || children })) }));
|
|
37
|
+
})) `
|
|
38
|
+
&.MenuItem {
|
|
39
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
40
|
+
border-radius: 3px;
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: row;
|
|
43
|
+
gap: 5px;
|
|
44
|
+
align-items: center;
|
|
45
|
+
min-height: 25px;
|
|
46
|
+
width: 100%;
|
|
47
|
+
min-width: 100%;
|
|
48
|
+
height: auto;
|
|
49
|
+
position: relative;
|
|
50
|
+
user-select: none;
|
|
51
|
+
outline: none;
|
|
52
|
+
|
|
53
|
+
border: none;
|
|
54
|
+
|
|
55
|
+
white-space: nowrap;
|
|
56
|
+
overflow: hidden;
|
|
57
|
+
text-overflow: ellipsis;
|
|
58
|
+
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
text-decoration: none;
|
|
61
|
+
|
|
62
|
+
font-weight: normal;
|
|
63
|
+
letter-spacing: normal;
|
|
64
|
+
|
|
65
|
+
padding: ${({ size }) => size === "xs"
|
|
66
|
+
? "2px 8px"
|
|
67
|
+
: size === "sm"
|
|
68
|
+
? "4px 10px"
|
|
69
|
+
: size === "md"
|
|
70
|
+
? "4px 12px"
|
|
71
|
+
: size === "lg"
|
|
72
|
+
? "5px 14px"
|
|
73
|
+
: size === "xl"
|
|
74
|
+
? "6px 16px"
|
|
75
|
+
: "2px 8px"};
|
|
76
|
+
|
|
77
|
+
&[data-disabled="true"] {
|
|
78
|
+
opacity: 0.5;
|
|
79
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
80
|
+
pointer-events: "none";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&:hover {
|
|
84
|
+
background-color: ${(props) => props.theme.palette.action.hover};
|
|
85
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&:active {
|
|
89
|
+
translate: none;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.button-label {
|
|
93
|
+
display: inline-block;
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
text-overflow: ellipsis;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentType } from "react";
|
|
2
|
+
import { Size } from "../../core";
|
|
3
|
+
import { DropDownItem } from "../types";
|
|
4
|
+
export declare const MenuItemList: React.FC<{
|
|
5
|
+
menuItems: DropDownItem[];
|
|
6
|
+
searchable?: boolean;
|
|
7
|
+
searchValue?: string;
|
|
8
|
+
isObjectArray?: boolean;
|
|
9
|
+
selected?: DropDownItem[];
|
|
10
|
+
TooltipContent?: ComponentType<any>;
|
|
11
|
+
multiselect?: boolean;
|
|
12
|
+
size?: Size;
|
|
13
|
+
handleAddItem: (item: DropDownItem) => void;
|
|
14
|
+
handleRemoveItem: (item: DropDownItem) => void;
|
|
15
|
+
onItemSelect?: (item: DropDownItem) => void;
|
|
16
|
+
renderOption?: (item: DropDownItem) => React.ReactNode;
|
|
17
|
+
onScroll?: (e: Event) => void;
|
|
18
|
+
}>;
|