@chayns-components/core 5.0.0-beta.1155 → 5.0.0-beta.1158
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/lib/cjs/components/combobox/ComboBox.js +92 -199
- package/lib/cjs/components/combobox/ComboBox.js.map +1 -1
- package/lib/cjs/components/combobox/ComboBox.styles.js +18 -49
- package/lib/cjs/components/combobox/ComboBox.styles.js.map +1 -1
- package/lib/cjs/components/combobox/combobox-item/ComboBoxItem.js +1 -1
- package/lib/cjs/components/combobox/combobox-item/ComboBoxItem.js.map +1 -1
- package/lib/cjs/components/dropdown-body-wrapper/DropdownBodyWrapper.js +86 -0
- package/lib/cjs/components/dropdown-body-wrapper/DropdownBodyWrapper.js.map +1 -0
- package/lib/cjs/components/dropdown-body-wrapper/DropdownBodyWrapper.styles.js +50 -0
- package/lib/cjs/components/dropdown-body-wrapper/DropdownBodyWrapper.styles.js.map +1 -0
- package/lib/cjs/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.js +104 -0
- package/lib/cjs/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.js.map +1 -0
- package/lib/cjs/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.styles.js +37 -0
- package/lib/cjs/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.styles.js.map +1 -0
- package/lib/cjs/components/grouped-image/GroupedImage.js.map +1 -1
- package/lib/cjs/components/list/list-item/list-item-body/ListItemBody.js.map +1 -1
- package/lib/cjs/components/search-box/SearchBox.js +77 -172
- package/lib/cjs/components/search-box/SearchBox.js.map +1 -1
- package/lib/cjs/components/search-box/search-box-body/SearchBoxBody.js +8 -28
- package/lib/cjs/components/search-box/search-box-body/SearchBoxBody.js.map +1 -1
- package/lib/cjs/components/search-box/search-box-body/SearchBoxBody.styles.js +2 -20
- package/lib/cjs/components/search-box/search-box-body/SearchBoxBody.styles.js.map +1 -1
- package/lib/cjs/hooks/container.js +9 -5
- package/lib/cjs/hooks/container.js.map +1 -1
- package/lib/cjs/hooks/dropdown.js +128 -0
- package/lib/cjs/hooks/dropdown.js.map +1 -0
- package/lib/cjs/index.js +7 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types/dropdown.js +18 -0
- package/lib/cjs/types/dropdown.js.map +1 -0
- package/lib/cjs/utils/calculate.js.map +1 -1
- package/lib/esm/components/combobox/ComboBox.js +57 -164
- package/lib/esm/components/combobox/ComboBox.js.map +1 -1
- package/lib/esm/components/combobox/ComboBox.styles.js +24 -71
- package/lib/esm/components/combobox/ComboBox.styles.js.map +1 -1
- package/lib/esm/components/combobox/combobox-item/ComboBoxItem.js +1 -1
- package/lib/esm/components/combobox/combobox-item/ComboBoxItem.js.map +1 -1
- package/lib/esm/components/dropdown-body-wrapper/DropdownBodyWrapper.js +79 -0
- package/lib/esm/components/dropdown-body-wrapper/DropdownBodyWrapper.js.map +1 -0
- package/lib/esm/components/dropdown-body-wrapper/DropdownBodyWrapper.styles.js +59 -0
- package/lib/esm/components/dropdown-body-wrapper/DropdownBodyWrapper.styles.js.map +1 -0
- package/lib/esm/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.js +98 -0
- package/lib/esm/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.js.map +1 -0
- package/lib/esm/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.styles.js +42 -0
- package/lib/esm/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.styles.js.map +1 -0
- package/lib/esm/components/grouped-image/GroupedImage.js.map +1 -1
- package/lib/esm/components/list/list-item/list-item-body/ListItemBody.js.map +1 -1
- package/lib/esm/components/search-box/SearchBox.js +26 -121
- package/lib/esm/components/search-box/SearchBox.js.map +1 -1
- package/lib/esm/components/search-box/search-box-body/SearchBoxBody.js +9 -29
- package/lib/esm/components/search-box/search-box-body/SearchBoxBody.js.map +1 -1
- package/lib/esm/components/search-box/search-box-body/SearchBoxBody.styles.js +13 -40
- package/lib/esm/components/search-box/search-box-body/SearchBoxBody.styles.js.map +1 -1
- package/lib/esm/hooks/container.js +9 -5
- package/lib/esm/hooks/container.js.map +1 -1
- package/lib/esm/hooks/dropdown.js +122 -0
- package/lib/esm/hooks/dropdown.js.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types/dropdown.js +12 -0
- package/lib/esm/types/dropdown.js.map +1 -0
- package/lib/esm/utils/calculate.js.map +1 -1
- package/lib/types/components/combobox/ComboBox.d.ts +9 -5
- package/lib/types/components/combobox/ComboBox.styles.d.ts +5 -12
- package/lib/types/components/dropdown-body-wrapper/DropdownBodyWrapper.d.ts +51 -0
- package/lib/types/components/dropdown-body-wrapper/DropdownBodyWrapper.styles.d.ts +11 -0
- package/lib/types/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.d.ts +26 -0
- package/lib/types/components/dropdown-body-wrapper/delayed-dropdown-content/DelayedDropdownContent.styles.d.ts +11 -0
- package/lib/types/components/grouped-image/GroupedImage.d.ts +4 -4
- package/lib/types/components/list/list-item/list-item-body/ListItemBody.d.ts +2 -2
- package/lib/types/components/search-box/search-box-body/SearchBoxBody.d.ts +0 -7
- package/lib/types/components/search-box/search-box-body/SearchBoxBody.styles.d.ts +1 -6
- package/lib/types/hooks/container.d.ts +3 -2
- package/lib/types/hooks/dropdown.d.ts +42 -0
- package/lib/types/index.d.ts +2 -1
- package/lib/types/types/dropdown.d.ts +26 -0
- package/lib/types/utils/calculate.d.ts +1 -1
- package/package.json +2 -2
- package/lib/cjs/types/comboBox.js +0 -18
- package/lib/cjs/types/comboBox.js.map +0 -1
- package/lib/esm/types/comboBox.js +0 -12
- package/lib/esm/types/comboBox.js.map +0 -1
- package/lib/types/types/comboBox.d.ts +0 -10
|
@@ -5,24 +5,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _chaynsApi = require("chayns-api");
|
|
8
|
-
var _react = require("
|
|
9
|
-
var _react2 = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _reactDom = require("react-dom");
|
|
11
|
-
var _comboBox = require("../../types/comboBox");
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
9
|
var _calculate = require("../../utils/calculate");
|
|
13
10
|
var _environment = require("../../utils/environment");
|
|
14
11
|
var _AreaContextProvider = require("../area-provider/AreaContextProvider");
|
|
15
12
|
var _Icon = _interopRequireDefault(require("../icon/Icon"));
|
|
16
13
|
var _ComboBoxItem = _interopRequireDefault(require("./combobox-item/ComboBoxItem"));
|
|
17
14
|
var _ComboBox = require("./ComboBox.styles");
|
|
15
|
+
var _DropdownBodyWrapper = _interopRequireDefault(require("../dropdown-body-wrapper/DropdownBodyWrapper"));
|
|
16
|
+
var _dropdown = require("../../types/dropdown");
|
|
18
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
18
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
20
19
|
const ComboBox = ({
|
|
21
20
|
bodyWidth,
|
|
22
|
-
direction =
|
|
21
|
+
direction = _dropdown.DropdownDirection.RIGHT,
|
|
23
22
|
isDisabled = false,
|
|
24
23
|
lists,
|
|
25
|
-
maxHeight =
|
|
24
|
+
maxHeight = 280,
|
|
26
25
|
onSelect,
|
|
27
26
|
placeholder,
|
|
28
27
|
prefix,
|
|
@@ -38,40 +37,30 @@ const ComboBox = ({
|
|
|
38
37
|
onInputBlur,
|
|
39
38
|
inputValue
|
|
40
39
|
}) => {
|
|
41
|
-
const [internalSelectedItem, setInternalSelectedItem] = (0,
|
|
42
|
-
const [isAnimating, setIsAnimating] = (0,
|
|
43
|
-
const [minWidth, setMinWidth] = (0,
|
|
44
|
-
const [bodyMinWidth, setBodyMinWidth] = (0,
|
|
45
|
-
const [focusedIndex, setFocusedIndex] = (0,
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const [portal, setPortal] = (0, _react2.useState)();
|
|
50
|
-
const [internalCoordinates, setInternalCoordinates] = (0, _react2.useState)({
|
|
51
|
-
x: 0,
|
|
52
|
-
y: 0
|
|
53
|
-
});
|
|
54
|
-
const [newContainer, setNewContainer] = (0, _react2.useState)(container ?? null);
|
|
55
|
-
const [shouldUseTopAlignment, setShouldUseTopAlignment] = (0, _react2.useState)(false);
|
|
56
|
-
const isInputFocused = (0, _react2.useRef)(false);
|
|
57
|
-
const styledComboBoxElementRef = (0, _react2.useRef)(null);
|
|
58
|
-
const contentRef = (0, _react2.useRef)(null);
|
|
40
|
+
const [internalSelectedItem, setInternalSelectedItem] = (0, _react.useState)();
|
|
41
|
+
const [isAnimating, setIsAnimating] = (0, _react.useState)(false);
|
|
42
|
+
const [minWidth, setMinWidth] = (0, _react.useState)(undefined);
|
|
43
|
+
const [bodyMinWidth, setBodyMinWidth] = (0, _react.useState)(0);
|
|
44
|
+
const [focusedIndex, setFocusedIndex] = (0, _react.useState)(null);
|
|
45
|
+
const isInputFocused = (0, _react.useRef)(false);
|
|
46
|
+
const styledComboBoxElementRef = (0, _react.useRef)(null);
|
|
47
|
+
const contentRef = (0, _react.useRef)(null);
|
|
59
48
|
const functions = (0, _chaynsApi.useFunctions)();
|
|
60
49
|
const values = (0, _chaynsApi.useValues)();
|
|
50
|
+
const isTouch = (0, _environment.getIsTouch)();
|
|
61
51
|
const {
|
|
62
52
|
browser
|
|
63
53
|
} = (0, _chaynsApi.useDevice)();
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const shouldDisableActions = (0, _react2.useMemo)(() => {
|
|
54
|
+
const areaProvider = (0, _react.useContext)(_AreaContextProvider.AreaContext);
|
|
55
|
+
const shouldChangeColor = (0, _react.useMemo)(() => areaProvider.shouldChangeColor ?? false, [areaProvider.shouldChangeColor]);
|
|
56
|
+
const shouldDisableActions = (0, _react.useMemo)(() => {
|
|
68
57
|
if (!selectedItem) {
|
|
69
58
|
return false;
|
|
70
59
|
}
|
|
71
60
|
const combinedLists = lists.flatMap(list => list.list);
|
|
72
61
|
return combinedLists.length === 1 && combinedLists.some(item => item.value === selectedItem.value);
|
|
73
62
|
}, [lists, selectedItem]);
|
|
74
|
-
const contentHeight = (0,
|
|
63
|
+
const contentHeight = (0, _react.useMemo)(() => {
|
|
75
64
|
const flatItems = lists.flatMap(list => list.list);
|
|
76
65
|
let result = flatItems.length * 36;
|
|
77
66
|
if (lists.length > 1) {
|
|
@@ -87,81 +76,25 @@ const ComboBox = ({
|
|
|
87
76
|
}
|
|
88
77
|
return result;
|
|
89
78
|
}, [lists, maxHeight]);
|
|
90
|
-
(0,
|
|
91
|
-
if (styledComboBoxElementRef.current && !container) {
|
|
92
|
-
const el = styledComboBoxElementRef.current;
|
|
93
|
-
const element = el.closest('.dialog-inner') || el.closest('.page-provider') || el.closest('body');
|
|
94
|
-
setNewContainer(element);
|
|
95
|
-
}
|
|
96
|
-
}, [container]);
|
|
97
|
-
(0, _react2.useEffect)(() => {
|
|
98
|
-
if (container instanceof Element) {
|
|
99
|
-
setNewContainer(container);
|
|
100
|
-
}
|
|
101
|
-
}, [container]);
|
|
102
|
-
const handleInputFocus = (0, _react2.useCallback)(event => {
|
|
79
|
+
const handleInputFocus = (0, _react.useCallback)(event => {
|
|
103
80
|
isInputFocused.current = true;
|
|
104
81
|
onInputFocus === null || onInputFocus === void 0 || onInputFocus(event);
|
|
105
82
|
}, [onInputFocus]);
|
|
106
|
-
const handleInputBlur = (0,
|
|
83
|
+
const handleInputBlur = (0, _react.useCallback)(event => {
|
|
107
84
|
isInputFocused.current = false;
|
|
108
85
|
onInputBlur === null || onInputBlur === void 0 || onInputBlur(event);
|
|
109
86
|
}, [onInputBlur]);
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}, [styledComboBoxElementRef]);
|
|
115
|
-
const handleOpen = (0, _react2.useCallback)(() => {
|
|
116
|
-
if (shouldDisableActions) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (styledComboBoxElementRef.current && newContainer) {
|
|
120
|
-
const {
|
|
121
|
-
left: comboBoxLeft,
|
|
122
|
-
top: comboBoxTop,
|
|
123
|
-
height
|
|
124
|
-
} = styledComboBoxElementRef.current.getBoundingClientRect();
|
|
125
|
-
const {
|
|
126
|
-
left,
|
|
127
|
-
top,
|
|
128
|
-
height: containerHeight
|
|
129
|
-
} = newContainer.getBoundingClientRect();
|
|
130
|
-
const x = comboBoxLeft - left + newContainer.scrollLeft;
|
|
131
|
-
const y = comboBoxTop - top + newContainer.scrollTop;
|
|
132
|
-
let useTopAlignment = [_comboBox.ComboBoxDirection.TOP, _comboBox.ComboBoxDirection.TOP_LEFT, _comboBox.ComboBoxDirection.TOP_RIGHT].includes(direction);
|
|
133
|
-
const hasBottomAlignment = [_comboBox.ComboBoxDirection.BOTTOM, _comboBox.ComboBoxDirection.BOTTOM_LEFT, _comboBox.ComboBoxDirection.BOTTOM_RIGHT].includes(direction);
|
|
134
|
-
if (!hasBottomAlignment && y + height + contentHeight > containerHeight) {
|
|
135
|
-
useTopAlignment = true;
|
|
136
|
-
setShouldUseTopAlignment(true);
|
|
137
|
-
} else {
|
|
138
|
-
setShouldUseTopAlignment(false);
|
|
139
|
-
}
|
|
140
|
-
setInternalCoordinates({
|
|
141
|
-
x,
|
|
142
|
-
y: useTopAlignment ? y : y + height
|
|
143
|
-
});
|
|
144
|
-
setIsAnimating(true);
|
|
145
|
-
}
|
|
146
|
-
}, [shouldDisableActions, newContainer, contentHeight, direction]);
|
|
147
|
-
const handleClose = (0, _react2.useCallback)(() => {
|
|
87
|
+
const handleOpen = (0, _react.useCallback)(() => {
|
|
88
|
+
setIsAnimating(true);
|
|
89
|
+
}, []);
|
|
90
|
+
const handleClose = (0, _react.useCallback)(() => {
|
|
148
91
|
setIsAnimating(false);
|
|
149
92
|
}, []);
|
|
150
93
|
|
|
151
|
-
/**
|
|
152
|
-
* This function adds an event listener to the document to close the combobox when the user clicks outside of it
|
|
153
|
-
*/
|
|
154
|
-
(0, _react2.useEffect)(() => {
|
|
155
|
-
document.addEventListener('click', handleClick);
|
|
156
|
-
return () => {
|
|
157
|
-
document.removeEventListener('click', handleClick);
|
|
158
|
-
};
|
|
159
|
-
}, [handleClick, styledComboBoxElementRef]);
|
|
160
|
-
|
|
161
94
|
/**
|
|
162
95
|
* This function sets the selected item
|
|
163
96
|
*/
|
|
164
|
-
const handleSetSelectedItem = (0,
|
|
97
|
+
const handleSetSelectedItem = (0, _react.useCallback)(itemToSelect => {
|
|
165
98
|
if (typeof onSelect === 'function') {
|
|
166
99
|
const onSelectResult = onSelect(itemToSelect);
|
|
167
100
|
if (onSelectResult === false) {
|
|
@@ -179,45 +112,44 @@ const ComboBox = ({
|
|
|
179
112
|
setInternalSelectedItem(itemToSelect);
|
|
180
113
|
setIsAnimating(false);
|
|
181
114
|
}, [onSelect]);
|
|
182
|
-
const handleClear = (0,
|
|
115
|
+
const handleClear = (0, _react.useCallback)(event => {
|
|
183
116
|
event.preventDefault();
|
|
184
117
|
event.stopPropagation();
|
|
185
118
|
handleSetSelectedItem(undefined);
|
|
186
119
|
}, [handleSetSelectedItem]);
|
|
187
|
-
(0,
|
|
188
|
-
const currentContent = contentRef.current;
|
|
189
|
-
if (portal && isAnimating && currentContent) {
|
|
190
|
-
const scrollHeight = currentContent.scrollHeight ?? 0;
|
|
191
|
-
const maxHeightInPixels = (0, _calculate.getMaxHeightInPixels)(maxHeight, styledComboBoxElementRef.current ?? document.body);
|
|
192
|
-
setOverflowY(scrollHeight > maxHeightInPixels ? 'scroll' : 'hidden');
|
|
193
|
-
}
|
|
194
|
-
}, [isAnimating, maxHeight, portal]);
|
|
195
|
-
(0, _react2.useEffect)(() => {
|
|
120
|
+
(0, _react.useEffect)(() => {
|
|
196
121
|
const handleKeyDown = e => {
|
|
197
|
-
if (!isAnimating)
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
122
|
+
if (!isAnimating) return;
|
|
200
123
|
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
201
124
|
var _contentRef$current;
|
|
202
125
|
e.preventDefault();
|
|
203
126
|
const children = (_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.children;
|
|
204
|
-
if (children
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
setFocusedIndex(newIndex);
|
|
127
|
+
if (!children || children.length === 0) return;
|
|
128
|
+
const stepDirection = e.key === 'ArrowUp' ? -1 : 1;
|
|
129
|
+
let newIndex = focusedIndex ?? -1;
|
|
130
|
+
let attempts = 0;
|
|
131
|
+
do {
|
|
132
|
+
newIndex = (newIndex + stepDirection + children.length) % children.length;
|
|
211
133
|
const newElement = children[newIndex];
|
|
212
|
-
|
|
213
|
-
newElement.
|
|
134
|
+
let shouldSkip = false;
|
|
135
|
+
if (newElement.id.startsWith('combobox-group--') || newElement.id.endsWith('--disabled-item')) {
|
|
136
|
+
shouldSkip = true;
|
|
137
|
+
}
|
|
138
|
+
if (!shouldSkip) break;
|
|
139
|
+
attempts++;
|
|
140
|
+
} while (attempts < children.length);
|
|
141
|
+
if (focusedIndex !== null) {
|
|
142
|
+
const prevElement = children[focusedIndex];
|
|
143
|
+
prevElement.tabIndex = -1;
|
|
214
144
|
}
|
|
145
|
+
setFocusedIndex(newIndex);
|
|
146
|
+
const focusedElement = children[newIndex];
|
|
147
|
+
focusedElement.tabIndex = 0;
|
|
148
|
+
focusedElement.focus();
|
|
215
149
|
} else if (e.key === 'Enter' && focusedIndex !== null) {
|
|
216
150
|
var _contentRef$current2;
|
|
217
151
|
const element = (_contentRef$current2 = contentRef.current) === null || _contentRef$current2 === void 0 ? void 0 : _contentRef$current2.children[focusedIndex];
|
|
218
|
-
if (!element)
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
152
|
+
if (!element) return;
|
|
221
153
|
const {
|
|
222
154
|
id
|
|
223
155
|
} = element;
|
|
@@ -228,22 +160,19 @@ const ComboBox = ({
|
|
|
228
160
|
}) => String(value) === id.replace('combobox-item__', ''));
|
|
229
161
|
return !!newSelectedItem;
|
|
230
162
|
});
|
|
231
|
-
if (
|
|
232
|
-
|
|
163
|
+
if (newSelectedItem) {
|
|
164
|
+
handleSetSelectedItem(newSelectedItem);
|
|
233
165
|
}
|
|
234
|
-
handleSetSelectedItem(newSelectedItem);
|
|
235
166
|
}
|
|
236
167
|
};
|
|
237
168
|
document.addEventListener('keydown', handleKeyDown);
|
|
238
|
-
return () =>
|
|
239
|
-
document.removeEventListener('keydown', handleKeyDown);
|
|
240
|
-
};
|
|
169
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
241
170
|
}, [focusedIndex, handleSetSelectedItem, isAnimating, lists]);
|
|
242
171
|
|
|
243
172
|
/**
|
|
244
173
|
* This function calculates the greatest width
|
|
245
174
|
*/
|
|
246
|
-
(0,
|
|
175
|
+
(0, _react.useEffect)(() => {
|
|
247
176
|
var _styledComboBoxElemen;
|
|
248
177
|
const allItems = lists.flatMap(list => list.list);
|
|
249
178
|
const hasImage = [selectedItem, ...allItems].some(item => item === null || item === void 0 ? void 0 : item.imageUrl);
|
|
@@ -294,19 +223,11 @@ const ComboBox = ({
|
|
|
294
223
|
/**
|
|
295
224
|
* This function sets the external selected item
|
|
296
225
|
*/
|
|
297
|
-
(0,
|
|
226
|
+
(0, _react.useEffect)(() => {
|
|
298
227
|
setIsAnimating(false);
|
|
299
228
|
setInternalSelectedItem(selectedItem);
|
|
300
229
|
}, [selectedItem]);
|
|
301
|
-
(0,
|
|
302
|
-
if ([_comboBox.ComboBoxDirection.BOTTOM_LEFT, _comboBox.ComboBoxDirection.TOP_LEFT, _comboBox.ComboBoxDirection.LEFT].includes(direction) && typeof bodyWidth === 'number' && typeof minWidth === 'number') {
|
|
303
|
-
const difference = minWidth - bodyWidth;
|
|
304
|
-
setTranslateX(`${difference}px`);
|
|
305
|
-
} else {
|
|
306
|
-
setTranslateX('0px');
|
|
307
|
-
}
|
|
308
|
-
}, [bodyWidth, direction, minWidth]);
|
|
309
|
-
const placeholderImageUrl = (0, _react2.useMemo)(() => {
|
|
230
|
+
const placeholderImageUrl = (0, _react.useMemo)(() => {
|
|
310
231
|
if (selectedItem) {
|
|
311
232
|
return selectedItem.imageUrl;
|
|
312
233
|
}
|
|
@@ -315,7 +236,7 @@ const ComboBox = ({
|
|
|
315
236
|
}
|
|
316
237
|
return undefined;
|
|
317
238
|
}, [internalSelectedItem, selectedItem]);
|
|
318
|
-
const placeholderIcon = (0,
|
|
239
|
+
const placeholderIcon = (0, _react.useMemo)(() => {
|
|
319
240
|
if (selectedItem) {
|
|
320
241
|
return selectedItem.icons;
|
|
321
242
|
}
|
|
@@ -328,7 +249,7 @@ const ComboBox = ({
|
|
|
328
249
|
/**
|
|
329
250
|
* This function resets the placeholder
|
|
330
251
|
*/
|
|
331
|
-
const placeholderText = (0,
|
|
252
|
+
const placeholderText = (0, _react.useMemo)(() => {
|
|
332
253
|
let text = placeholder;
|
|
333
254
|
if (selectedItem) {
|
|
334
255
|
text = selectedItem.text;
|
|
@@ -337,7 +258,7 @@ const ComboBox = ({
|
|
|
337
258
|
}
|
|
338
259
|
return text;
|
|
339
260
|
}, [internalSelectedItem, placeholder, selectedItem]);
|
|
340
|
-
const shouldShowRoundPlaceholderImage = (0,
|
|
261
|
+
const shouldShowRoundPlaceholderImage = (0, _react.useMemo)(() => {
|
|
341
262
|
const selectedItemList = lists.find(list => list.list.some(({
|
|
342
263
|
value
|
|
343
264
|
}) => value === ((selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) ?? (internalSelectedItem === null || internalSelectedItem === void 0 ? void 0 : internalSelectedItem.value))));
|
|
@@ -347,7 +268,7 @@ const ComboBox = ({
|
|
|
347
268
|
/**
|
|
348
269
|
* This function opens the content of the combobox
|
|
349
270
|
*/
|
|
350
|
-
const handleHeaderClick = (0,
|
|
271
|
+
const handleHeaderClick = (0, _react.useCallback)(() => {
|
|
351
272
|
if (!isDisabled && !isInputFocused.current) {
|
|
352
273
|
if (isAnimating) {
|
|
353
274
|
handleClose();
|
|
@@ -356,12 +277,14 @@ const ComboBox = ({
|
|
|
356
277
|
}
|
|
357
278
|
}
|
|
358
279
|
}, [handleClose, handleOpen, isAnimating, isDisabled]);
|
|
359
|
-
const comboBoxGroups = (0,
|
|
280
|
+
const comboBoxGroups = (0, _react.useMemo)(() => lists.map(list => /*#__PURE__*/_react.default.createElement(_react.Fragment, {
|
|
360
281
|
key: list.groupName ?? 'default-group'
|
|
361
|
-
}, list.groupName && lists.length > 1 && /*#__PURE__*/
|
|
282
|
+
}, list.groupName && lists.length > 1 && /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxTopic, {
|
|
283
|
+
id: `combobox-group--${list.groupName}`
|
|
284
|
+
}, list.groupName), list.list.map(item =>
|
|
362
285
|
/*#__PURE__*/
|
|
363
286
|
// ToDo: Cleanup this - item should be given as a prop to avoid full spreading
|
|
364
|
-
|
|
287
|
+
_react.default.createElement(_ComboBoxItem.default, {
|
|
365
288
|
icons: item.icons,
|
|
366
289
|
id: item.value,
|
|
367
290
|
imageBackground: item.imageBackground,
|
|
@@ -379,59 +302,12 @@ const ComboBox = ({
|
|
|
379
302
|
value: item.value,
|
|
380
303
|
textStyles: item.textStyles
|
|
381
304
|
})))), [handleSetSelectedItem, lists, selectedItem, shouldShowBigImage, shouldShowRoundImage]);
|
|
382
|
-
|
|
383
|
-
left: internalCoordinates.x,
|
|
384
|
-
top: internalCoordinates.y
|
|
385
|
-
}), [internalCoordinates.x, internalCoordinates.y]);
|
|
386
|
-
(0, _react2.useEffect)(() => {
|
|
387
|
-
const useTopAlignment = shouldUseTopAlignment || [_comboBox.ComboBoxDirection.TOP, _comboBox.ComboBoxDirection.TOP_LEFT, _comboBox.ComboBoxDirection.TOP_RIGHT].includes(direction);
|
|
388
|
-
if (useTopAlignment) {
|
|
389
|
-
setTranslateY('-100%');
|
|
390
|
-
} else {
|
|
391
|
-
setTranslateY('0px');
|
|
392
|
-
}
|
|
393
|
-
}, [direction, shouldUseTopAlignment]);
|
|
394
|
-
(0, _react2.useEffect)(() => {
|
|
395
|
-
if (!newContainer) {
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
setPortal(() => /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react2.default.createElement(_react.AnimatePresence, {
|
|
399
|
-
initial: false
|
|
400
|
-
}, isAnimating && /*#__PURE__*/_react2.default.createElement(_ComboBox.StyledMotionComboBoxBody, {
|
|
401
|
-
$browser: browser === null || browser === void 0 ? void 0 : browser.name,
|
|
402
|
-
animate: {
|
|
403
|
-
height: 'fit-content',
|
|
404
|
-
opacity: 1
|
|
405
|
-
},
|
|
406
|
-
$overflowY: overflowY,
|
|
407
|
-
$translateX: translateX,
|
|
408
|
-
$translateY: translateY,
|
|
409
|
-
initial: {
|
|
410
|
-
height: 0,
|
|
411
|
-
opacity: 0
|
|
412
|
-
},
|
|
413
|
-
exit: {
|
|
414
|
-
height: 0,
|
|
415
|
-
opacity: 0
|
|
416
|
-
},
|
|
417
|
-
$maxHeight: maxHeight,
|
|
418
|
-
$minWidth: bodyWidth ?? bodyMinWidth,
|
|
419
|
-
style: bodyStyles,
|
|
420
|
-
$direction: direction,
|
|
421
|
-
$shouldUseCurrentItemWidth: shouldUseCurrentItemWidth,
|
|
422
|
-
transition: {
|
|
423
|
-
duration: 0.2
|
|
424
|
-
},
|
|
425
|
-
tabIndex: 0,
|
|
426
|
-
ref: contentRef
|
|
427
|
-
}, comboBoxGroups)), newContainer));
|
|
428
|
-
}, [bodyWidth, bodyMinWidth, bodyStyles, browser === null || browser === void 0 ? void 0 : browser.name, comboBoxGroups, newContainer, direction, isAnimating, maxHeight, minWidth, overflowY, shouldUseCurrentItemWidth, translateX, translateY]);
|
|
429
|
-
return (0, _react2.useMemo)(() => /*#__PURE__*/_react2.default.createElement(_ComboBox.StyledComboBox, {
|
|
305
|
+
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBox, {
|
|
430
306
|
ref: styledComboBoxElementRef,
|
|
431
307
|
$minWidth: minWidth,
|
|
432
308
|
$shouldUseFullWidth: shouldUseFullWidth,
|
|
433
309
|
$shouldUseCurrentItemWidth: shouldUseCurrentItemWidth
|
|
434
|
-
}, /*#__PURE__*/
|
|
310
|
+
}, /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxHeader, {
|
|
435
311
|
$direction: direction,
|
|
436
312
|
onClick: handleHeaderClick,
|
|
437
313
|
$isOpen: isAnimating,
|
|
@@ -439,30 +315,47 @@ const ComboBox = ({
|
|
|
439
315
|
$isDisabled: isDisabled,
|
|
440
316
|
$shouldChangeColor: shouldChangeColor,
|
|
441
317
|
$shouldShowBigImage: shouldShowBigImage
|
|
442
|
-
}, /*#__PURE__*/
|
|
318
|
+
}, /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxPrefixAndPlaceholderWrapper, null, prefix && /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxPrefix, null, prefix), /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxPlaceholder, {
|
|
443
319
|
$shouldReduceOpacity: !selectedItem && !internalSelectedItem
|
|
444
|
-
}, placeholderImageUrl && /*#__PURE__*/
|
|
320
|
+
}, placeholderImageUrl && /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxPlaceholderImage, {
|
|
445
321
|
src: placeholderImageUrl,
|
|
446
322
|
$shouldShowBigImage: shouldShowBigImage,
|
|
447
323
|
$shouldShowRoundImage: shouldShowRoundPlaceholderImage
|
|
448
|
-
}), placeholderIcon && /*#__PURE__*/
|
|
324
|
+
}), placeholderIcon && /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
449
325
|
icons: placeholderIcon
|
|
450
|
-
}), typeof inputValue === 'string' ? /*#__PURE__*/
|
|
326
|
+
}), typeof inputValue === 'string' ? /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxInput, {
|
|
451
327
|
disabled: isDisabled,
|
|
452
328
|
value: inputValue,
|
|
453
329
|
onChange: onInputChange,
|
|
454
330
|
onBlur: handleInputBlur,
|
|
455
331
|
onFocus: handleInputFocus,
|
|
456
332
|
placeholder: placeholderText
|
|
457
|
-
}) : /*#__PURE__*/
|
|
333
|
+
}) : /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxPlaceholderText, null, placeholderText), internalSelectedItem && internalSelectedItem.suffixElement && internalSelectedItem.suffixElement)), shouldShowClearIcon && internalSelectedItem && /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxClearIconWrapper, {
|
|
458
334
|
onClick: handleClear
|
|
459
|
-
}, /*#__PURE__*/
|
|
335
|
+
}, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
460
336
|
icons: ['fa fa-times']
|
|
461
|
-
})), !shouldDisableActions && /*#__PURE__*/
|
|
337
|
+
})), !shouldDisableActions && /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxIconWrapper, {
|
|
462
338
|
$shouldShowBorderLeft: shouldShowClearIcon === true && internalSelectedItem !== undefined
|
|
463
|
-
}, /*#__PURE__*/
|
|
339
|
+
}, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
464
340
|
icons: ['fa fa-chevron-down']
|
|
465
|
-
}))),
|
|
341
|
+
}))), styledComboBoxElementRef.current && /*#__PURE__*/_react.default.createElement(_DropdownBodyWrapper.default, {
|
|
342
|
+
anchorElement: styledComboBoxElementRef.current,
|
|
343
|
+
bodyWidth: bodyWidth,
|
|
344
|
+
contentHeight: contentHeight,
|
|
345
|
+
onClose: handleClose,
|
|
346
|
+
direction: direction,
|
|
347
|
+
container: container,
|
|
348
|
+
shouldShowDropdown: isAnimating,
|
|
349
|
+
minBodyWidth: bodyWidth ?? bodyMinWidth,
|
|
350
|
+
maxHeight: maxHeight
|
|
351
|
+
}, /*#__PURE__*/_react.default.createElement(_ComboBox.StyledComboBoxBody, {
|
|
352
|
+
$shouldUseCurrentItemWidth: shouldUseCurrentItemWidth,
|
|
353
|
+
$maxHeight: maxHeight,
|
|
354
|
+
$minWidth: bodyWidth ?? bodyMinWidth,
|
|
355
|
+
$browser: browser === null || browser === void 0 ? void 0 : browser.name,
|
|
356
|
+
ref: contentRef,
|
|
357
|
+
tabIndex: 0
|
|
358
|
+
}, comboBoxGroups))), [minWidth, shouldUseFullWidth, shouldUseCurrentItemWidth, direction, handleHeaderClick, isAnimating, isTouch, isDisabled, shouldChangeColor, shouldShowBigImage, prefix, selectedItem, internalSelectedItem, placeholderImageUrl, shouldShowRoundPlaceholderImage, placeholderIcon, inputValue, onInputChange, handleInputBlur, handleInputFocus, placeholderText, shouldShowClearIcon, handleClear, shouldDisableActions, bodyWidth, contentHeight, handleClose, container, bodyMinWidth, maxHeight, browser === null || browser === void 0 ? void 0 : browser.name, comboBoxGroups]);
|
|
466
359
|
};
|
|
467
360
|
ComboBox.displayName = 'ComboBox';
|
|
468
361
|
var _default = exports.default = ComboBox;
|