@monolith-forensics/monolith-ui 1.0.10 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Button/Button.tsx +382 -0
- package/Button/index.ts +2 -0
- package/{src/components/Calendar/Calendar.js → Calendar/Calendar.tsx} +104 -93
- package/{src/components/Calendar/CalendarStyles.js → Calendar/CalendarStyles.tsx} +26 -36
- package/{src/components/Calendar/calendarHelpers.js → Calendar/calendarHelpers.ts} +10 -8
- package/Calendar/index.ts +1 -0
- package/CheckBox/CheckBox.tsx +61 -0
- package/CheckBox/index.ts +1 -0
- package/{src/components/DateInput/DateInput.js → DateInput/DateInput.tsx} +227 -93
- package/DateInput/index.ts +1 -0
- package/DropDownMenu/DropDownMenu.tsx +402 -0
- package/DropDownMenu/index.ts +1 -0
- package/Error/Error.tsx +51 -0
- package/Error/index.ts +1 -0
- package/{src/components/FieldLabel → FieldLabel}/FieldLabel.tsx +25 -22
- package/{src/components/FileInputField/FileInputField.js → FileInputField/FileInputField.tsx} +23 -15
- package/FileInputField/index.ts +1 -0
- package/Flyout/Flyout.tsx +172 -0
- package/Flyout/FlyoutHeader.tsx +14 -0
- package/Flyout/FlyoutTitle.tsx +10 -0
- package/Flyout/index.ts +3 -0
- package/FormSection/FormSection.tsx +71 -0
- package/FormSection/index.ts +1 -0
- package/Grid/Grid.tsx +18 -0
- package/Grid/index.ts +1 -0
- package/IconButton/IconButton.tsx +27 -0
- package/IconButton/index.ts +1 -0
- package/{src/components/Input → Input}/Input.tsx +57 -34
- package/Modal/Modal.tsx +172 -0
- package/Modal/index.ts +1 -0
- package/{src/components/Pill → Pill}/Pill.tsx +41 -11
- package/SelectBox/SelectBox.tsx +745 -0
- package/SelectBox/index.ts +1 -0
- package/Switch/Switch.tsx +204 -0
- package/Switch/index.ts +1 -0
- package/TagBox/TagBox.tsx +694 -0
- package/TagBox/TagBoxStyles.tsx +116 -0
- package/TagBox/index.ts +1 -0
- package/{src/components/TextArea → TextArea}/TextArea.tsx +35 -13
- package/{src/components/TextAreaInput → TextAreaInput}/TextAreaInput.tsx +11 -13
- package/{src/components/TextInput → TextInput}/TextInput.tsx +11 -13
- package/Tooltip/Tooltip.tsx +68 -0
- package/Tooltip/index.ts +1 -0
- package/{src/components/ArrowButton → core}/ArrowButton.tsx +17 -20
- package/core/ClearButton.tsx +51 -0
- package/core/StyledContent.tsx +50 -0
- package/core/StyledFloatContainer.tsx +7 -0
- package/core/Types/Size.ts +3 -0
- package/core/Types/Variant.ts +10 -0
- package/core/index.ts +6 -0
- package/dist/Button/Button.d.ts +19 -0
- package/dist/Button/Button.js +332 -0
- package/dist/Button/index.d.ts +2 -0
- package/dist/Button/index.js +8 -0
- package/dist/Calendar/Calendar.d.ts +15 -0
- package/dist/Calendar/Calendar.js +232 -0
- package/dist/Calendar/CalendarStyles.d.ts +36 -0
- package/dist/Calendar/CalendarStyles.js +170 -0
- package/dist/Calendar/calendarHelpers.d.ts +53 -0
- package/dist/Calendar/calendarHelpers.js +181 -0
- package/dist/Calendar/index.d.ts +1 -0
- package/dist/Calendar/index.js +8 -0
- package/dist/CheckBox/CheckBox.d.ts +11 -0
- package/dist/CheckBox/CheckBox.js +34 -0
- package/dist/CheckBox/index.d.ts +1 -0
- package/dist/CheckBox/index.js +8 -0
- package/dist/DateInput/DateInput.d.ts +24 -0
- package/dist/DateInput/DateInput.js +511 -0
- package/dist/DateInput/index.d.ts +1 -0
- package/dist/DateInput/index.js +8 -0
- package/dist/DropDownMenu/DropDownMenu.d.ts +36 -0
- package/dist/DropDownMenu/DropDownMenu.js +212 -0
- package/dist/DropDownMenu/index.d.ts +1 -0
- package/dist/DropDownMenu/index.js +8 -0
- package/dist/Error/Error.d.ts +4 -0
- package/dist/Error/Error.js +38 -0
- package/dist/Error/index.d.ts +1 -0
- package/dist/Error/index.js +8 -0
- package/dist/FieldLabel/FieldLabel.d.ts +19 -0
- package/dist/FieldLabel/FieldLabel.js +119 -0
- package/dist/FieldLabel/index.d.ts +1 -0
- package/dist/FieldLabel/index.js +8 -0
- package/dist/FileInputField/FileInputField.d.ts +18 -0
- package/dist/FileInputField/FileInputField.js +116 -0
- package/dist/FileInputField/index.d.ts +1 -0
- package/dist/FileInputField/index.js +8 -0
- package/dist/Flyout/Flyout.d.ts +10 -0
- package/dist/Flyout/Flyout.js +111 -0
- package/dist/Flyout/FlyoutHeader.d.ts +5 -0
- package/dist/Flyout/FlyoutHeader.js +12 -0
- package/dist/Flyout/FlyoutTitle.d.ts +2 -0
- package/dist/Flyout/FlyoutTitle.js +13 -0
- package/dist/Flyout/index.d.ts +3 -0
- package/dist/Flyout/index.js +12 -0
- package/dist/FormSection/FormSection.d.ts +9 -0
- package/dist/FormSection/FormSection.js +51 -0
- package/dist/FormSection/index.d.ts +1 -0
- package/dist/FormSection/index.js +8 -0
- package/dist/Grid/Grid.d.ts +6 -0
- package/dist/Grid/Grid.js +15 -0
- package/dist/Grid/index.d.ts +1 -0
- package/dist/Grid/index.js +8 -0
- package/dist/IconButton/IconButton.d.ts +5 -0
- package/dist/IconButton/IconButton.js +30 -0
- package/dist/IconButton/index.d.ts +1 -0
- package/dist/IconButton/index.js +8 -0
- package/dist/Input/Input.d.ts +21 -0
- package/dist/Input/Input.js +148 -0
- package/dist/Input/index.d.ts +1 -0
- package/dist/Input/index.js +8 -0
- package/dist/Modal/Modal.d.ts +14 -0
- package/dist/Modal/Modal.js +134 -0
- package/dist/Modal/index.d.ts +1 -0
- package/dist/Modal/index.js +8 -0
- package/dist/Pill/Pill.d.ts +11 -0
- package/dist/Pill/Pill.js +146 -0
- package/dist/Pill/index.d.ts +1 -0
- package/dist/Pill/index.js +8 -0
- package/dist/SelectBox/SelectBox.d.ts +45 -0
- package/dist/SelectBox/SelectBox.js +469 -0
- package/dist/SelectBox/index.d.ts +1 -0
- package/dist/SelectBox/index.js +8 -0
- package/dist/Switch/Switch.d.ts +18 -0
- package/dist/Switch/Switch.js +157 -0
- package/dist/Switch/index.d.ts +1 -0
- package/dist/Switch/index.js +8 -0
- package/dist/TagBox/TagBox.d.ts +38 -0
- package/dist/TagBox/TagBox.js +440 -0
- package/dist/TagBox/TagBoxStyles.d.ts +11 -0
- package/dist/TagBox/TagBoxStyles.js +113 -0
- package/dist/TagBox/index.d.ts +1 -0
- package/dist/TagBox/index.js +8 -0
- package/dist/TextArea/TextArea.d.ts +16 -0
- package/dist/TextArea/TextArea.js +80 -0
- package/dist/TextArea/index.d.ts +1 -0
- package/dist/TextArea/index.js +8 -0
- package/dist/TextAreaInput/TextAreaInput.d.ts +12 -0
- package/dist/TextAreaInput/TextAreaInput.js +23 -0
- package/dist/TextAreaInput/index.d.ts +1 -0
- package/dist/TextAreaInput/index.js +8 -0
- package/dist/TextInput/TextInput.d.ts +12 -0
- package/dist/TextInput/TextInput.js +30 -0
- package/dist/TextInput/index.d.ts +1 -0
- package/dist/TextInput/index.js +8 -0
- package/dist/Tooltip/Tooltip.d.ts +12 -0
- package/dist/Tooltip/Tooltip.js +53 -0
- package/dist/Tooltip/index.d.ts +1 -0
- package/dist/Tooltip/index.js +8 -0
- package/dist/core/ArrowButton.d.ts +6 -0
- package/dist/core/ArrowButton.js +48 -0
- package/dist/core/ClearButton.d.ts +6 -0
- package/dist/core/ClearButton.js +48 -0
- package/dist/core/StyledContent.d.ts +7 -0
- package/dist/core/StyledContent.js +46 -0
- package/dist/core/StyledFloatContainer.d.ts +2 -0
- package/dist/core/StyledFloatContainer.js +10 -0
- package/dist/core/Types/Size.d.ts +2 -0
- package/dist/core/Types/Size.js +2 -0
- package/dist/core/Types/Variant.d.ts +2 -0
- package/dist/core/Types/Variant.js +2 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +14 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +51 -0
- package/index.ts +22 -0
- package/package.json +12 -21
- package/{src/components/theme → theme}/components.js +0 -2
- package/{src/components/theme → theme}/index.js +0 -1
- package/{src/components/theme → theme}/variants.js +0 -1
- package/tsconfig.json +11 -11
- package/.gitattributes +0 -2
- package/rollup.config.js +0 -10
- package/src/components/ArrowButton/index.tsx +0 -1
- package/src/components/Button/Button.tsx +0 -278
- package/src/components/Button/index.ts +0 -1
- package/src/components/SelectBox/SelectBox.js +0 -543
- package/src/components/TagBox/TagBox.js +0 -563
- package/src/components/index.ts +0 -7
- package/src/index.ts +0 -1
- /package/{src/components/FieldLabel → FieldLabel}/index.ts +0 -0
- /package/{src/components/Input/index.tsx → Input/index.ts} +0 -0
- /package/{src/components/Pill → Pill}/index.ts +0 -0
- /package/{src/components/TextArea → TextArea}/index.ts +0 -0
- /package/{src/components/TextAreaInput → TextAreaInput}/index.ts +0 -0
- /package/{src/components/TextInput/index.tsx → TextInput/index.ts} +0 -0
- /package/{src/components/core/index.js → core/MonolithThemeProvider.js} +0 -0
- /package/{src/components/theme → theme}/breakpoints.js +0 -0
- /package/{src/components/theme → theme}/shadows.js +0 -0
- /package/{src/components/theme → theme}/typography.js +0 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FloatingFocusManager,
|
|
3
|
+
FloatingPortal,
|
|
4
|
+
flip,
|
|
5
|
+
useFloating,
|
|
6
|
+
} from "@floating-ui/react";
|
|
7
|
+
import {
|
|
8
|
+
ComponentPropsWithoutRef,
|
|
9
|
+
ComponentType,
|
|
10
|
+
ReactNode,
|
|
11
|
+
UIEvent,
|
|
12
|
+
forwardRef,
|
|
13
|
+
useEffect,
|
|
14
|
+
useRef,
|
|
15
|
+
useState,
|
|
16
|
+
} from "react";
|
|
17
|
+
import styled from "styled-components";
|
|
18
|
+
import { Button, Tooltip, CheckBox, Input } from "..";
|
|
19
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
20
|
+
import { ButtonProps } from "../Button";
|
|
21
|
+
import { Size, Variant } from "../core";
|
|
22
|
+
|
|
23
|
+
const StyledFloatContainer = styled.div`
|
|
24
|
+
z-index: 1500;
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const StyledInnerItemContainer = styled.div`
|
|
28
|
+
overflow-y: auto;
|
|
29
|
+
|
|
30
|
+
&[data-scroll-active="true"] {
|
|
31
|
+
padding-right: 5px;
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
type SearchInputProps = React.ComponentPropsWithoutRef<typeof Input>;
|
|
36
|
+
|
|
37
|
+
const SearchInput = forwardRef<HTMLInputElement, SearchInputProps>(
|
|
38
|
+
(props, ref) => <Input ref={ref} style={{ marginBottom: 8 }} {...props} />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
interface StyledItemProps {
|
|
42
|
+
className?: string;
|
|
43
|
+
children?: React.ReactNode | string;
|
|
44
|
+
size?: Size;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
|
|
47
|
+
"data-selected"?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const StyledItem = styled.div<StyledItemProps>`
|
|
51
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
52
|
+
border-radius: 3px;
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-direction: row;
|
|
55
|
+
gap: 5px;
|
|
56
|
+
align-items: center;
|
|
57
|
+
min-height: 25px;
|
|
58
|
+
padding: 7px 10px;
|
|
59
|
+
position: relative;
|
|
60
|
+
user-select: none;
|
|
61
|
+
outline: none;
|
|
62
|
+
|
|
63
|
+
white-space: nowrap;
|
|
64
|
+
overflow: hidden;
|
|
65
|
+
text-overflow: ellipsis;
|
|
66
|
+
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
|
|
69
|
+
font-family: ${({ theme }) => theme.typography.fontFamily};
|
|
70
|
+
|
|
71
|
+
font-size: ${({ size }) =>
|
|
72
|
+
size === "xs"
|
|
73
|
+
? "11px"
|
|
74
|
+
: size === "sm"
|
|
75
|
+
? "13px"
|
|
76
|
+
: size === "md"
|
|
77
|
+
? "15px"
|
|
78
|
+
: size === "lg"
|
|
79
|
+
? "17px"
|
|
80
|
+
: size === "xl"
|
|
81
|
+
? "19px"
|
|
82
|
+
: "11px"};
|
|
83
|
+
|
|
84
|
+
padding: ${({ size }) =>
|
|
85
|
+
size === "xs"
|
|
86
|
+
? "2px 8px"
|
|
87
|
+
: size === "sm"
|
|
88
|
+
? "4px 10px"
|
|
89
|
+
: size === "md"
|
|
90
|
+
? "4px 12px"
|
|
91
|
+
: size === "lg"
|
|
92
|
+
? "5px 14px"
|
|
93
|
+
: size === "xl"
|
|
94
|
+
? "6px 16px"
|
|
95
|
+
: "2px 8px"};
|
|
96
|
+
|
|
97
|
+
&[data-disabled] {
|
|
98
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
99
|
+
pointer-events: "none";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&:hover {
|
|
103
|
+
background-color: ${(props) => props.theme.palette.action.hover};
|
|
104
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
interface StyledContentProps {
|
|
109
|
+
maxDropdownHeight?: number | string;
|
|
110
|
+
variant?: Variant;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const StyledContent = styled.div<StyledContentProps>`
|
|
114
|
+
position: relative;
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
overflow-y: hidden;
|
|
118
|
+
overflow-x: hidden;
|
|
119
|
+
|
|
120
|
+
max-height: ${({ maxDropdownHeight }) =>
|
|
121
|
+
Number.isInteger(maxDropdownHeight)
|
|
122
|
+
? `${maxDropdownHeight}px`
|
|
123
|
+
: maxDropdownHeight || "250px"};
|
|
124
|
+
|
|
125
|
+
background-color: ${(props) => props.theme.palette.background.default};
|
|
126
|
+
background-color: ${({ theme, variant }) => {
|
|
127
|
+
switch (variant) {
|
|
128
|
+
case "filled":
|
|
129
|
+
return theme.palette.input.background;
|
|
130
|
+
case "outlined":
|
|
131
|
+
return theme.palette.input.background;
|
|
132
|
+
case "text":
|
|
133
|
+
return "transparent";
|
|
134
|
+
default:
|
|
135
|
+
return theme.palette.input.background;
|
|
136
|
+
}
|
|
137
|
+
}};
|
|
138
|
+
|
|
139
|
+
border-radius: 5px;
|
|
140
|
+
border: 1px solid ${(props) => props.theme.palette.divider};
|
|
141
|
+
padding: 5px;
|
|
142
|
+
animation-duration: 400ms;
|
|
143
|
+
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
|
|
144
|
+
will-change: transform, opacity;
|
|
145
|
+
|
|
146
|
+
&[data-empty="true"] {
|
|
147
|
+
display: none;
|
|
148
|
+
}
|
|
149
|
+
`;
|
|
150
|
+
|
|
151
|
+
interface DropDownItem {
|
|
152
|
+
toLowerCase?: () => string;
|
|
153
|
+
label: string;
|
|
154
|
+
value: string;
|
|
155
|
+
data?: any; // Additional data to be passed to the TooltipContent component, could be anything
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface DropDownMenuProps {
|
|
159
|
+
className?: string;
|
|
160
|
+
children?: ReactNode;
|
|
161
|
+
data?: DropDownItem[];
|
|
162
|
+
variant?: Variant;
|
|
163
|
+
defaultValue?: DropDownItem[];
|
|
164
|
+
multiselect?: boolean;
|
|
165
|
+
size?: Size;
|
|
166
|
+
title?: string;
|
|
167
|
+
TooltipContent?: ComponentType<any>;
|
|
168
|
+
renderOption?: (item: DropDownItem) => ReactNode;
|
|
169
|
+
onChange?: (selected: DropDownItem[], diff: DropDownItem[]) => void;
|
|
170
|
+
onItemSelect?: (item: DropDownItem) => void;
|
|
171
|
+
onScroll?: (e: UIEvent<HTMLDivElement>) => void;
|
|
172
|
+
loading?: boolean;
|
|
173
|
+
arrow?: boolean;
|
|
174
|
+
searchable?: boolean;
|
|
175
|
+
dropDownProps?: ComponentPropsWithoutRef<typeof StyledContent>;
|
|
176
|
+
buttonProps?: ButtonProps;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const DropDownMenu = styled(
|
|
180
|
+
({
|
|
181
|
+
className,
|
|
182
|
+
children,
|
|
183
|
+
data = [],
|
|
184
|
+
variant = "outlined",
|
|
185
|
+
defaultValue,
|
|
186
|
+
multiselect = false,
|
|
187
|
+
size = "xs",
|
|
188
|
+
TooltipContent,
|
|
189
|
+
renderOption,
|
|
190
|
+
onChange,
|
|
191
|
+
onItemSelect,
|
|
192
|
+
onScroll,
|
|
193
|
+
loading,
|
|
194
|
+
arrow,
|
|
195
|
+
searchable,
|
|
196
|
+
dropDownProps,
|
|
197
|
+
buttonProps,
|
|
198
|
+
}: DropDownMenuProps) => {
|
|
199
|
+
const isObjectArray = Object.keys(data?.[0] || {})?.includes("label");
|
|
200
|
+
|
|
201
|
+
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
202
|
+
const [selected, setSelected] = useState<DropDownItem[]>(
|
|
203
|
+
defaultValue || []
|
|
204
|
+
);
|
|
205
|
+
const [searchValue, setSearchValue] = useState<string>("");
|
|
206
|
+
|
|
207
|
+
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
|
208
|
+
const searchInputRef = useRef<HTMLInputElement>(null);
|
|
209
|
+
|
|
210
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
211
|
+
open: isOpen,
|
|
212
|
+
onOpenChange: setIsOpen,
|
|
213
|
+
placement: "bottom-start",
|
|
214
|
+
strategy: "absolute",
|
|
215
|
+
// Handle collisions with the viewport
|
|
216
|
+
middleware: [flip()],
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const handleAddItem = (item: DropDownItem) => {
|
|
220
|
+
setSelected((prev: DropDownItem[]) => {
|
|
221
|
+
let newSelected = [...prev, item];
|
|
222
|
+
|
|
223
|
+
const diff = data.filter(
|
|
224
|
+
(i) =>
|
|
225
|
+
!newSelected.find((s) =>
|
|
226
|
+
isObjectArray ? s?.value === i?.value : s === i
|
|
227
|
+
)
|
|
228
|
+
);
|
|
229
|
+
onChange?.(newSelected, diff);
|
|
230
|
+
return newSelected;
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const handleRemoveItem = (item: DropDownItem) => {
|
|
235
|
+
setSelected((prev) => {
|
|
236
|
+
let newSelected = prev.filter((i) =>
|
|
237
|
+
isObjectArray ? i?.value !== item?.value : i !== item
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const diff = data.filter(
|
|
241
|
+
(i) =>
|
|
242
|
+
!newSelected.find((s) =>
|
|
243
|
+
isObjectArray ? s?.value === i?.value : s === i
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
onChange?.(newSelected, diff);
|
|
247
|
+
return newSelected;
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const handleSearch = useDebouncedCallback(
|
|
252
|
+
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
253
|
+
setSearchValue(e.target.value);
|
|
254
|
+
},
|
|
255
|
+
150
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
// Close on outside click
|
|
259
|
+
useEffect(() => {
|
|
260
|
+
const close = (e: Event) => {
|
|
261
|
+
const target = e.target as Node;
|
|
262
|
+
const referenceElement = refs?.reference?.current as Node;
|
|
263
|
+
const floatingElement = refs?.floating?.current as Node;
|
|
264
|
+
|
|
265
|
+
if (
|
|
266
|
+
floatingElement && // Check if the floating element exists
|
|
267
|
+
e.target !== referenceElement && // Check if the target is not the reference (input)
|
|
268
|
+
!referenceElement?.contains?.(target) && // Check if the target is not inside the reference (input)
|
|
269
|
+
!floatingElement?.contains?.(target) // Check if the target is not inside the floating element (content)
|
|
270
|
+
) {
|
|
271
|
+
setIsOpen(false);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
document.addEventListener("mousedown", close);
|
|
275
|
+
return () => document.removeEventListener("mousdown", close);
|
|
276
|
+
}, [refs.floating, refs.reference]);
|
|
277
|
+
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
if (isOpen && searchable) {
|
|
280
|
+
searchInputRef?.current?.focus?.();
|
|
281
|
+
}
|
|
282
|
+
if (!isOpen) {
|
|
283
|
+
setSearchValue("");
|
|
284
|
+
}
|
|
285
|
+
}, [isOpen, searchable]);
|
|
286
|
+
|
|
287
|
+
const scrollActive =
|
|
288
|
+
(scrollContainerRef?.current?.scrollHeight || 0) >
|
|
289
|
+
(scrollContainerRef?.current?.clientHeight || 0);
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<div className={className + " mfDropDownMenu"}>
|
|
293
|
+
<Button
|
|
294
|
+
ref={(ref) => {
|
|
295
|
+
refs.setReference(ref);
|
|
296
|
+
}}
|
|
297
|
+
onMouseDown={() => setIsOpen(!isOpen)}
|
|
298
|
+
rightSection={arrow ? <span>▼</span> : null}
|
|
299
|
+
size={size}
|
|
300
|
+
{...buttonProps}
|
|
301
|
+
>
|
|
302
|
+
{children}
|
|
303
|
+
</Button>
|
|
304
|
+
{isOpen && (
|
|
305
|
+
<FloatingPortal preserveTabOrder>
|
|
306
|
+
<FloatingFocusManager context={context} modal={false}>
|
|
307
|
+
<StyledFloatContainer
|
|
308
|
+
ref={refs.setFloating}
|
|
309
|
+
style={floatingStyles}
|
|
310
|
+
className="mfFloating"
|
|
311
|
+
>
|
|
312
|
+
<StyledContent
|
|
313
|
+
className="mfFloatingContent"
|
|
314
|
+
style={{ width: 150, maxWidth: 400 }}
|
|
315
|
+
variant={variant}
|
|
316
|
+
{...dropDownProps}
|
|
317
|
+
>
|
|
318
|
+
<StyledInnerItemContainer
|
|
319
|
+
ref={scrollContainerRef}
|
|
320
|
+
data-scroll-active={scrollActive}
|
|
321
|
+
onScroll={onScroll}
|
|
322
|
+
>
|
|
323
|
+
{loading && <div>Loading...</div>}
|
|
324
|
+
{searchable && (
|
|
325
|
+
<SearchInput
|
|
326
|
+
ref={searchInputRef}
|
|
327
|
+
variant="outlined"
|
|
328
|
+
placeholder="Search"
|
|
329
|
+
onChange={handleSearch}
|
|
330
|
+
/>
|
|
331
|
+
)}
|
|
332
|
+
{!loading &&
|
|
333
|
+
data
|
|
334
|
+
.filter((item) => {
|
|
335
|
+
if (!searchable) return true;
|
|
336
|
+
if (isObjectArray) {
|
|
337
|
+
return (
|
|
338
|
+
item?.label
|
|
339
|
+
?.toLowerCase()
|
|
340
|
+
.includes(searchValue.toLowerCase()) ||
|
|
341
|
+
item?.value
|
|
342
|
+
?.toLowerCase()
|
|
343
|
+
.includes(searchValue.toLowerCase())
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
return item
|
|
347
|
+
.toLowerCase?.()
|
|
348
|
+
.includes(searchValue.toLowerCase());
|
|
349
|
+
})
|
|
350
|
+
.map((item, index) => {
|
|
351
|
+
const isSelected = !!selected?.find((s) =>
|
|
352
|
+
isObjectArray
|
|
353
|
+
? s?.value === item?.value
|
|
354
|
+
: s === item
|
|
355
|
+
);
|
|
356
|
+
return (
|
|
357
|
+
<Tooltip
|
|
358
|
+
key={index}
|
|
359
|
+
content={
|
|
360
|
+
TooltipContent ? (
|
|
361
|
+
<TooltipContent data={item.data} />
|
|
362
|
+
) : null
|
|
363
|
+
}
|
|
364
|
+
side="left"
|
|
365
|
+
>
|
|
366
|
+
<StyledItem
|
|
367
|
+
className="mfFloatingItem"
|
|
368
|
+
onClick={(e) => {
|
|
369
|
+
e.preventDefault();
|
|
370
|
+
e.stopPropagation();
|
|
371
|
+
if (multiselect) {
|
|
372
|
+
isSelected
|
|
373
|
+
? handleRemoveItem(item)
|
|
374
|
+
: handleAddItem(item);
|
|
375
|
+
} else {
|
|
376
|
+
setIsOpen(false);
|
|
377
|
+
}
|
|
378
|
+
onItemSelect?.(item);
|
|
379
|
+
}}
|
|
380
|
+
data-selected={isSelected}
|
|
381
|
+
size={size}
|
|
382
|
+
>
|
|
383
|
+
{multiselect && <CheckBox value={isSelected} />}
|
|
384
|
+
<>
|
|
385
|
+
{renderOption?.(item) || item?.label || item}
|
|
386
|
+
</>
|
|
387
|
+
</StyledItem>
|
|
388
|
+
</Tooltip>
|
|
389
|
+
);
|
|
390
|
+
})}
|
|
391
|
+
</StyledInnerItemContainer>
|
|
392
|
+
</StyledContent>
|
|
393
|
+
</StyledFloatContainer>
|
|
394
|
+
</FloatingFocusManager>
|
|
395
|
+
</FloatingPortal>
|
|
396
|
+
)}
|
|
397
|
+
</div>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
)``;
|
|
401
|
+
|
|
402
|
+
export default DropDownMenu;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./DropDownMenu";
|
package/Error/Error.tsx
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
import { XIcon, ShieldAlert } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
const ErrorContainer = styled.div`
|
|
6
|
+
background-color: ${({ theme }) => theme.palette.error.main + "15"};
|
|
7
|
+
color: ${({ theme }) => theme.palette.error.light};
|
|
8
|
+
border: 1px solid #d93025;
|
|
9
|
+
padding: 10px;
|
|
10
|
+
margin-bottom: 10px;
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: space-between;
|
|
13
|
+
border-radius: 5px;
|
|
14
|
+
align-items: center;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const CloseButton = styled.button`
|
|
18
|
+
background: none;
|
|
19
|
+
border: none;
|
|
20
|
+
color: ${({ theme }) => theme.palette.error.light};
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
const ErrorText = styled.span`
|
|
25
|
+
margin-left: 10px;
|
|
26
|
+
flex: 1;
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
const ErrorComponent = ({ error }: { error: string }) => {
|
|
30
|
+
const [isVisible, setIsVisible] = useState(true);
|
|
31
|
+
|
|
32
|
+
const handleClose = () => {
|
|
33
|
+
setIsVisible(false);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
{isVisible && (
|
|
39
|
+
<ErrorContainer>
|
|
40
|
+
<ShieldAlert size={19} />
|
|
41
|
+
<ErrorText>{error}</ErrorText>
|
|
42
|
+
<CloseButton onClick={handleClose}>
|
|
43
|
+
<XIcon size={19} />
|
|
44
|
+
</CloseButton>
|
|
45
|
+
</ErrorContainer>
|
|
46
|
+
)}
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default ErrorComponent;
|
package/Error/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Error";
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import styled from "styled-components";
|
|
3
2
|
import * as Tooltip from "@radix-ui/react-tooltip";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { Size } from "../core";
|
|
4
5
|
|
|
5
6
|
interface InfoComponentProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
className?: string;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
description?: string;
|
|
10
|
+
label?: string | ReactNode;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
const InfoComponent
|
|
12
|
-
({ className, children, description, label }) => {
|
|
13
|
+
export const InfoComponent = styled(
|
|
14
|
+
({ className, children, description, label }: InfoComponentProps) => {
|
|
13
15
|
if (!description) return children;
|
|
14
16
|
|
|
15
17
|
return (
|
|
@@ -38,7 +40,7 @@ const InfoComponent: React.FC<InfoComponentProps> = styled(
|
|
|
38
40
|
}
|
|
39
41
|
)`
|
|
40
42
|
pointer-events: none;
|
|
41
|
-
z-index:
|
|
43
|
+
z-index: 999999;
|
|
42
44
|
background-color: ${({ theme }) => theme.palette.background.default};
|
|
43
45
|
padding: 15px;
|
|
44
46
|
border-radius: 5px;
|
|
@@ -57,46 +59,46 @@ const InfoComponent: React.FC<InfoComponentProps> = styled(
|
|
|
57
59
|
`;
|
|
58
60
|
|
|
59
61
|
interface FieldLabelProps {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
className?: string;
|
|
63
|
+
children?: ReactNode;
|
|
64
|
+
error?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
size?: Size;
|
|
64
67
|
asterisk?: boolean;
|
|
65
|
-
children: string | Element;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
const FieldLabel
|
|
70
|
+
const FieldLabel = styled(
|
|
69
71
|
({
|
|
70
72
|
className,
|
|
71
73
|
children,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}) => {
|
|
74
|
+
error,
|
|
75
|
+
description,
|
|
76
|
+
size = "sm",
|
|
77
|
+
}: FieldLabelProps) => {
|
|
76
78
|
return (
|
|
77
|
-
<div className={className}>
|
|
79
|
+
<div className={className + " FieldLabel"}>
|
|
78
80
|
<InfoComponent description={description} label={children}>
|
|
79
81
|
<div className="label">{children}</div>
|
|
80
82
|
</InfoComponent>
|
|
81
83
|
{error && (
|
|
82
|
-
<div className="error" title={
|
|
83
|
-
{
|
|
84
|
+
<div className="error" title={error}>
|
|
85
|
+
{error || "Invalid Value"}
|
|
84
86
|
</div>
|
|
85
87
|
)}
|
|
86
88
|
</div>
|
|
87
89
|
);
|
|
88
90
|
}
|
|
89
91
|
)`
|
|
92
|
+
user-select: none;
|
|
90
93
|
font-family: apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
|
91
94
|
"Helvetica Neue", Arial, sans-serif;
|
|
92
95
|
user-select: none;
|
|
93
96
|
display: flex;
|
|
94
97
|
flex-direction: row;
|
|
95
|
-
align-items:
|
|
98
|
+
align-items: baseline;
|
|
96
99
|
gap: 5px;
|
|
97
100
|
|
|
98
101
|
min-height: 15px;
|
|
99
|
-
// font-size: 12px;
|
|
100
102
|
font-weight: 400;
|
|
101
103
|
margin-bottom: 2.5px;
|
|
102
104
|
|
|
@@ -134,6 +136,7 @@ const FieldLabel: React.FC<FieldLabelProps> = styled(
|
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
.error {
|
|
139
|
+
user-select: none;
|
|
137
140
|
transition: all 0.2s ease;
|
|
138
141
|
cursor: pointer;
|
|
139
142
|
color: ${({ theme }) => theme.palette.error.main};
|
package/{src/components/FileInputField/FileInputField.js → FileInputField/FileInputField.tsx}
RENAMED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
2
|
-
import { useDropzone } from "react-dropzone";
|
|
1
|
+
import { useCallback, useState, ReactNode, HTMLAttributes } from "react";
|
|
3
2
|
import styled from "styled-components";
|
|
4
|
-
import
|
|
5
|
-
import Pill from "
|
|
3
|
+
import { useDropzone, DropzoneOptions } from "react-dropzone";
|
|
4
|
+
import { Pill, FieldLabel } from "..";
|
|
5
|
+
import { Size, Variant } from "../core";
|
|
6
|
+
|
|
7
|
+
interface FileInputFieldProps {
|
|
8
|
+
className?: string;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
variant?: Variant;
|
|
11
|
+
label?: string;
|
|
12
|
+
error?: string;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
size?: Size;
|
|
15
|
+
onChange?: (files: File[]) => void;
|
|
16
|
+
onFocus?: () => void;
|
|
17
|
+
dropZoneOptions?: DropzoneOptions;
|
|
18
|
+
style?: HTMLAttributes<HTMLDivElement>;
|
|
19
|
+
}
|
|
6
20
|
|
|
7
21
|
const FileInputField = styled(
|
|
8
22
|
({
|
|
@@ -10,23 +24,22 @@ const FileInputField = styled(
|
|
|
10
24
|
children,
|
|
11
25
|
label,
|
|
12
26
|
error,
|
|
13
|
-
errorMessage,
|
|
14
27
|
required,
|
|
15
28
|
size,
|
|
16
29
|
onChange,
|
|
17
30
|
onFocus,
|
|
18
31
|
dropZoneOptions = {},
|
|
19
32
|
style = {},
|
|
20
|
-
}) => {
|
|
21
|
-
const [files, setFiles] = useState([]);
|
|
33
|
+
}: FileInputFieldProps) => {
|
|
34
|
+
const [files, setFiles] = useState<File[]>([]);
|
|
22
35
|
|
|
23
|
-
const onDrop = useCallback((acceptedFiles) => {
|
|
36
|
+
const onDrop = useCallback((acceptedFiles: File[]) => {
|
|
24
37
|
setFiles(acceptedFiles);
|
|
25
38
|
// Do something with the files
|
|
26
39
|
onChange?.(acceptedFiles);
|
|
27
40
|
}, []);
|
|
28
41
|
|
|
29
|
-
const handleRemoveFile = (file) => {
|
|
42
|
+
const handleRemoveFile = (file: File) => {
|
|
30
43
|
setFiles((prev) => prev.filter((f) => f !== file));
|
|
31
44
|
};
|
|
32
45
|
|
|
@@ -38,12 +51,7 @@ const FileInputField = styled(
|
|
|
38
51
|
return (
|
|
39
52
|
<div className={className}>
|
|
40
53
|
{label && (
|
|
41
|
-
<FieldLabel
|
|
42
|
-
error={error}
|
|
43
|
-
errorMessage={errorMessage}
|
|
44
|
-
asterisk={required}
|
|
45
|
-
size={size}
|
|
46
|
-
>
|
|
54
|
+
<FieldLabel error={error} asterisk={required} size={size}>
|
|
47
55
|
{label}
|
|
48
56
|
</FieldLabel>
|
|
49
57
|
)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./FileInputField";
|