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