@monolith-forensics/monolith-ui 1.2.69 → 1.2.71
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 +1 -1
- package/dist/DropDownMenu/DropDownMenu.d.ts +1 -44
- package/dist/DropDownMenu/DropDownMenu.js +8 -314
- 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 +9 -0
- package/dist/DropDownMenu/components/MenuItem.js +110 -0
- package/dist/DropDownMenu/components/MenuItemList.d.ts +18 -0
- package/dist/DropDownMenu/components/MenuItemList.js +73 -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 +3 -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 +47 -0
- package/dist/RichTextEditor/Components/BubbleMenu.d.ts +1 -2
- package/dist/RichTextEditor/Toolbar/Toolbar.d.ts +1 -1
- package/dist/Table/TableHeader.js +8 -2
- package/package.json +1 -1
package/dist/Button/Button.js
CHANGED
|
@@ -326,7 +326,7 @@ const StyledLoader = styled.span `
|
|
|
326
326
|
`;
|
|
327
327
|
const Button = forwardRef((props, ref) => {
|
|
328
328
|
const { children, loading = false, leftSection = null, rightSection = null, href = null, download = null, justify = "center" } = props, other = __rest(props, ["children", "loading", "leftSection", "rightSection", "href", "download", "justify"]);
|
|
329
|
-
const buttonContent = (_jsx("
|
|
329
|
+
const buttonContent = (_jsx("div", { className: "inner-span", style: { height: "100%", width: "100%", justifyContent: justify }, children: loading ? (_jsx(StyledLoader, { children: _jsx(Loader2Icon, {}) })) : (_jsxs(_Fragment, { children: [leftSection && _jsx("div", { "data-position": "left", children: leftSection }), _jsx("div", { className: "button-label", children: children }), rightSection && _jsx("div", { "data-position": "right", children: rightSection })] })) }));
|
|
330
330
|
return (_jsx(StyledButton, Object.assign({ ref: ref }, other, { children: href ? (_jsx(StyledAnchor, { href: href, download: download, children: buttonContent })) : (buttonContent) })));
|
|
331
331
|
});
|
|
332
332
|
export default Button;
|
|
@@ -1,46 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ButtonProps } from "../Button";
|
|
3
|
-
import { Size, Variant } from "../core";
|
|
4
|
-
import { DropDownItem } from "./types";
|
|
5
|
-
interface StyledContentProps {
|
|
6
|
-
maxDropdownHeight?: number | string;
|
|
7
|
-
variant?: Variant;
|
|
8
|
-
}
|
|
9
|
-
declare const StyledContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledContentProps>> & string;
|
|
10
|
-
export interface DropDownMenuProps {
|
|
11
|
-
className?: string;
|
|
12
|
-
children?: ReactNode | string;
|
|
13
|
-
label?: string;
|
|
14
|
-
data: DropDownItem[];
|
|
15
|
-
variant?: Variant;
|
|
16
|
-
defaultValue?: DropDownItem[];
|
|
17
|
-
multiselect?: boolean;
|
|
18
|
-
size?: Size;
|
|
19
|
-
title?: string;
|
|
20
|
-
TooltipContent?: ComponentType<any>;
|
|
21
|
-
renderOption?: (item: DropDownItem) => ReactNode;
|
|
22
|
-
onChange?: (selected: DropDownItem[], diff: DropDownItem[]) => void;
|
|
23
|
-
onItemSelect?: (item: DropDownItem) => void;
|
|
24
|
-
onScroll?: (e: UIEvent<HTMLDivElement>) => void;
|
|
25
|
-
loading?: boolean;
|
|
26
|
-
arrow?: boolean;
|
|
27
|
-
searchable?: boolean;
|
|
28
|
-
dropDownProps?: ComponentPropsWithoutRef<typeof StyledContent>;
|
|
29
|
-
buttonRender?: (props: any) => ReactElement;
|
|
30
|
-
buttonProps?: ButtonProps;
|
|
31
|
-
}
|
|
32
|
-
interface MenuProps {
|
|
33
|
-
label?: any;
|
|
34
|
-
nested?: boolean;
|
|
35
|
-
children?: React.ReactNode;
|
|
36
|
-
buttonRender?: (props: any) => ReactElement;
|
|
37
|
-
arrow?: boolean;
|
|
38
|
-
variant?: Variant;
|
|
39
|
-
buttonProps?: ButtonProps;
|
|
40
|
-
size?: Size;
|
|
41
|
-
buttonSize?: Size;
|
|
42
|
-
multiselect?: boolean;
|
|
43
|
-
}
|
|
44
|
-
export declare const Menu: React.ForwardRefExoticComponent<Omit<React.HTMLProps<HTMLButtonElement> & MenuProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
1
|
+
import { DropDownMenuProps } from "./types";
|
|
45
2
|
declare const DropDownMenu: ({ data, children, defaultValue, variant, arrow, size, searchable, loading, onScroll, multiselect, renderOption, onItemSelect, onChange, buttonProps, TooltipContent, }: DropDownMenuProps) => import("react/jsx-runtime").JSX.Element;
|
|
46
3
|
export default DropDownMenu;
|
|
@@ -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 StyledFloatContainer = styled.div `
|
|
20
|
-
z-index: 1500;
|
|
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, justify: "start" }, 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
|
-
});
|
|
4
|
+
import { Menu, MenuItemList, SearchInput, StyledInnerItemContainer, } from "./components";
|
|
276
5
|
const DropDownMenu = ({ data, children, defaultValue, variant, arrow, size, searchable, loading, onScroll, multiselect, renderOption, onItemSelect, onChange, buttonProps, TooltipContent, }) => {
|
|
277
|
-
var _a
|
|
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, 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 { MenuItem } from "./MenuItem";
|
|
18
|
+
import { StyledFloatContainer } from "./StyledFloatContainer";
|
|
19
|
+
import { StyledContent } from "./StyledContent";
|
|
20
|
+
export const MenuComponent = forwardRef((_a, forwardedRef) => {
|
|
21
|
+
var { children, label, arrow, size, buttonSize, variant, buttonProps, buttonRender, multiselect, onMenuClose } = _a, props = __rest(_a, ["children", "label", "arrow", "size", "buttonSize", "variant", "buttonProps", "buttonRender", "multiselect", "onMenuClose"]);
|
|
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: !isNested,
|
|
56
|
+
ignoreMouse: isNested,
|
|
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() {
|
|
79
|
+
if (!multiselect) {
|
|
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 }, 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, { className: "mfFloatingContent", 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,9 @@
|
|
|
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<Omit<MenuProps & ButtonProps & {
|
|
4
|
+
multiselect?: boolean;
|
|
5
|
+
} & import("react").ButtonHTMLAttributes<HTMLButtonElement> & import("react").RefAttributes<unknown>, "ref"> & {
|
|
6
|
+
ref?: ((instance: unknown) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<unknown> | null | undefined;
|
|
7
|
+
}, never>> & string & Omit<import("react").ForwardRefExoticComponent<MenuProps & ButtonProps & {
|
|
8
|
+
multiselect?: boolean;
|
|
9
|
+
} & import("react").ButtonHTMLAttributes<HTMLButtonElement> & import("react").RefAttributes<unknown>>, keyof import("react").Component<any, {}, any>>;
|
|
@@ -0,0 +1,110 @@
|
|
|
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 } = _a, props = __rest(_a, ["label", "children", "disabled", "multiselect", "TooltipContent", "itemData"]);
|
|
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");
|
|
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
|
+
font-size: ${({ size }) => size === "xs"
|
|
66
|
+
? "11px"
|
|
67
|
+
: size === "sm"
|
|
68
|
+
? "13px"
|
|
69
|
+
: size === "md"
|
|
70
|
+
? "15px"
|
|
71
|
+
: size === "lg"
|
|
72
|
+
? "17px"
|
|
73
|
+
: size === "xl"
|
|
74
|
+
? "19px"
|
|
75
|
+
: "11px"};
|
|
76
|
+
|
|
77
|
+
padding: ${({ size }) => size === "xs"
|
|
78
|
+
? "2px 8px"
|
|
79
|
+
: size === "sm"
|
|
80
|
+
? "4px 10px"
|
|
81
|
+
: size === "md"
|
|
82
|
+
? "4px 12px"
|
|
83
|
+
: size === "lg"
|
|
84
|
+
? "5px 14px"
|
|
85
|
+
: size === "xl"
|
|
86
|
+
? "6px 16px"
|
|
87
|
+
: "2px 8px"};
|
|
88
|
+
|
|
89
|
+
&[data-disabled] {
|
|
90
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
91
|
+
pointer-events: "none";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
&:hover {
|
|
95
|
+
background-color: ${(props) => props.theme.palette.action.hover};
|
|
96
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&:active {
|
|
100
|
+
translate: none;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.button-label {
|
|
104
|
+
display: inline-block;
|
|
105
|
+
overflow: hidden;
|
|
106
|
+
white-space: nowrap;
|
|
107
|
+
text-overflow: ellipsis;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
@@ -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
|
+
}>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef } from "react";
|
|
3
|
+
import CheckBox from "../../CheckBox";
|
|
4
|
+
import DropDownMenu from "../DropDownMenu";
|
|
5
|
+
import { MenuItem } from "./MenuItem";
|
|
6
|
+
import styled from "styled-components";
|
|
7
|
+
import { FixedSizeList } from "react-window";
|
|
8
|
+
const filterMenuItems = (menuItems, searchValue) => {
|
|
9
|
+
return menuItems.filter((item) => {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
if (item === null || item === void 0 ? void 0 : item.label) {
|
|
12
|
+
return (((_a = item === null || item === void 0 ? void 0 : item.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(searchValue.toLowerCase())) ||
|
|
13
|
+
((_b = item === null || item === void 0 ? void 0 : item.value) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(searchValue.toLowerCase())));
|
|
14
|
+
}
|
|
15
|
+
return (_c = item.toLowerCase) === null || _c === void 0 ? void 0 : _c.call(item).includes(searchValue.toLowerCase());
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const ListViewPort = styled.div.attrs({ className: "ListViewPort" }) `
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
`;
|
|
22
|
+
export const MenuItemList = ({ menuItems, searchable, searchValue = "", isObjectArray, selected, TooltipContent, multiselect, size, handleAddItem, handleRemoveItem, onItemSelect, renderOption, onScroll, }) => {
|
|
23
|
+
const abortController = new AbortController();
|
|
24
|
+
const targetElm = useRef(null);
|
|
25
|
+
const listElm = useRef(null);
|
|
26
|
+
const handleItemClick = (item, isSelected) => {
|
|
27
|
+
var _a;
|
|
28
|
+
if (multiselect) {
|
|
29
|
+
isSelected ? handleRemoveItem(item) : handleAddItem(item);
|
|
30
|
+
}
|
|
31
|
+
onItemSelect === null || onItemSelect === void 0 ? void 0 : onItemSelect(item);
|
|
32
|
+
(_a = item === null || item === void 0 ? void 0 : item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, item);
|
|
33
|
+
};
|
|
34
|
+
const filteredItems = searchable
|
|
35
|
+
? filterMenuItems(menuItems, searchValue)
|
|
36
|
+
: menuItems;
|
|
37
|
+
useLayoutEffect(() => {
|
|
38
|
+
if (listElm.current) {
|
|
39
|
+
if (onScroll) {
|
|
40
|
+
listElm.current.addEventListener("scroll", (e) => onScroll === null || onScroll === void 0 ? void 0 : onScroll(e));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Event cleanup
|
|
44
|
+
return () => {
|
|
45
|
+
abortController.abort();
|
|
46
|
+
};
|
|
47
|
+
}, [filteredItems, listElm.current, onScroll]);
|
|
48
|
+
const overscanCount = 10;
|
|
49
|
+
const itemHeight = 25;
|
|
50
|
+
const itemCount = (filteredItems === null || filteredItems === void 0 ? void 0 : filteredItems.length) || 0;
|
|
51
|
+
const height = itemCount * 25 < 200 ? itemCount * 25 : 200;
|
|
52
|
+
const width = 188;
|
|
53
|
+
return (_jsx(ListViewPort, { ref: targetElm, children: _jsx(FixedSizeList, { itemData: filteredItems, overscanCount: overscanCount, height: height, width: width, itemCount: itemCount, itemSize: itemHeight, outerRef: listElm, children: ({ data, index, style }) => {
|
|
54
|
+
const item = (data === null || data === void 0 ? void 0 : data[index]) || {};
|
|
55
|
+
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));
|
|
56
|
+
if (item.items) {
|
|
57
|
+
return _jsx(DropDownMenu, { data: item.items, children: item.label });
|
|
58
|
+
}
|
|
59
|
+
return (_jsxs(MenuItem, { className: "MenuItem", itemData: item, TooltipContent: TooltipContent, "data-selected": isSelected, leftSection: multiselect && (_jsx(CheckBox, { value: isSelected, size: size, onChange: (newValue) => {
|
|
60
|
+
var _a;
|
|
61
|
+
newValue ? handleAddItem(item) : handleRemoveItem(item);
|
|
62
|
+
(_a = item === null || item === void 0 ? void 0 : item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, item);
|
|
63
|
+
} })), multiselect: multiselect, size: size, title: !TooltipContent ? item === null || item === void 0 ? void 0 : item.label : undefined, onClick: (e) => {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
handleItemClick(item, isSelected);
|
|
67
|
+
}, style: style, children: [(item === null || item === void 0 ? void 0 : item.leftSection) || null, _jsx(_Fragment, { children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) ||
|
|
68
|
+
(item === null || item === void 0 ? void 0 : item.label) ||
|
|
69
|
+
(typeof item === "string" || typeof item === "number"
|
|
70
|
+
? item
|
|
71
|
+
: null) }), (item === null || item === void 0 ? void 0 : item.rightSection) || null] }, index));
|
|
72
|
+
} }) }));
|
|
73
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SearchInput: import("react").ForwardRefExoticComponent<Omit<Omit<Omit<import("../../Input/Input").InputProps, "ref"> & import("react").RefAttributes<HTMLInputElement>, "ref">, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { StyledContentProps } from "../types";
|
|
2
|
+
export declare const StyledContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledContentProps>> & string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
export const StyledContent = styled.div `
|
|
3
|
+
position: relative;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
overflow-y: hidden;
|
|
8
|
+
overflow-x: hidden;
|
|
9
|
+
|
|
10
|
+
width: 200px;
|
|
11
|
+
min-width: 150px;
|
|
12
|
+
max-width: 400px;
|
|
13
|
+
max-height: ${({ maxDropdownHeight }) => Number.isInteger(maxDropdownHeight)
|
|
14
|
+
? `${maxDropdownHeight}px`
|
|
15
|
+
: maxDropdownHeight || "250px"};
|
|
16
|
+
|
|
17
|
+
background-color: ${(props) => props.theme.palette.background.default};
|
|
18
|
+
background-color: ${({ theme, variant }) => {
|
|
19
|
+
switch (variant) {
|
|
20
|
+
case "filled":
|
|
21
|
+
return theme.palette.input.background;
|
|
22
|
+
case "outlined":
|
|
23
|
+
return theme.palette.input.background;
|
|
24
|
+
case "text":
|
|
25
|
+
return "transparent";
|
|
26
|
+
default:
|
|
27
|
+
return theme.palette.input.background;
|
|
28
|
+
}
|
|
29
|
+
}};
|
|
30
|
+
|
|
31
|
+
border-radius: 5px;
|
|
32
|
+
border: 1px solid ${(props) => props.theme.palette.divider};
|
|
33
|
+
outline: none;
|
|
34
|
+
padding: 5px;
|
|
35
|
+
animation-duration: 400ms;
|
|
36
|
+
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
|
|
37
|
+
will-change: transform, opacity;
|
|
38
|
+
|
|
39
|
+
&[data-empty="true"] {
|
|
40
|
+
display: none;
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const StyledFloatContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const StyledInnerItemContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
2
|
+
ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
3
|
+
}>, never>, never>> & string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./SearchInput";
|
|
2
|
+
export * from "./StyledContent";
|
|
3
|
+
export * from "./StyledFloatContainer";
|
|
4
|
+
export * from "./StyledInnerItemContainer";
|
|
5
|
+
export * from "./MenuItem";
|
|
6
|
+
export * from "./MenuContext";
|
|
7
|
+
export * from "./MenuComponent";
|
|
8
|
+
export * from "./Menu";
|
|
9
|
+
export * from "./MenuItemList";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./SearchInput";
|
|
2
|
+
export * from "./StyledContent";
|
|
3
|
+
export * from "./StyledFloatContainer";
|
|
4
|
+
export * from "./StyledInnerItemContainer";
|
|
5
|
+
export * from "./MenuItem";
|
|
6
|
+
export * from "./MenuContext";
|
|
7
|
+
export * from "./MenuComponent";
|
|
8
|
+
export * from "./Menu";
|
|
9
|
+
export * from "./MenuItemList";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from "./DropDownMenu";
|
|
2
|
-
export
|
|
2
|
+
export * from "./types";
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ComponentType, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { Size, Variant } from "../core";
|
|
3
|
+
import Input from "../Input";
|
|
4
|
+
import { ButtonProps } from "../Button";
|
|
5
|
+
import { StyledContent } from "./components";
|
|
1
6
|
export type DropDownItem = {
|
|
2
7
|
toLowerCase?: () => string;
|
|
3
8
|
label: string;
|
|
@@ -8,3 +13,45 @@ export type DropDownItem = {
|
|
|
8
13
|
leftSection?: React.ReactNode;
|
|
9
14
|
rightSection?: React.ReactNode;
|
|
10
15
|
};
|
|
16
|
+
export type SearchInputProps = React.ComponentPropsWithoutRef<typeof Input>;
|
|
17
|
+
export interface StyledContentProps {
|
|
18
|
+
maxDropdownHeight?: number | string;
|
|
19
|
+
variant?: Variant;
|
|
20
|
+
}
|
|
21
|
+
export interface DropDownMenuProps {
|
|
22
|
+
className?: string;
|
|
23
|
+
children?: ReactNode | string;
|
|
24
|
+
label?: string;
|
|
25
|
+
data: DropDownItem[];
|
|
26
|
+
variant?: Variant;
|
|
27
|
+
defaultValue?: DropDownItem[];
|
|
28
|
+
multiselect?: boolean;
|
|
29
|
+
size?: Size;
|
|
30
|
+
title?: string;
|
|
31
|
+
TooltipContent?: ComponentType<any>;
|
|
32
|
+
renderOption?: (item: DropDownItem) => ReactNode;
|
|
33
|
+
onChange?: (selected: DropDownItem[], diff: DropDownItem[]) => void;
|
|
34
|
+
onItemSelect?: (item: DropDownItem) => void;
|
|
35
|
+
onScroll?: (e: Event) => void;
|
|
36
|
+
loading?: boolean;
|
|
37
|
+
arrow?: boolean;
|
|
38
|
+
searchable?: boolean;
|
|
39
|
+
dropDownProps?: ComponentPropsWithoutRef<typeof StyledContent>;
|
|
40
|
+
buttonRender?: (props: any) => ReactElement;
|
|
41
|
+
buttonProps?: ButtonProps;
|
|
42
|
+
}
|
|
43
|
+
export interface MenuProps {
|
|
44
|
+
label?: any;
|
|
45
|
+
itemData?: any;
|
|
46
|
+
nested?: boolean;
|
|
47
|
+
children?: React.ReactNode;
|
|
48
|
+
buttonRender?: (props: any) => ReactElement;
|
|
49
|
+
arrow?: boolean;
|
|
50
|
+
variant?: Variant;
|
|
51
|
+
buttonProps?: ButtonProps;
|
|
52
|
+
size?: Size;
|
|
53
|
+
buttonSize?: Size;
|
|
54
|
+
multiselect?: boolean;
|
|
55
|
+
onMenuClose?: () => void;
|
|
56
|
+
TooltipContent?: ComponentType<any>;
|
|
57
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import Extensions from "../Enums/Extensions";
|
|
2
|
-
import { DropDownItem } from "../../DropDownMenu";
|
|
2
|
+
import { DropDownItem, DropDownMenuProps } from "../../DropDownMenu";
|
|
3
3
|
import { ReactElement } from "react";
|
|
4
4
|
import { ButtonProps } from "../../Button";
|
|
5
5
|
import { Editor } from "@tiptap/react";
|
|
6
|
-
import { DropDownMenuProps } from "../../DropDownMenu/DropDownMenu";
|
|
7
6
|
export interface BubbleMenuProps {
|
|
8
7
|
className?: string;
|
|
9
8
|
editor: Editor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Editor } from "@tiptap/react";
|
|
2
2
|
import Controls from "../Enums/Controls";
|
|
3
|
+
import { DropDownMenuProps } from "../../DropDownMenu";
|
|
3
4
|
import { ReactNode } from "react";
|
|
4
|
-
import { DropDownMenuProps } from "../../DropDownMenu/DropDownMenu";
|
|
5
5
|
import { ButtonProps } from "../../Button";
|
|
6
6
|
export type CustomItem = {
|
|
7
7
|
type: "button";
|
|
@@ -8,6 +8,12 @@ import CheckBox from "../CheckBox";
|
|
|
8
8
|
import { ArrowDownIcon, ArrowUpIcon } from "lucide-react";
|
|
9
9
|
import resolveColumnReorder from "./Utils/resolveColumnReorder";
|
|
10
10
|
import TableDefaults from "./TableDefaults";
|
|
11
|
+
import styled from "styled-components";
|
|
12
|
+
const StyledCaption = styled.span `
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
text-overflow: ellipsis;
|
|
16
|
+
`;
|
|
11
17
|
const TableHeader = ({ headerRowElm }) => {
|
|
12
18
|
var _a;
|
|
13
19
|
const { columnState, sortState, setColumnState, onColumnResize, handleColumnReorder, enableColumnReorder, handleColumnHeaderClick, enableColumnResize, headerRowHeight, enableActionButton, enableSelection, selectionState, disableSelectAll, selectAllRows, clearSelections, compactState, } = useTable();
|
|
@@ -86,8 +92,8 @@ const TableHeader = ({ headerRowElm }) => {
|
|
|
86
92
|
// console.log("onResize", e);
|
|
87
93
|
}, onResizeFinished: (e) => {
|
|
88
94
|
handleResize(e);
|
|
89
|
-
} })), _jsxs(InnerCellContent, { className: "mfui inner-cell-content", children: [column.caption, (sortState === null || sortState === void 0 ? void 0 : sortState.dataField) === column.dataField &&
|
|
90
|
-
|
|
95
|
+
} })), _jsxs(InnerCellContent, { className: "mfui inner-cell-content", children: [_jsx(StyledCaption, { style: { flex: 1 }, children: column.caption }), _jsx(StyledCaption, { children: (sortState === null || sortState === void 0 ? void 0 : sortState.dataField) === column.dataField &&
|
|
96
|
+
(sortState.dir === "asc" ? (_jsx(ArrowUpIcon, { size: 14 })) : (_jsx(ArrowDownIcon, { size: 14 }))) })] })] }), column.columnId));
|
|
91
97
|
})] }) }));
|
|
92
98
|
};
|
|
93
99
|
export default TableHeader;
|