@synerise/ds-context-selector 1.3.16 → 1.3.17
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/CHANGELOG.md +4 -0
- package/dist/ContextSelector.d.ts +2 -2
- package/dist/ContextSelector.js +112 -179
- package/dist/ContextSelector.styles.d.ts +10 -10
- package/dist/ContextSelector.styles.js +30 -32
- package/dist/ContextSelector.types.d.ts +6 -6
- package/dist/ContextSelector.types.js +5 -2
- package/dist/ContextSelectorDropdown/ContextSelectorDropdown.d.ts +2 -2
- package/dist/ContextSelectorDropdown/ContextSelectorDropdown.js +173 -252
- package/dist/ContextSelectorDropdown/ContextSelectorDropdownItem.d.ts +2 -2
- package/dist/ContextSelectorDropdown/ContextSelectorDropdownItem.js +29 -42
- package/dist/ContextSelectorDropdown/utils.d.ts +1 -1
- package/dist/ContextSelectorDropdown/utils.js +9 -5
- package/dist/constants.js +23 -10
- package/dist/hooks/useTexts.d.ts +1 -1
- package/dist/hooks/useTexts.js +37 -35
- package/dist/index.js +4 -1
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/package.json +18 -17
|
@@ -1,254 +1,229 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useRef, useState, useCallback, useEffect } from "react";
|
|
3
|
+
import { VariableSizeList } from "react-window";
|
|
4
|
+
import { v4 } from "uuid";
|
|
5
|
+
import { theme } from "@synerise/ds-core";
|
|
6
|
+
import Divider from "@synerise/ds-divider";
|
|
7
|
+
import Dropdown from "@synerise/ds-dropdown";
|
|
8
|
+
import Icon, { ArrowRightCircleM, SearchM } from "@synerise/ds-icon";
|
|
9
|
+
import { itemSizes, ListContextProvider } from "@synerise/ds-list-item";
|
|
10
|
+
import Result from "@synerise/ds-result";
|
|
11
|
+
import Scrollbar from "@synerise/ds-scrollbar";
|
|
12
|
+
import Tabs from "@synerise/ds-tabs";
|
|
13
|
+
import { getActiveTabGroup, getGroupName, useSearchResults, focusWithArrowKeys } from "@synerise/ds-utils";
|
|
14
|
+
import { ShowMoreItem, TabsWrapper, Skeleton, ItemsList, Title } from "../ContextSelector.styles.js";
|
|
15
|
+
import { isContextItemsInSubGroup } from "../ContextSelector.types.js";
|
|
16
|
+
import { NO_GROUP_NAME, DROPDOWN_HEIGHT, TABS_HEIGHT, SUBGROUP_HEADER_HEIGHT, SEARCH_HEIGHT } from "../constants.js";
|
|
17
|
+
import ContextSelectorDropdownItem from "./ContextSelectorDropdownItem.js";
|
|
18
|
+
import { isGroup, isListTitle } from "./utils.js";
|
|
19
|
+
const ITEM_SIZE = {
|
|
20
|
+
[itemSizes.LARGE]: 50,
|
|
21
|
+
[itemSizes.DEFAULT]: 32,
|
|
22
|
+
title: 32,
|
|
23
|
+
divider: 16
|
|
24
|
+
};
|
|
21
25
|
function isDivider(element) {
|
|
22
|
-
return element.type ===
|
|
26
|
+
return element.type === "divider";
|
|
23
27
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
overflowX: 'unset',
|
|
49
|
-
overflowY: 'unset'
|
|
28
|
+
const ContextSelectorDropdown = ({
|
|
29
|
+
texts,
|
|
30
|
+
setSelected,
|
|
31
|
+
onSetGroup,
|
|
32
|
+
groups,
|
|
33
|
+
items,
|
|
34
|
+
recentItems,
|
|
35
|
+
setDropdownVisible,
|
|
36
|
+
value,
|
|
37
|
+
visible,
|
|
38
|
+
hideSearchField = false,
|
|
39
|
+
loading,
|
|
40
|
+
menuItemHeight,
|
|
41
|
+
dropdownWrapperStyles,
|
|
42
|
+
onSearch,
|
|
43
|
+
onFetchData,
|
|
44
|
+
hasMoreItems,
|
|
45
|
+
outerHeight = DROPDOWN_HEIGHT,
|
|
46
|
+
popoverDelay,
|
|
47
|
+
maxSearchResultsInGroup = 4
|
|
48
|
+
}) => {
|
|
49
|
+
const listStyle = {
|
|
50
|
+
overflowX: "unset",
|
|
51
|
+
overflowY: "unset"
|
|
50
52
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return group.defaultGroup;
|
|
54
|
-
});
|
|
53
|
+
const defaultTab = useMemo(() => {
|
|
54
|
+
const defaultIndex = groups?.findIndex((group) => group.defaultGroup);
|
|
55
55
|
return defaultIndex || 0;
|
|
56
56
|
}, [groups]);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
activeTab = _useState3[0],
|
|
68
|
-
setActiveTab = _useState3[1];
|
|
69
|
-
var _useState4 = useState(undefined),
|
|
70
|
-
activeGroup = _useState4[0],
|
|
71
|
-
setActiveGroup = _useState4[1];
|
|
72
|
-
var _useState5 = useState(true),
|
|
73
|
-
searchInputCanBeFocused = _useState5[0],
|
|
74
|
-
setSearchInputFocus = _useState5[1];
|
|
75
|
-
var classNames = useMemo(function () {
|
|
76
|
-
return "ds-context-item ds-context-item-" + uuid();
|
|
57
|
+
const listRef = useRef(null);
|
|
58
|
+
const overlayRef = useRef(null);
|
|
59
|
+
const scrollBarRef = useRef(null);
|
|
60
|
+
const [searchInputHandle, setSearchInputHandle] = useState();
|
|
61
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
62
|
+
const [activeTab, setActiveTab] = useState(defaultTab);
|
|
63
|
+
const [activeGroup, setActiveGroup] = useState(void 0);
|
|
64
|
+
const [searchInputCanBeFocused, setSearchInputFocus] = useState(true);
|
|
65
|
+
const classNames = useMemo(() => {
|
|
66
|
+
return `ds-context-item ds-context-item-${v4()}`;
|
|
77
67
|
}, []);
|
|
78
|
-
|
|
68
|
+
const resetList = useCallback(() => {
|
|
79
69
|
if (listRef.current) {
|
|
80
70
|
listRef.current.resetAfterIndex(0, false);
|
|
81
71
|
}
|
|
82
72
|
}, [listRef]);
|
|
83
|
-
|
|
73
|
+
const handleOnSetGroup = useCallback((item) => {
|
|
84
74
|
if (isGroup(item)) {
|
|
85
75
|
onSetGroup && onSetGroup(item);
|
|
86
76
|
setActiveGroup(item);
|
|
87
77
|
resetList();
|
|
88
78
|
}
|
|
89
79
|
}, [onSetGroup, setActiveGroup, resetList]);
|
|
90
|
-
|
|
91
|
-
setSearchQuery(
|
|
80
|
+
const clearSearch = useCallback(() => {
|
|
81
|
+
setSearchQuery("");
|
|
92
82
|
resetList();
|
|
93
83
|
}, [setSearchQuery, resetList]);
|
|
94
|
-
|
|
84
|
+
const hideDropdown = useCallback(() => {
|
|
95
85
|
setDropdownVisible(false);
|
|
96
86
|
}, [setDropdownVisible]);
|
|
97
|
-
|
|
87
|
+
const handleSelect = useCallback((parameter) => {
|
|
98
88
|
setSelected(parameter);
|
|
99
|
-
setActiveGroup(
|
|
89
|
+
setActiveGroup(void 0);
|
|
100
90
|
setActiveTab(defaultTab);
|
|
101
91
|
}, [defaultTab, setSelected]);
|
|
102
|
-
|
|
103
|
-
return groups ? getActiveTabGroup(activeTab, groups) :
|
|
92
|
+
const currentTabItems = useMemo(() => {
|
|
93
|
+
return groups ? getActiveTabGroup(activeTab, groups) : void 0;
|
|
104
94
|
}, [groups, activeTab]);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var group = groupedItems[groupName] || [];
|
|
95
|
+
const groupByGroupName = useCallback((dropdownItems, maxItemsInGroup) => {
|
|
96
|
+
const itemsNumber = dropdownItems?.length;
|
|
97
|
+
const groupedItems = {};
|
|
98
|
+
for (let i = 0; i < itemsNumber; i += 1) {
|
|
99
|
+
const item = dropdownItems[i];
|
|
100
|
+
const groupName = item.groupName || NO_GROUP_NAME;
|
|
101
|
+
const group = groupedItems[groupName] || [];
|
|
113
102
|
group.push(item);
|
|
114
103
|
groupedItems[groupName] = group;
|
|
115
104
|
}
|
|
116
|
-
|
|
117
|
-
Object.keys(groupedItems).forEach(
|
|
105
|
+
const resultItems = [];
|
|
106
|
+
Object.keys(groupedItems).forEach((key, index) => {
|
|
118
107
|
if (index > 0) {
|
|
119
108
|
resultItems.push({
|
|
120
|
-
type:
|
|
109
|
+
type: "divider"
|
|
121
110
|
});
|
|
122
111
|
}
|
|
123
112
|
if (key !== NO_GROUP_NAME && !activeGroup) {
|
|
124
113
|
resultItems.push({
|
|
125
|
-
type:
|
|
114
|
+
type: "title",
|
|
126
115
|
title: key
|
|
127
116
|
});
|
|
128
117
|
}
|
|
129
|
-
|
|
130
|
-
groupItems.forEach(
|
|
131
|
-
|
|
118
|
+
const groupItems = maxItemsInGroup ? groupedItems[key].slice(0, maxItemsInGroup) : groupedItems[key];
|
|
119
|
+
groupItems.forEach((item) => {
|
|
120
|
+
const resultItem = isContextItemsInSubGroup(item) ? {
|
|
132
121
|
className: classNames,
|
|
133
|
-
item
|
|
134
|
-
searchQuery
|
|
122
|
+
item,
|
|
123
|
+
searchQuery,
|
|
135
124
|
select: handleOnSetGroup,
|
|
136
|
-
menuItemHeight
|
|
125
|
+
menuItemHeight
|
|
137
126
|
} : {
|
|
138
127
|
className: classNames,
|
|
139
|
-
item
|
|
140
|
-
searchQuery
|
|
141
|
-
clearSearch
|
|
142
|
-
hideDropdown
|
|
128
|
+
item,
|
|
129
|
+
searchQuery,
|
|
130
|
+
clearSearch,
|
|
131
|
+
hideDropdown,
|
|
143
132
|
select: handleSelect,
|
|
144
|
-
selected: Boolean(value) && item.id ===
|
|
145
|
-
menuItemHeight
|
|
133
|
+
selected: Boolean(value) && item.id === value?.id,
|
|
134
|
+
menuItemHeight
|
|
146
135
|
};
|
|
147
136
|
resultItems.push(resultItem);
|
|
148
137
|
});
|
|
149
138
|
if (maxItemsInGroup && groupedItems[key].length > maxItemsInGroup) {
|
|
150
|
-
|
|
139
|
+
const anyItem = groupItems[0];
|
|
151
140
|
resultItems.push({
|
|
152
141
|
className: classNames,
|
|
153
142
|
select: handleOnSetGroup,
|
|
154
|
-
menuItemHeight
|
|
155
|
-
label:
|
|
143
|
+
menuItemHeight,
|
|
144
|
+
label: /* @__PURE__ */ jsx(ShowMoreItem, { children: texts.showMore }),
|
|
156
145
|
item: {
|
|
157
146
|
isGroup: true,
|
|
158
147
|
id: anyItem.groupId,
|
|
159
|
-
name: getGroupName(anyItem.groupId, groups) ||
|
|
160
|
-
icon:
|
|
148
|
+
name: getGroupName(anyItem.groupId, groups) || "",
|
|
149
|
+
icon: /* @__PURE__ */ jsx(ArrowRightCircleM, {})
|
|
161
150
|
}
|
|
162
151
|
});
|
|
163
152
|
}
|
|
164
153
|
});
|
|
165
154
|
return resultItems;
|
|
166
155
|
}, [activeGroup, classNames, searchQuery, handleOnSetGroup, menuItemHeight, clearSearch, hideDropdown, handleSelect, value, texts.showMore, groups]);
|
|
167
|
-
|
|
168
|
-
searchResults
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var activeItems = useMemo(function () {
|
|
156
|
+
const {
|
|
157
|
+
searchResults
|
|
158
|
+
} = useSearchResults(items, groups, activeTab, groupByGroupName, activeGroup, searchQuery, maxSearchResultsInGroup);
|
|
159
|
+
const hasSubgroups = useMemo(() => Boolean(currentTabItems?.subGroups), [currentTabItems]);
|
|
160
|
+
const activeItems = useMemo(() => {
|
|
173
161
|
if (!onSearch && searchQuery) {
|
|
174
162
|
return searchResults;
|
|
175
163
|
}
|
|
176
164
|
if (hasSubgroups && !activeGroup) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
prev.push(_extends({}, curr, {
|
|
165
|
+
const subGroups = hasSubgroups ? currentTabItems?.subGroups?.map((group) => ({
|
|
166
|
+
...group,
|
|
167
|
+
isGroup: true
|
|
168
|
+
})) : [];
|
|
169
|
+
const subItems = items?.reduce((prev, curr) => {
|
|
170
|
+
if (curr.groupId === currentTabItems?.id) {
|
|
171
|
+
prev.push({
|
|
172
|
+
...curr,
|
|
186
173
|
isGroup: false
|
|
187
|
-
})
|
|
174
|
+
});
|
|
188
175
|
}
|
|
189
176
|
return prev;
|
|
190
177
|
}, []);
|
|
191
|
-
return groupByGroupName([
|
|
178
|
+
return groupByGroupName([...subGroups || [], ...subItems]);
|
|
192
179
|
}
|
|
193
180
|
if (activeGroup) {
|
|
194
|
-
return groupByGroupName(items
|
|
195
|
-
return activeGroup && item.groupId === activeGroup.id;
|
|
196
|
-
}));
|
|
181
|
+
return groupByGroupName(items?.filter((item) => activeGroup && item.groupId === activeGroup.id));
|
|
197
182
|
}
|
|
198
183
|
if (activeTab && groups && groups[activeTab]) {
|
|
199
|
-
return groupByGroupName(items
|
|
200
|
-
return item.groupId === groups[activeTab].id;
|
|
201
|
-
}));
|
|
184
|
+
return groupByGroupName(items?.filter((item) => item.groupId === groups[activeTab].id));
|
|
202
185
|
}
|
|
203
186
|
if ((recentItems || []).length > 0) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
});
|
|
214
|
-
var result = groupByGroupName(recentItemsWithGroup.concat(itemsWithAllGroup));
|
|
187
|
+
const recentItemsWithGroup = (recentItems || []).map((item) => ({
|
|
188
|
+
...item,
|
|
189
|
+
groupName: texts.recentItemsGroupName
|
|
190
|
+
}));
|
|
191
|
+
const itemsWithAllGroup = (items || []).map((item) => ({
|
|
192
|
+
...item,
|
|
193
|
+
groupName: texts.allItemsGroupName
|
|
194
|
+
}));
|
|
195
|
+
const result = groupByGroupName(recentItemsWithGroup.concat(itemsWithAllGroup));
|
|
215
196
|
return result;
|
|
216
197
|
}
|
|
217
198
|
return groupByGroupName(items);
|
|
218
|
-
}, [onSearch, searchQuery, hasSubgroups, activeGroup, activeTab, groups, groupByGroupName, items, searchResults, currentTabItems
|
|
219
|
-
useEffect(
|
|
220
|
-
|
|
221
|
-
(_listRef$current = listRef.current) == null || _listRef$current.resetAfterIndex(0, false);
|
|
199
|
+
}, [onSearch, searchQuery, hasSubgroups, activeGroup, activeTab, groups, groupByGroupName, items, searchResults, currentTabItems?.subGroups, currentTabItems?.id, recentItems, texts.recentItemsGroupName, texts.allItemsGroupName]);
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
listRef.current?.resetAfterIndex(0, false);
|
|
222
202
|
}, [activeItems, listRef]);
|
|
223
|
-
|
|
203
|
+
const handleSearch = useCallback((val) => {
|
|
224
204
|
setSearchQuery(val);
|
|
225
205
|
resetList();
|
|
226
206
|
onSearch && onSearch(val);
|
|
227
207
|
}, [setSearchQuery, resetList, onSearch]);
|
|
228
|
-
|
|
229
|
-
return
|
|
230
|
-
|
|
231
|
-
label: group.name
|
|
232
|
-
};
|
|
208
|
+
const getTabs = useMemo(() => {
|
|
209
|
+
return groups?.map((group) => ({
|
|
210
|
+
label: group.name
|
|
233
211
|
})) || [];
|
|
234
212
|
}, [groups]);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
var handleScroll = function handleScroll(_ref2) {
|
|
244
|
-
var currentTarget = _ref2.currentTarget;
|
|
245
|
-
var scrollTop = currentTarget.scrollTop;
|
|
213
|
+
const hasTabs = getTabs.length > 1;
|
|
214
|
+
const getNoResultContainer = useMemo(() => /* @__PURE__ */ jsx(Result, { noSearchResults: true, type: "no-results", description: texts.noResults }), [texts]);
|
|
215
|
+
const handleScroll = ({
|
|
216
|
+
currentTarget
|
|
217
|
+
}) => {
|
|
218
|
+
const {
|
|
219
|
+
scrollTop
|
|
220
|
+
} = currentTarget;
|
|
246
221
|
if (listRef.current !== null) {
|
|
247
222
|
listRef.current.scrollTo(scrollTop);
|
|
248
223
|
}
|
|
249
224
|
};
|
|
250
|
-
|
|
251
|
-
|
|
225
|
+
const getItemSize = (index) => {
|
|
226
|
+
const item = activeItems[index];
|
|
252
227
|
if (isListTitle(item)) {
|
|
253
228
|
return ITEM_SIZE.title;
|
|
254
229
|
}
|
|
@@ -257,10 +232,10 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
257
232
|
}
|
|
258
233
|
return menuItemHeight ? ITEM_SIZE[menuItemHeight] : ITEM_SIZE[itemSizes.DEFAULT];
|
|
259
234
|
};
|
|
260
|
-
|
|
235
|
+
const dropdownContentHeight = useMemo(() => {
|
|
261
236
|
return outerHeight - (hasTabs && !searchQuery ? TABS_HEIGHT : 0) - (activeGroup ? SUBGROUP_HEADER_HEIGHT : 0) - SEARCH_HEIGHT;
|
|
262
237
|
}, [activeGroup, hasTabs, outerHeight, searchQuery]);
|
|
263
|
-
useEffect(
|
|
238
|
+
useEffect(() => {
|
|
264
239
|
if (scrollBarRef.current && listRef.current) {
|
|
265
240
|
scrollBarRef.current.scrollTo({
|
|
266
241
|
top: 0
|
|
@@ -268,93 +243,39 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
268
243
|
listRef.current.resetAfterIndex(0);
|
|
269
244
|
}
|
|
270
245
|
}, [searchQuery, activeGroup, activeTab]);
|
|
271
|
-
return
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
onKeyDown: function onKeyDown(event) {
|
|
275
|
-
var _document;
|
|
276
|
-
if (((_document = document) == null ? void 0 : _document.activeElement) === (searchInputHandle == null ? void 0 : searchInputHandle.current)) {
|
|
277
|
-
setSearchInputFocus(false);
|
|
278
|
-
}
|
|
279
|
-
searchQuery && focusWithArrowKeys(event, classNames.split(' ')[1], function () {
|
|
280
|
-
setSearchInputFocus(true);
|
|
281
|
-
});
|
|
246
|
+
return /* @__PURE__ */ jsxs(Dropdown.Wrapper, { style: dropdownWrapperStyles, ref: overlayRef, onKeyDown: (event) => {
|
|
247
|
+
if (document?.activeElement === searchInputHandle?.current) {
|
|
248
|
+
setSearchInputFocus(false);
|
|
282
249
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
250
|
+
searchQuery && focusWithArrowKeys(event, classNames.split(" ")[1], () => {
|
|
251
|
+
setSearchInputFocus(true);
|
|
252
|
+
});
|
|
253
|
+
}, children: [
|
|
254
|
+
!hideSearchField && /* @__PURE__ */ jsx(Dropdown.SearchInput, { onSearchChange: handleSearch, onClearInput: () => {
|
|
255
|
+
handleSearch("");
|
|
256
|
+
onSearch && onSearch("");
|
|
288
257
|
resetList();
|
|
289
|
-
},
|
|
290
|
-
|
|
291
|
-
value: searchQuery,
|
|
292
|
-
autofocus: !searchQuery || searchInputCanBeFocused,
|
|
293
|
-
autofocusDelay: 50,
|
|
294
|
-
handleInputRef: setSearchInputHandle,
|
|
295
|
-
iconLeft: /*#__PURE__*/React.createElement(Icon, {
|
|
296
|
-
component: /*#__PURE__*/React.createElement(SearchM, null),
|
|
297
|
-
color: theme.palette['grey-600']
|
|
298
|
-
})
|
|
299
|
-
}), hasTabs && /*#__PURE__*/React.createElement(S.TabsWrapper, null, /*#__PURE__*/React.createElement(Tabs, {
|
|
300
|
-
block: true,
|
|
301
|
-
tabs: getTabs,
|
|
302
|
-
activeTab: activeTab,
|
|
303
|
-
handleTabClick: function handleTabClick(index) {
|
|
258
|
+
}, placeholder: texts.searchPlaceholder, value: searchQuery, autofocus: !searchQuery || searchInputCanBeFocused, autofocusDelay: 50, handleInputRef: setSearchInputHandle, iconLeft: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(SearchM, {}), color: theme.palette["grey-600"] }) }),
|
|
259
|
+
hasTabs && /* @__PURE__ */ jsx(TabsWrapper, { children: /* @__PURE__ */ jsx(Tabs, { block: true, tabs: getTabs, activeTab, handleTabClick: (index) => {
|
|
304
260
|
setActiveTab(index);
|
|
305
|
-
setActiveGroup(
|
|
261
|
+
setActiveGroup(void 0);
|
|
306
262
|
resetList();
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
label: activeGroup.name,
|
|
311
|
-
onClick: function onClick() {
|
|
312
|
-
return setActiveGroup(undefined);
|
|
313
|
-
}
|
|
314
|
-
}), loading ? /*#__PURE__*/React.createElement(S.Skeleton, {
|
|
315
|
-
contentHeight: dropdownContentHeight,
|
|
316
|
-
size: "M",
|
|
317
|
-
numberOfSkeletons: 3
|
|
318
|
-
}) : /*#__PURE__*/React.createElement(S.ItemsList, {
|
|
319
|
-
contentHeight: dropdownContentHeight
|
|
320
|
-
}, activeItems != null && activeItems.length ? /*#__PURE__*/React.createElement(Scrollbar, {
|
|
321
|
-
absolute: true,
|
|
322
|
-
style: {
|
|
263
|
+
}, visible }) }),
|
|
264
|
+
activeGroup && /* @__PURE__ */ jsx(Dropdown.BackAction, { label: activeGroup.name, onClick: () => setActiveGroup(void 0) }),
|
|
265
|
+
loading ? /* @__PURE__ */ jsx(Skeleton, { contentHeight: dropdownContentHeight, size: "M", numberOfSkeletons: 3 }) : /* @__PURE__ */ jsx(ItemsList, { contentHeight: dropdownContentHeight, children: activeItems?.length ? /* @__PURE__ */ jsx(Scrollbar, { absolute: true, style: {
|
|
323
266
|
padding: 8
|
|
324
|
-
},
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
itemSize: getItemSize,
|
|
339
|
-
style: listStyle,
|
|
340
|
-
ref: listRef
|
|
341
|
-
}, function (_ref3) {
|
|
342
|
-
var index = _ref3.index,
|
|
343
|
-
style = _ref3.style;
|
|
344
|
-
var item = activeItems[index];
|
|
345
|
-
if (item && isDivider(item)) {
|
|
346
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
347
|
-
style: style
|
|
348
|
-
}, /*#__PURE__*/React.createElement(Divider, {
|
|
349
|
-
marginTop: 8,
|
|
350
|
-
marginBottom: 8
|
|
351
|
-
}));
|
|
352
|
-
}
|
|
353
|
-
return item && isListTitle(item) ? /*#__PURE__*/React.createElement(S.Title, {
|
|
354
|
-
style: style
|
|
355
|
-
}, item.title) : /*#__PURE__*/React.createElement(ContextSelectorDropdownItem, _extends({
|
|
356
|
-
style: style
|
|
357
|
-
}, item));
|
|
358
|
-
}))) : getNoResultContainer));
|
|
267
|
+
}, loading, hasMore: hasMoreItems, onYReachEnd: onFetchData, onScroll: handleScroll, ref: scrollBarRef, children: /* @__PURE__ */ jsx(ListContextProvider, { popoverDelay, children: /* @__PURE__ */ jsx(VariableSizeList, { className: "ds-context-selector-list", width: "100%", height: 300, itemCount: activeItems.length, itemSize: getItemSize, style: listStyle, ref: listRef, children: ({
|
|
268
|
+
index,
|
|
269
|
+
style
|
|
270
|
+
}) => {
|
|
271
|
+
const item = activeItems[index];
|
|
272
|
+
if (item && isDivider(item)) {
|
|
273
|
+
return /* @__PURE__ */ jsx("div", { style, children: /* @__PURE__ */ jsx(Divider, { marginTop: 8, marginBottom: 8 }) });
|
|
274
|
+
}
|
|
275
|
+
return item && isListTitle(item) ? /* @__PURE__ */ jsx(Title, { style, children: item.title }) : /* @__PURE__ */ jsx(ContextSelectorDropdownItem, { style, ...item });
|
|
276
|
+
} }, `list-${activeGroup}-${activeTab}`) }) }) : getNoResultContainer })
|
|
277
|
+
] });
|
|
278
|
+
};
|
|
279
|
+
export {
|
|
280
|
+
ContextSelectorDropdown as default
|
|
359
281
|
};
|
|
360
|
-
export default ContextSelectorDropdown;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ContextSelectorDropdownItemProps } from '../ContextSelector.types';
|
|
3
3
|
declare const ContextSelectorDropdownItem: ({ item, clearSearch, searchQuery, hideDropdown, select, selected, className, menuItemHeight, style, label, }: ContextSelectorDropdownItemProps) => React.JSX.Element;
|
|
4
4
|
export default ContextSelectorDropdownItem;
|
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
suffixel: item != null && item.customSuffix ? item.customSuffix : selected && /*#__PURE__*/React.createElement(Icon, {
|
|
31
|
-
component: /*#__PURE__*/React.createElement(CheckS, null),
|
|
32
|
-
color: theme.palette['green-600']
|
|
33
|
-
}),
|
|
34
|
-
onClick: function onClick() {
|
|
35
|
-
clearSearch && clearSearch();
|
|
36
|
-
hideDropdown && hideDropdown();
|
|
37
|
-
select && select(item);
|
|
38
|
-
},
|
|
39
|
-
size: menuItemHeight,
|
|
40
|
-
description: item.description
|
|
41
|
-
}, itemProps), label || item.name);
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { theme } from "@synerise/ds-core";
|
|
3
|
+
import Icon, { CheckS } from "@synerise/ds-icon";
|
|
4
|
+
import ListItem from "@synerise/ds-list-item";
|
|
5
|
+
const ContextSelectorDropdownItem = ({
|
|
6
|
+
item,
|
|
7
|
+
clearSearch,
|
|
8
|
+
searchQuery,
|
|
9
|
+
hideDropdown,
|
|
10
|
+
select,
|
|
11
|
+
selected,
|
|
12
|
+
className,
|
|
13
|
+
menuItemHeight,
|
|
14
|
+
style,
|
|
15
|
+
label
|
|
16
|
+
}) => {
|
|
17
|
+
const {
|
|
18
|
+
id,
|
|
19
|
+
icon: _,
|
|
20
|
+
...itemProps
|
|
21
|
+
} = item;
|
|
22
|
+
return /* @__PURE__ */ jsx(ListItem, { style, className, prefixel: item.useCustomIcon ? item.icon : /* @__PURE__ */ jsx(Icon, { component: item.icon }), highlight: searchQuery, suffixel: item?.customSuffix ? item.customSuffix : selected && /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(CheckS, {}), color: theme.palette["green-600"] }), onClick: () => {
|
|
23
|
+
clearSearch && clearSearch();
|
|
24
|
+
hideDropdown && hideDropdown();
|
|
25
|
+
select && select(item);
|
|
26
|
+
}, size: menuItemHeight, description: item.description, ...itemProps, children: label || item.name }, item.name + item.id);
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
ContextSelectorDropdownItem as default
|
|
42
30
|
};
|
|
43
|
-
export default ContextSelectorDropdownItem;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ContextGroup, ContextItem, DropdownItemProps, ListTitle } from '../ContextSelector.types';
|
|
2
2
|
export declare const isListTitle: (element: DropdownItemProps) => element is ListTitle;
|
|
3
3
|
export declare const isGroup: (item: ContextItem | ContextGroup) => item is ContextGroup;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
return element.title !==
|
|
1
|
+
const isListTitle = (element) => {
|
|
2
|
+
return element.title !== void 0;
|
|
3
|
+
};
|
|
4
|
+
const isGroup = (item) => {
|
|
5
|
+
return "isGroup" in item;
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
isGroup,
|
|
9
|
+
isListTitle
|
|
3
10
|
};
|
|
4
|
-
export var isGroup = function isGroup(item) {
|
|
5
|
-
return 'isGroup' in item;
|
|
6
|
-
};
|