@synerise/ds-context-selector 1.3.16 → 1.3.18

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.
@@ -1,254 +1,229 @@
1
- var _ITEM_SIZE;
2
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
- import { VariableSizeList } from 'react-window';
5
- import { v4 as uuid } from 'uuid';
6
- import { theme } from '@synerise/ds-core';
7
- import Divider from '@synerise/ds-divider';
8
- import Dropdown from '@synerise/ds-dropdown';
9
- import Icon, { ArrowRightCircleM, SearchM } from '@synerise/ds-icon';
10
- import { ListContextProvider, itemSizes } from '@synerise/ds-list-item';
11
- import Result from '@synerise/ds-result';
12
- import Scrollbar from '@synerise/ds-scrollbar';
13
- import Tabs from '@synerise/ds-tabs';
14
- import { focusWithArrowKeys, getActiveTabGroup, getGroupName, useSearchResults } from '@synerise/ds-utils';
15
- import * as S from '../ContextSelector.styles';
16
- import { isContextItemsInSubGroup } from '../ContextSelector.types';
17
- import { DROPDOWN_HEIGHT, NO_GROUP_NAME, SEARCH_HEIGHT, SUBGROUP_HEADER_HEIGHT, TABS_HEIGHT } from '../constants';
18
- import ContextSelectorDropdownItem from './ContextSelectorDropdownItem';
19
- import { isGroup, isListTitle } from './utils';
20
- var ITEM_SIZE = (_ITEM_SIZE = {}, _ITEM_SIZE[itemSizes.LARGE] = 50, _ITEM_SIZE[itemSizes.DEFAULT] = 32, _ITEM_SIZE.title = 32, _ITEM_SIZE.divider = 16, _ITEM_SIZE);
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 === 'divider';
26
+ return element.type === "divider";
23
27
  }
