@monolith-forensics/monolith-ui 1.0.12 → 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 -20
- 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
|
@@ -1,563 +0,0 @@
|
|
|
1
|
-
import styled from "styled-components";
|
|
2
|
-
import { useFloating, flip, offset } from "@floating-ui/react";
|
|
3
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
-
import FieldLabel from "../FieldLabel/FieldLabel.js";
|
|
5
|
-
import Pill from "../Pill/Pill.js";
|
|
6
|
-
import { ArrowButton, ClearButton } from "../SelectBox/SelectBox.js";
|
|
7
|
-
|
|
8
|
-
const StyledInputContainer = styled.div`
|
|
9
|
-
position: relative;
|
|
10
|
-
cursor: pointer;
|
|
11
|
-
|
|
12
|
-
user-select: none;
|
|
13
|
-
|
|
14
|
-
display: flex;
|
|
15
|
-
flex-direction: row;
|
|
16
|
-
align-items: center;
|
|
17
|
-
user-select: none;
|
|
18
|
-
|
|
19
|
-
pointer-events: all;
|
|
20
|
-
outline: none;
|
|
21
|
-
|
|
22
|
-
border-radius: 5px;
|
|
23
|
-
transition: border 0.1s ease-in-out;
|
|
24
|
-
border: 1px solid
|
|
25
|
-
${({ theme, variant }) => {
|
|
26
|
-
switch (variant) {
|
|
27
|
-
case "filled":
|
|
28
|
-
return "transparent";
|
|
29
|
-
case "outlined":
|
|
30
|
-
return theme.palette.input.border;
|
|
31
|
-
case "text":
|
|
32
|
-
return "transparent";
|
|
33
|
-
default:
|
|
34
|
-
return theme.palette.input.border;
|
|
35
|
-
}
|
|
36
|
-
}};
|
|
37
|
-
font-weight: 500;
|
|
38
|
-
color: ${(props) => props.theme.palette.text.primary};
|
|
39
|
-
font-size: ${({ size }) =>
|
|
40
|
-
size === "xs"
|
|
41
|
-
? "12px"
|
|
42
|
-
: size === "sm"
|
|
43
|
-
? "14px"
|
|
44
|
-
: size === "md"
|
|
45
|
-
? "16px"
|
|
46
|
-
: size === "lg"
|
|
47
|
-
? "18px"
|
|
48
|
-
: size === "xl"
|
|
49
|
-
? "20px"
|
|
50
|
-
: "12px"};
|
|
51
|
-
|
|
52
|
-
width: 100%;
|
|
53
|
-
min-height: ${({ size }) =>
|
|
54
|
-
size === "xs"
|
|
55
|
-
? "26px"
|
|
56
|
-
: size === "sm"
|
|
57
|
-
? "30px"
|
|
58
|
-
: size === "md"
|
|
59
|
-
? "36px"
|
|
60
|
-
: size === "lg"
|
|
61
|
-
? "42px"
|
|
62
|
-
: size === "xl"
|
|
63
|
-
? "50px"
|
|
64
|
-
: "26px"};
|
|
65
|
-
|
|
66
|
-
padding: ${({ size }) =>
|
|
67
|
-
size === "xs"
|
|
68
|
-
? "3px 8px"
|
|
69
|
-
: size === "sm"
|
|
70
|
-
? "3px 10px"
|
|
71
|
-
: size === "md"
|
|
72
|
-
? "5px 12px"
|
|
73
|
-
: size === "lg"
|
|
74
|
-
? "5px 14px"
|
|
75
|
-
: size === "xl"
|
|
76
|
-
? "5px 16px"
|
|
77
|
-
: "5px 8px"};
|
|
78
|
-
|
|
79
|
-
&[data-button-right="true"] {
|
|
80
|
-
padding-right: 36px;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
background-color: ${({ theme, variant }) => {
|
|
84
|
-
switch (variant) {
|
|
85
|
-
case "filled":
|
|
86
|
-
return theme.palette.input.background;
|
|
87
|
-
case "outlined":
|
|
88
|
-
return theme.palette.input.background;
|
|
89
|
-
case "text":
|
|
90
|
-
return "transparent";
|
|
91
|
-
default:
|
|
92
|
-
return theme.palette.input.background;
|
|
93
|
-
}
|
|
94
|
-
}};
|
|
95
|
-
|
|
96
|
-
&[readOnly] {
|
|
97
|
-
cursor: pointer;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
& [data-has-space="true"] {
|
|
101
|
-
padding-left: 4px;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
& [data-selected="true"] {
|
|
105
|
-
background-color: ${(props) => props.theme.palette.primary.main}50;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
&[data-empty="true"] {
|
|
109
|
-
color: ${(props) => props.theme.palette.input.placeholder};
|
|
110
|
-
div {
|
|
111
|
-
color: ${(props) => props.theme.palette.input.placeholder};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
& [data-default-btn="true"] {
|
|
116
|
-
color: ${(props) => props.theme.palette.text.secondary};
|
|
117
|
-
div {
|
|
118
|
-
color: ${(props) => props.theme.palette.text.secondary};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
&:focus {
|
|
123
|
-
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
124
|
-
}
|
|
125
|
-
`;
|
|
126
|
-
|
|
127
|
-
const StyledInput = styled.input`
|
|
128
|
-
pointer-events: all;
|
|
129
|
-
outline: none;
|
|
130
|
-
background: transparent;
|
|
131
|
-
height: 100%;
|
|
132
|
-
flex: 1;
|
|
133
|
-
appearance: none;
|
|
134
|
-
border: 0;
|
|
135
|
-
color: inherit;
|
|
136
|
-
|
|
137
|
-
font-size: ${({ size }) =>
|
|
138
|
-
size === "xs"
|
|
139
|
-
? "12px"
|
|
140
|
-
: size === "sm"
|
|
141
|
-
? "14px"
|
|
142
|
-
: size === "md"
|
|
143
|
-
? "16px"
|
|
144
|
-
: size === "lg"
|
|
145
|
-
? "18px"
|
|
146
|
-
: size === "xl"
|
|
147
|
-
? "20px"
|
|
148
|
-
: "12px"};
|
|
149
|
-
|
|
150
|
-
::placeholder {
|
|
151
|
-
font-size: ${({ size }) =>
|
|
152
|
-
size === "xs"
|
|
153
|
-
? "10px"
|
|
154
|
-
: size === "sm"
|
|
155
|
-
? "12px"
|
|
156
|
-
: size === "md"
|
|
157
|
-
? "14px"
|
|
158
|
-
: size === "lg"
|
|
159
|
-
? "16px"
|
|
160
|
-
: size === "xl"
|
|
161
|
-
? "18px"
|
|
162
|
-
: "10px"};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
&[data-button-right="true"] {
|
|
166
|
-
padding-right: 30px;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
&[readOnly] {
|
|
170
|
-
cursor: pointer;
|
|
171
|
-
}
|
|
172
|
-
`;
|
|
173
|
-
|
|
174
|
-
const StyledInnerContainer = styled.div`
|
|
175
|
-
display: flex;
|
|
176
|
-
align-items: center;
|
|
177
|
-
gap: 5px;
|
|
178
|
-
flex-wrap: wrap;
|
|
179
|
-
|
|
180
|
-
&[data-button-right="true"] {
|
|
181
|
-
padding-right: 30px;
|
|
182
|
-
}
|
|
183
|
-
`;
|
|
184
|
-
|
|
185
|
-
const StyledFloatContainer = styled.div`
|
|
186
|
-
z-index: 100000;
|
|
187
|
-
`;
|
|
188
|
-
|
|
189
|
-
const StyledContent = styled.div`
|
|
190
|
-
position: relative;
|
|
191
|
-
|
|
192
|
-
max-height: ${({ maxDropdownHeight }) =>
|
|
193
|
-
Number.isInteger(maxDropdownHeight)
|
|
194
|
-
? `${maxDropdownHeight}px`
|
|
195
|
-
: maxDropdownHeight || "250px"};
|
|
196
|
-
|
|
197
|
-
overflow-y: auto;
|
|
198
|
-
overflow-x: hidden;
|
|
199
|
-
|
|
200
|
-
background-color: ${(props) => props.theme.palette.background.default};
|
|
201
|
-
background-color: ${({ theme, variant }) => {
|
|
202
|
-
switch (variant) {
|
|
203
|
-
case "filled":
|
|
204
|
-
return theme.palette.input.background;
|
|
205
|
-
case "outlined":
|
|
206
|
-
return theme.palette.input.background;
|
|
207
|
-
case "text":
|
|
208
|
-
return "transparent";
|
|
209
|
-
default:
|
|
210
|
-
return theme.palette.input.background;
|
|
211
|
-
}
|
|
212
|
-
}};
|
|
213
|
-
|
|
214
|
-
border-radius: 5px;
|
|
215
|
-
border: 1px solid ${(props) => props.theme.palette.divider};
|
|
216
|
-
padding: 5px;
|
|
217
|
-
box-shadow: 0px 10px 38px -10px rgba(22, 23, 24, 0.85),
|
|
218
|
-
0px 10px 20px -15px rgba(22, 23, 24, 0.65);
|
|
219
|
-
animation-duration: 400ms;
|
|
220
|
-
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
|
|
221
|
-
will-change: transform, opacity;
|
|
222
|
-
|
|
223
|
-
&[data-empty="true"] {
|
|
224
|
-
display: none;
|
|
225
|
-
}
|
|
226
|
-
`;
|
|
227
|
-
|
|
228
|
-
const StyledItem = styled.div`
|
|
229
|
-
line-height: 1;
|
|
230
|
-
color: ${(props) => props.theme.palette.text.primary};
|
|
231
|
-
border-radius: 3px;
|
|
232
|
-
display: flex;
|
|
233
|
-
align-items: center;
|
|
234
|
-
min-height: 25px;
|
|
235
|
-
padding: 7px 10px;
|
|
236
|
-
position: relative;
|
|
237
|
-
user-select: none;
|
|
238
|
-
outline: none;
|
|
239
|
-
|
|
240
|
-
cursor: pointer;
|
|
241
|
-
|
|
242
|
-
font-family: "Arial", sans-serif;
|
|
243
|
-
font-size: ${({ size }) =>
|
|
244
|
-
size === "xs"
|
|
245
|
-
? "12px"
|
|
246
|
-
: size === "sm"
|
|
247
|
-
? "14px"
|
|
248
|
-
: size === "md"
|
|
249
|
-
? "16px"
|
|
250
|
-
: size === "lg"
|
|
251
|
-
? "18px"
|
|
252
|
-
: size === "xl"
|
|
253
|
-
? "20px"
|
|
254
|
-
: "12px"};
|
|
255
|
-
|
|
256
|
-
&[data-disabled] {
|
|
257
|
-
color: ${(props) => props.theme.palette.text.secondary};
|
|
258
|
-
pointer-events: "none";
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
&:hover {
|
|
262
|
-
background-color: ${(props) => props.theme.palette.action.hover};
|
|
263
|
-
color: ${(props) => props.theme.palette.text.primary};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
&[data-selected="true"] {
|
|
267
|
-
display: none;
|
|
268
|
-
// background-color: ${(props) => props.theme.palette.divider};
|
|
269
|
-
color: ${(props) => props.theme.palette.primary.main};
|
|
270
|
-
}
|
|
271
|
-
`;
|
|
272
|
-
|
|
273
|
-
const TagBox = styled(
|
|
274
|
-
({
|
|
275
|
-
className,
|
|
276
|
-
data = [],
|
|
277
|
-
placeholder = "Select or enter tags",
|
|
278
|
-
arrow = true,
|
|
279
|
-
onChange,
|
|
280
|
-
onItemAdded,
|
|
281
|
-
size = "sm",
|
|
282
|
-
variant = "filled",
|
|
283
|
-
width = "100%",
|
|
284
|
-
allowCustomValue = true,
|
|
285
|
-
searchable = false,
|
|
286
|
-
clearable = false,
|
|
287
|
-
label = null,
|
|
288
|
-
description = null,
|
|
289
|
-
required = false,
|
|
290
|
-
error = false,
|
|
291
|
-
renderOption,
|
|
292
|
-
}) => {
|
|
293
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
294
|
-
const [selectedItems, setSelectedItems] = useState([]);
|
|
295
|
-
const [searchValue, setSearchValue] = useState("");
|
|
296
|
-
const inputRef = useRef(null);
|
|
297
|
-
|
|
298
|
-
const isObjectArray = data.length > 0 && data[0]?.label !== undefined;
|
|
299
|
-
|
|
300
|
-
const filteredItems = data.filter((item) =>
|
|
301
|
-
isObjectArray
|
|
302
|
-
? item.label.toLowerCase().includes(searchValue.toLowerCase())
|
|
303
|
-
: item.toLowerCase().includes(searchValue.toLowerCase())
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
const { refs, floatingStyles } = useFloating({
|
|
307
|
-
open: isOpen,
|
|
308
|
-
onOpenChange: setIsOpen,
|
|
309
|
-
placement: "bottom-start",
|
|
310
|
-
strategy: "absolute",
|
|
311
|
-
// Handle collisions with the viewport
|
|
312
|
-
middleware: [flip(), offset(5)],
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const toggleOpen = () => {
|
|
316
|
-
setIsOpen((prev) => {
|
|
317
|
-
if (!prev) {
|
|
318
|
-
inputRef?.current?.focus?.();
|
|
319
|
-
}
|
|
320
|
-
return !prev;
|
|
321
|
-
});
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
const handleClear = (e) => {
|
|
325
|
-
e.preventDefault();
|
|
326
|
-
e.stopPropagation();
|
|
327
|
-
|
|
328
|
-
if (inputRef?.current?.value) inputRef.current.value = "";
|
|
329
|
-
onChange?.([]);
|
|
330
|
-
setSelectedItems([]);
|
|
331
|
-
setIsOpen(false);
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
const handleItemClick = (event, item) => {
|
|
335
|
-
if (inputRef?.current?.value) inputRef.current.value = "";
|
|
336
|
-
setSearchValue("");
|
|
337
|
-
handleChangeSelection(item);
|
|
338
|
-
// setIsOpen(false);
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const handleRemoveItem = (item) => {
|
|
342
|
-
setSelectedItems((prev) => {
|
|
343
|
-
const newItems = prev.filter((prevItem) =>
|
|
344
|
-
isObjectArray ? prevItem.value !== item.value : prevItem !== item
|
|
345
|
-
);
|
|
346
|
-
onChange?.(newItems.map((item) => item?.value || item));
|
|
347
|
-
return newItems;
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
const handleChangeSelection = useCallback(
|
|
352
|
-
(option) => {
|
|
353
|
-
setSelectedItems((prev) => {
|
|
354
|
-
onChange?.([
|
|
355
|
-
...prev.map((item) => item?.value || item),
|
|
356
|
-
option?.value || option,
|
|
357
|
-
]);
|
|
358
|
-
return [...prev, option];
|
|
359
|
-
});
|
|
360
|
-
},
|
|
361
|
-
[onChange]
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
const handleAddItem = useCallback(
|
|
365
|
-
(newItem) => {
|
|
366
|
-
const isNewItem = data.every((item) =>
|
|
367
|
-
isObjectArray
|
|
368
|
-
? item.label.toLowerCase() !== newItem.toLowerCase()
|
|
369
|
-
: item.toLowerCase() !== newItem.toLowerCase()
|
|
370
|
-
);
|
|
371
|
-
if (isNewItem) {
|
|
372
|
-
const newValue = isObjectArray
|
|
373
|
-
? { label: newItem, value: newItem }
|
|
374
|
-
: newItem;
|
|
375
|
-
data.push(newValue);
|
|
376
|
-
handleChangeSelection(newValue);
|
|
377
|
-
onItemAdded?.(newValue);
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
[onItemAdded]
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
const handleKeyDown = (e) => {
|
|
384
|
-
// // Escape key
|
|
385
|
-
// if (e.key === "Escape") {
|
|
386
|
-
// refs?.reference?.current?.blur();
|
|
387
|
-
// setIsOpen(false);
|
|
388
|
-
// }
|
|
389
|
-
|
|
390
|
-
// // Enter key
|
|
391
|
-
// if (e.key === "Enter") {
|
|
392
|
-
// const currentInputValue = inputRef?.current?.value;
|
|
393
|
-
// if (currentInputValue === "") {
|
|
394
|
-
// return;
|
|
395
|
-
// }
|
|
396
|
-
// if (allowCustomValue) {
|
|
397
|
-
// handleAddItem(currentInputValue);
|
|
398
|
-
// setSearchValue("");
|
|
399
|
-
// if (inputRef?.current?.value) inputRef.current.value = "";
|
|
400
|
-
// } else {
|
|
401
|
-
// const item = data.find((item) =>
|
|
402
|
-
// isObjectArray
|
|
403
|
-
// ? item.label.toLowerCase() === currentInputValue.toLowerCase()
|
|
404
|
-
// : item.toLowerCase() === currentInputValue.toLowerCase()
|
|
405
|
-
// );
|
|
406
|
-
// if (!item) {
|
|
407
|
-
// if (inputRef?.current?.value) inputRef.current.value = "";
|
|
408
|
-
// setSearchValue("");
|
|
409
|
-
// // handleChangeSelection(null);
|
|
410
|
-
// }
|
|
411
|
-
// }
|
|
412
|
-
|
|
413
|
-
// setIsOpen(false);
|
|
414
|
-
// }
|
|
415
|
-
|
|
416
|
-
// // Arrow down
|
|
417
|
-
// if (e.key === "ArrowDown") {
|
|
418
|
-
// e.preventDefault();
|
|
419
|
-
// setSelected((prev) => {
|
|
420
|
-
// let newItem = filteredItems[0]; // Loop back to the first item
|
|
421
|
-
// const index = filteredItems.findIndex((item) =>
|
|
422
|
-
// isObjectArray ? item.value === prev?.value : item === prev
|
|
423
|
-
// );
|
|
424
|
-
// if (index < filteredItems.length - 1) {
|
|
425
|
-
// newItem = filteredItems[index + 1];
|
|
426
|
-
// }
|
|
427
|
-
// if (inputRef?.current?.value) inputRef.current.value = newItem.label;
|
|
428
|
-
// onChange?.(newItem?.value || newItem, newItem);
|
|
429
|
-
// return newItem;
|
|
430
|
-
// });
|
|
431
|
-
// }
|
|
432
|
-
|
|
433
|
-
// // Arrow up
|
|
434
|
-
// if (e.key === "ArrowUp") {
|
|
435
|
-
// e.preventDefault();
|
|
436
|
-
// setSelected((prev) => {
|
|
437
|
-
// let newItem = filteredItems[filteredItems.length - 1]; // Loop back to the last item
|
|
438
|
-
// const index = filteredItems.findIndex((item) =>
|
|
439
|
-
// isObjectArray ? item.value === prev?.value : item === prev
|
|
440
|
-
// );
|
|
441
|
-
// if (index > 0) {
|
|
442
|
-
// newItem = filteredItems[index - 1];
|
|
443
|
-
// }
|
|
444
|
-
// if (inputRef?.current?.value) inputRef.current.value = newItem.label;
|
|
445
|
-
// onChange?.(newItem?.value || newItem, newItem);
|
|
446
|
-
// return newItem;
|
|
447
|
-
// });
|
|
448
|
-
// }
|
|
449
|
-
|
|
450
|
-
// Tab key
|
|
451
|
-
if (e.key === "Tab") {
|
|
452
|
-
setIsOpen(false);
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
// Close on outside click
|
|
457
|
-
useEffect(() => {
|
|
458
|
-
const close = (e) => {
|
|
459
|
-
if (
|
|
460
|
-
refs.floating.current && // Check if the floating element exists
|
|
461
|
-
e.target !== refs.reference.current && // Check if the target is not the reference (input)
|
|
462
|
-
!refs.reference.current.contains(e.target) && // Check if the target is not inside the reference (input)
|
|
463
|
-
!refs.floating.current.contains(e.target) // Check if the target is not inside the floating element (content)
|
|
464
|
-
) {
|
|
465
|
-
setIsOpen(false);
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
document.addEventListener("click", close);
|
|
469
|
-
return () => document.removeEventListener("click", close);
|
|
470
|
-
}, [refs.floating]);
|
|
471
|
-
|
|
472
|
-
const contentWidth =
|
|
473
|
-
refs?.reference?.current?.getClientRects?.()?.[0]?.width || "100%";
|
|
474
|
-
|
|
475
|
-
return (
|
|
476
|
-
<div>
|
|
477
|
-
{label && (
|
|
478
|
-
<FieldLabel
|
|
479
|
-
error={error}
|
|
480
|
-
asterisk={required}
|
|
481
|
-
size={size}
|
|
482
|
-
description={description}
|
|
483
|
-
>
|
|
484
|
-
{label}
|
|
485
|
-
</FieldLabel>
|
|
486
|
-
)}
|
|
487
|
-
<StyledInputContainer
|
|
488
|
-
ref={refs.setReference}
|
|
489
|
-
onClick={toggleOpen}
|
|
490
|
-
size={size}
|
|
491
|
-
variant={variant}
|
|
492
|
-
width={width}
|
|
493
|
-
onKeyDown={handleKeyDown}
|
|
494
|
-
>
|
|
495
|
-
<StyledInnerContainer data-button-right={arrow || clearable}>
|
|
496
|
-
{selectedItems.map((item, index) => (
|
|
497
|
-
<Pill
|
|
498
|
-
key={index}
|
|
499
|
-
size="xs"
|
|
500
|
-
onRemove={() => handleRemoveItem(item)}
|
|
501
|
-
>
|
|
502
|
-
{item.label}
|
|
503
|
-
</Pill>
|
|
504
|
-
))}
|
|
505
|
-
{(searchable || allowCustomValue || selectedItems.length === 0) && (
|
|
506
|
-
<StyledInput
|
|
507
|
-
ref={inputRef}
|
|
508
|
-
onChange={(e) => setSearchValue(e.target.value)}
|
|
509
|
-
placeholder={placeholder}
|
|
510
|
-
size={size}
|
|
511
|
-
readOnly={!(searchable || allowCustomValue)}
|
|
512
|
-
data-button-right={arrow || clearable}
|
|
513
|
-
/>
|
|
514
|
-
)}
|
|
515
|
-
</StyledInnerContainer>
|
|
516
|
-
{clearable && selectedItems.length > 0 ? (
|
|
517
|
-
<ClearButton onClick={handleClear} />
|
|
518
|
-
) : arrow ? (
|
|
519
|
-
<ArrowButton />
|
|
520
|
-
) : null}
|
|
521
|
-
</StyledInputContainer>
|
|
522
|
-
{isOpen && (
|
|
523
|
-
<StyledFloatContainer
|
|
524
|
-
ref={refs.setFloating}
|
|
525
|
-
style={floatingStyles}
|
|
526
|
-
className="mfFloating"
|
|
527
|
-
>
|
|
528
|
-
<StyledContent
|
|
529
|
-
className="mfFloatingContent"
|
|
530
|
-
style={{ width: contentWidth, maxWidth: contentWidth }}
|
|
531
|
-
variant={variant}
|
|
532
|
-
data-empty={
|
|
533
|
-
filteredItems.length === 0 ||
|
|
534
|
-
selectedItems.length === filteredItems.length
|
|
535
|
-
}
|
|
536
|
-
>
|
|
537
|
-
{filteredItems.map((item, index) => (
|
|
538
|
-
<StyledItem
|
|
539
|
-
key={item?.value || index}
|
|
540
|
-
className="mfFloatingItem"
|
|
541
|
-
onClick={(e) => handleItemClick(e, item)}
|
|
542
|
-
data-selected={selectedItems.some(
|
|
543
|
-
(selectedItem) =>
|
|
544
|
-
selectedItem.value === item?.value ||
|
|
545
|
-
selectedItem === item
|
|
546
|
-
)}
|
|
547
|
-
size={size}
|
|
548
|
-
>
|
|
549
|
-
{renderOption ? renderOption(item) : item?.label || item}
|
|
550
|
-
</StyledItem>
|
|
551
|
-
))}
|
|
552
|
-
</StyledContent>
|
|
553
|
-
</StyledFloatContainer>
|
|
554
|
-
)}
|
|
555
|
-
</div>
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
)`
|
|
559
|
-
position: relative;
|
|
560
|
-
cursor: pointer;
|
|
561
|
-
`;
|
|
562
|
-
|
|
563
|
-
export default TagBox;
|
package/src/components/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as Button } from "./Button";
|
|
2
|
-
export { default as Input } from "./Input";
|
|
3
|
-
export { default as TextArea } from "./TextArea";
|
|
4
|
-
export { default as FieldLabel } from "./FieldLabel";
|
|
5
|
-
export { default as TextInput } from "./TextInput";
|
|
6
|
-
export { default as TextAreaInput } from "./TextAreaInput";
|
|
7
|
-
export { default as Pill } from "./Pill";
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./components";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|