24
- var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
25
- var texts = _ref.texts,
26
- setSelected = _ref.setSelected,
27
- onSetGroup = _ref.onSetGroup,
28
- groups = _ref.groups,
29
- items = _ref.items,
30
- recentItems = _ref.recentItems,
31
- setDropdownVisible = _ref.setDropdownVisible,
32
- value = _ref.value,
33
- visible = _ref.visible,
34
- _ref$hideSearchField = _ref.hideSearchField,
35
- hideSearchField = _ref$hideSearchField === void 0 ? false : _ref$hideSearchField,
36
- loading = _ref.loading,
37
- menuItemHeight = _ref.menuItemHeight,
38
- dropdownWrapperStyles = _ref.dropdownWrapperStyles,
39
- onSearch = _ref.onSearch,
40
- onFetchData = _ref.onFetchData,
41
- hasMoreItems = _ref.hasMoreItems,
42
- _ref$outerHeight = _ref.outerHeight,
43
- outerHeight = _ref$outerHeight === void 0 ? DROPDOWN_HEIGHT : _ref$outerHeight,
44
- popoverDelay = _ref.popoverDelay,
45
- _ref$maxSearchResults = _ref.maxSearchResultsInGroup,
46
- maxSearchResultsInGroup = _ref$maxSearchResults === void 0 ? 4 : _ref$maxSearchResults;
47
- var listStyle = {
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
- var defaultTab = useMemo(function () {
52
- var defaultIndex = groups == null ? void 0 : groups.findIndex(function (group) {
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
- var listRef = useRef(null);
58
- var overlayRef = useRef(null);
59
- var scrollBarRef = useRef(null);
60
- var _useState = useState(),
61
- searchInputHandle = _useState[0],
62
- setSearchInputHandle = _useState[1];
63
- var _useState2 = useState(''),
64
- searchQuery = _useState2[0],
65
- setSearchQuery = _useState2[1];
66
- var _useState3 = useState(defaultTab),
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
- var resetList = useCallback(function () {
68
+ const resetList = useCallback(() => {
79
69
  if (listRef.current) {
80
70
  listRef.current.resetAfterIndex(0, false);
81
71
  }
82
72
  }, [listRef]);
83
- var handleOnSetGroup = useCallback(function (item) {
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
- var clearSearch = useCallback(function () {
91
- setSearchQuery('');
80
+ const clearSearch = useCallback(() => {
81
+ setSearchQuery("");
92
82
  resetList();
93
83
  }, [setSearchQuery, resetList]);
94
- var hideDropdown = useCallback(function () {
84
+ const hideDropdown = useCallback(() => {
95
85
  setDropdownVisible(false);
96
86
  }, [setDropdownVisible]);
97
- var handleSelect = useCallback(function (parameter) {
87
+ const handleSelect = useCallback((parameter) => {
98
88
  setSelected(parameter);
99
- setActiveGroup(undefined);
89
+ setActiveGroup(void 0);
100
90
  setActiveTab(defaultTab);
101
91
  }, [defaultTab, setSelected]);
102
- var currentTabItems = useMemo(function () {
103
- return groups ? getActiveTabGroup(activeTab, groups) : undefined;
92
+ const currentTabItems = useMemo(() => {
93
+ return groups ? getActiveTabGroup(activeTab, groups) : void 0;
104
94
  }, [groups, activeTab]);
105
- var groupByGroupName = useCallback(function (dropdownItems, maxItemsInGroup) {
106
- var itemsNumber = dropdownItems == null ? void 0 : dropdownItems.length;
107
- var groupedItems = {};
108
- for (var i = 0; i < itemsNumber; i += 1) {
109
- var item = dropdownItems[i];
110
- // @ts-expect-error Property 'groupName' does not exist on type 'ContextGroup
111
- var groupName = item.groupName || NO_GROUP_NAME;
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
- var resultItems = [];
117
- Object.keys(groupedItems).forEach(function (key, index) {
105
+ const resultItems = [];
106
+ Object.keys(groupedItems).forEach((key, index) => {
118
107
  if (index > 0) {
119
108
  resultItems.push({
120
- type: 'divider'
109
+ type: "divider"
121
110
  });
122
111
  }
123
112
  if (key !== NO_GROUP_NAME && !activeGroup) {
124
113
  resultItems.push({
125
- type: 'title',
114
+ type: "title",
126
115
  title: key
127
116
  });
128
117
  }
129
- var groupItems = maxItemsInGroup ? groupedItems[key].slice(0, maxItemsInGroup) : groupedItems[key];
130
- groupItems.forEach(function (item) {
131
- var resultItem = isContextItemsInSubGroup(item) ? {
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: item,
134
- searchQuery: searchQuery,
122
+ item,
123
+ searchQuery,
135
124
  select: handleOnSetGroup,
136
- menuItemHeight: menuItemHeight
125
+ menuItemHeight
137
126
  } : {
138
127
  className: classNames,
139
- item: item,
140
- searchQuery: searchQuery,
141
- clearSearch: clearSearch,
142
- hideDropdown: hideDropdown,
128
+ item,
129
+ searchQuery,
130
+ clearSearch,
131
+ hideDropdown,
143
132
  select: handleSelect,
144
- selected: Boolean(value) && item.id === (value == null ? void 0 : value.id),
145
- menuItemHeight: 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
- var anyItem = groupItems[0];
139
+ const anyItem = groupItems[0];
151
140
  resultItems.push({
152
141
  className: classNames,
153
142
  select: handleOnSetGroup,
154
- menuItemHeight: menuItemHeight,
155
- label: /*#__PURE__*/React.createElement(S.ShowMoreItem, null, texts.showMore),
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: /*#__PURE__*/React.createElement(ArrowRightCircleM, null)
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
- var _useSearchResults = useSearchResults(items, groups, activeTab, groupByGroupName, activeGroup, searchQuery, maxSearchResultsInGroup),
168
- searchResults = _useSearchResults.searchResults;
169
- var hasSubgroups = useMemo(function () {
170
- return Boolean(currentTabItems == null ? void 0 : currentTabItems.subGroups);
171
- }, [currentTabItems]);
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
- var _currentTabItems$subG;
178
- var subGroups = hasSubgroups ? currentTabItems == null || (_currentTabItems$subG = currentTabItems.subGroups) == null ? void 0 : _currentTabItems$subG.map(function (group) {
179
- return _extends({}, group, {
180
- isGroup: true
181
- });
182
- }) : [];
183
- var subItems = items == null ? void 0 : items.reduce(function (prev, curr) {
184
- if (curr.groupId === (currentTabItems == null ? void 0 : currentTabItems.id)) {
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([].concat(subGroups || [], subItems));
178
+ return groupByGroupName([...subGroups || [], ...subItems]);
192
179
  }
193
180
  if (activeGroup) {
194
- return groupByGroupName(items == null ? void 0 : items.filter(function (item) {
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 == null ? void 0 : items.filter(function (item) {
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
- var recentItemsWithGroup = (recentItems || []).map(function (item) {
205
- return _extends({}, item, {
206
- groupName: texts.recentItemsGroupName
207
- });
208
- });
209
- var itemsWithAllGroup = (items || []).map(function (item) {
210
- return _extends({}, item, {
211
- groupName: texts.allItemsGroupName
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 == null ? void 0 : currentTabItems.subGroups, currentTabItems == null ? void 0 : currentTabItems.id, recentItems, texts.recentItemsGroupName, texts.allItemsGroupName]);
219
- useEffect(function () {
220
- var _listRef$current;
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
- var handleSearch = useCallback(function (val) {
203
+ const handleSearch = useCallback((val) => {
224
204
  setSearchQuery(val);
225
205
  resetList();
226
206
  onSearch && onSearch(val);
227
207
  }, [setSearchQuery, resetList, onSearch]);
228
- var getTabs = useMemo(function () {
229
- return (groups == null ? void 0 : groups.map(function (group) {
230
- return {
231
- label: group.name
232
- };
208
+ const getTabs = useMemo(() => {
209
+ return groups?.map((group) => ({
210
+ label: group.name
233
211
  })) || [];
234
212
  }, [groups]);
235
- var hasTabs = getTabs.length > 1;
236
- var getNoResultContainer = useMemo(function () {
237
- return /*#__PURE__*/React.createElement(Result, {
238
- noSearchResults: true,
239
- type: "no-results",
240
- description: texts.noResults
241
- });
242
- }, [texts]);
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
- var getItemSize = function getItemSize(index) {
251
- var item = activeItems[index];
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
- var dropdownContentHeight = useMemo(function () {
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(function () {
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 /*#__PURE__*/React.createElement(Dropdown.Wrapper, {
272
- style: dropdownWrapperStyles,
273
- ref: overlayRef,
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
- }, !hideSearchField && /*#__PURE__*/React.createElement(Dropdown.SearchInput, {
284
- onSearchChange: handleSearch,
285
- onClearInput: function onClearInput() {
286
- handleSearch('');
287
- onSearch && onSearch('');
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
- placeholder: texts.searchPlaceholder,
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(undefined);
261
+ setActiveGroup(void 0);
306
262
  resetList();
307
- },
308
- visible: visible
309
- })), activeGroup && /*#__PURE__*/React.createElement(Dropdown.BackAction, {
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
- loading: loading,
326
- hasMore: hasMoreItems,
327
- onYReachEnd: onFetchData,
328
- onScroll: handleScroll,
329
- ref: scrollBarRef
330
- }, /*#__PURE__*/React.createElement(ListContextProvider, {
331
- popoverDelay: popoverDelay
332
- }, /*#__PURE__*/React.createElement(VariableSizeList, {
333
- className: "ds-context-selector-list",
334
- key: "list-" + activeGroup + "-" + activeTab,
335
- width: "100%",
336
- height: 300,
337
- itemCount: activeItems.length,
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 { type ContextSelectorDropdownItemProps } from '../ContextSelector.types';
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
- var _excluded = ["id", "icon"];
2
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
- import React from 'react';
5
- import { theme } from '@synerise/ds-core';
6
- import Icon, { CheckS } from '@synerise/ds-icon';
7
- import ListItem from '@synerise/ds-list-item';
8
- var ContextSelectorDropdownItem = function ContextSelectorDropdownItem(_ref) {
9
- var item = _ref.item,
10
- clearSearch = _ref.clearSearch,
11
- searchQuery = _ref.searchQuery,
12
- hideDropdown = _ref.hideDropdown,
13
- select = _ref.select,
14
- selected = _ref.selected,
15
- className = _ref.className,
16
- menuItemHeight = _ref.menuItemHeight,
17
- style = _ref.style,
18
- label = _ref.label;
19
- var id = item.id,
20
- _ = item.icon,
21
- itemProps = _objectWithoutPropertiesLoose(item, _excluded);
22
- return /*#__PURE__*/React.createElement(ListItem, _extends({
23
- style: style,
24
- className: className,
25
- key: item.name + item.id,
26
- prefixel: item.useCustomIcon ? item.icon : /*#__PURE__*/React.createElement(Icon, {
27
- component: item.icon
28
- }),
29
- highlight: searchQuery,
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 type { ContextGroup, ContextItem, DropdownItemProps, ListTitle } from '../ContextSelector.types';
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
- export var isListTitle = function isListTitle(element) {
2
- return element.title !== undefined;
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
- };