@synerise/ds-context-selector 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +19 -15
- package/dist/ContextSelector.js +22 -7
- package/dist/ContextSelector.styles.d.ts +1 -0
- package/dist/ContextSelector.styles.js +5 -1
- package/dist/ContextSelector.types.d.ts +25 -0
- package/dist/ContextSelectorDropdown/ContextSelectorDropdown.js +127 -62
- package/dist/ContextSelectorDropdown/ContextSelectorDropdownItem.js +3 -1
- package/package.json +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.7.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-context-selector@0.6.4...@synerise/ds-context-selector@0.7.0) (2021-10-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **condition:** performance improvements ([c3f54cf](https://github.com/Synerise/synerise-design/commit/c3f54cffcf2cfcb58da8686b88800fffed5e26ce))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **context-selector:** adds infinitescroll and virtualization ([dc8592e](https://github.com/Synerise/synerise-design/commit/dc8592e42c161502c44527cbb4a80a25670e95a9))
|
|
17
|
+
* **context-selector:** adds new types, updates readme ([375df69](https://github.com/Synerise/synerise-design/commit/375df69b583948d362fed0f0917870fd9c96f156))
|
|
18
|
+
* **context-selector:** adds virtualization ([7f00e48](https://github.com/Synerise/synerise-design/commit/7f00e48fba72f2f5e5557e92a821b6ea1f23f495))
|
|
19
|
+
* **context-selector:** adds virtualization ([9dba88c](https://github.com/Synerise/synerise-design/commit/9dba88c9598a7a22977a06dba1813f687f714161))
|
|
20
|
+
* **context-selector:** optimization improvements ([28feae6](https://github.com/Synerise/synerise-design/commit/28feae6ebc0e07c37c6c83f5197e80ea7c59347f))
|
|
21
|
+
* **context-selector:** performance improvements ([a1c1fb8](https://github.com/Synerise/synerise-design/commit/a1c1fb834e2c5464cbfd2852da77f9ace3667908))
|
|
22
|
+
* **context-selector:** update styles ([5bdc277](https://github.com/Synerise/synerise-design/commit/5bdc277644da1f6eae9fe1d4aa9da7379bed389f))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [0.6.4](https://github.com/Synerise/synerise-design/compare/@synerise/ds-context-selector@0.6.3...@synerise/ds-context-selector@0.6.4) (2021-09-21)
|
|
7
29
|
|
|
8
30
|
**Note:** Version bump only for package @synerise/ds-context-selector
|
package/README.md
CHANGED
|
@@ -84,21 +84,25 @@ import ContextSelector from '@synerise/ds-context-selector'
|
|
|
84
84
|
|
|
85
85
|
## API
|
|
86
86
|
|
|
87
|
-
| Property | Description
|
|
88
|
-
| --- | ---
|
|
89
|
-
| groups | Groups of items
|
|
90
|
-
| items | Array of items
|
|
91
|
-
| onSelectItem | Callback called when user selects item
|
|
92
|
-
| opened | Whether if dropdown should opens from outside of component
|
|
93
|
-
| texts | Translations object
|
|
94
|
-
| selectedItem | Selected item
|
|
95
|
-
| addMode | If true trigger doesn't change style when value is set
|
|
96
|
-
| customTriggerComponent | Add custom trigger
|
|
97
|
-
| trigger | Add custom trigger to modal
|
|
98
|
-
| menuItemHeight | Set component Menu.Item height
|
|
99
|
-
| dropdownWrapperStyles | Apply custom styles to dropdown wrapper
|
|
100
|
-
| onClickOutsideEvents | Overwrite default events for document listener
|
|
101
|
-
| onClickOutside | Callback called when user click outside dropdown
|
|
87
|
+
| Property | Description | Type | Default |
|
|
88
|
+
| --- | --- | --- | --- |
|
|
89
|
+
| groups | Groups of items | ContextGroup[] | [] |
|
|
90
|
+
| items | Array of items | ContextItem[] | [] |
|
|
91
|
+
| onSelectItem | Callback called when user selects item | (item: ContextItem \ ContextGroup \ undefined) => void | - |
|
|
92
|
+
| opened | Whether if dropdown should opens from outside of component | boolean | false |
|
|
93
|
+
| texts | Translations object | ContextSelectorTexts | - |
|
|
94
|
+
| selectedItem | Selected item | ContextItem \ undefined | undefined |
|
|
95
|
+
| addMode | If true trigger doesn't change style when value is set | ContextItem \ undefined | undefined |
|
|
96
|
+
| customTriggerComponent | Add custom trigger | React.ReactNode | undefined |
|
|
97
|
+
| trigger | Add custom trigger to modal | 'click' \ 'hover' \ 'contextMenu' | 'click |
|
|
98
|
+
| menuItemHeight | Set component Menu.Item height | 'large' \ 'default' | - |
|
|
99
|
+
| dropdownWrapperStyles | Apply custom styles to dropdown wrapper | CSSProperties \ undefined | - |
|
|
100
|
+
| onClickOutsideEvents | Overwrite default events for document listener | HandledEventsType[] \ undefined | - |
|
|
101
|
+
| onClickOutside | Callback called when user click outside dropdown | () => void \ undefined | - |
|
|
102
|
+
| onSearch | Callback called when user enter any char in search input | (query: string) => void | - |
|
|
103
|
+
| onFetchData | Callback called when user scrolls to the end of dropdown list | () => void | - |
|
|
104
|
+
| hasMoreItems | Whether if onFetchData should be called | boolean | - |
|
|
105
|
+
|
|
102
106
|
|
|
103
107
|
### ContextGroup
|
|
104
108
|
|
package/dist/ContextSelector.js
CHANGED
|
@@ -16,6 +16,7 @@ import Icon from '@synerise/ds-icon';
|
|
|
16
16
|
import { AngleDownS, Add3M } from '@synerise/ds-icon/dist/icons';
|
|
17
17
|
import Dropdown from '@synerise/ds-dropdown';
|
|
18
18
|
import Tooltip from '@synerise/ds-tooltip';
|
|
19
|
+
import { getPopupContainer } from '@synerise/ds-utils';
|
|
19
20
|
import ContextSelectorDropdown from './ContextSelectorDropdown/ContextSelectorDropdown';
|
|
20
21
|
import { ItemWrapper } from './ContextSelector.styles';
|
|
21
22
|
|
|
@@ -34,7 +35,12 @@ var ContextSelector = function ContextSelector(_ref) {
|
|
|
34
35
|
menuItemHeight = _ref.menuItemHeight,
|
|
35
36
|
dropdownWrapperStyles = _ref.dropdownWrapperStyles,
|
|
36
37
|
onClickOutsideEvents = _ref.onClickOutsideEvents,
|
|
37
|
-
onClickOutside = _ref.onClickOutside
|
|
38
|
+
onClickOutside = _ref.onClickOutside,
|
|
39
|
+
onSearch = _ref.onSearch,
|
|
40
|
+
hasMoreItems = _ref.hasMoreItems,
|
|
41
|
+
onFetchData = _ref.onFetchData,
|
|
42
|
+
onOpen = _ref.onOpen,
|
|
43
|
+
type = _ref.type;
|
|
38
44
|
|
|
39
45
|
var _React$useState = React.useState(false),
|
|
40
46
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
@@ -42,6 +48,7 @@ var ContextSelector = function ContextSelector(_ref) {
|
|
|
42
48
|
setDropdownVisible = _React$useState2[1];
|
|
43
49
|
|
|
44
50
|
var handleChange = React.useCallback(function (val) {
|
|
51
|
+
setDropdownVisible(false);
|
|
45
52
|
onSelectItem(val);
|
|
46
53
|
}, [onSelectItem]);
|
|
47
54
|
var handleOnSetGroup = React.useCallback(function (val) {
|
|
@@ -56,11 +63,13 @@ var ContextSelector = function ContextSelector(_ref) {
|
|
|
56
63
|
return selectedItem ? 'two-icons' : 'label-icon';
|
|
57
64
|
}, [selectedItem]);
|
|
58
65
|
var triggerColor = React.useMemo(function () {
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
if (!selectedItem) return 'blue';
|
|
67
|
+
return type === 'event' ? 'cyan' : 'green';
|
|
68
|
+
}, [selectedItem, type]);
|
|
61
69
|
var handleClick = React.useCallback(function () {
|
|
70
|
+
onOpen && onOpen();
|
|
62
71
|
setDropdownVisible(true);
|
|
63
|
-
}, []);
|
|
72
|
+
}, [onOpen]);
|
|
64
73
|
var triggerButton = React.useMemo(function () {
|
|
65
74
|
var buttonLabel = texts.buttonLabel;
|
|
66
75
|
return addMode && !selectedItem ? React.createElement(Button, {
|
|
@@ -82,7 +91,10 @@ var ContextSelector = function ContextSelector(_ref) {
|
|
|
82
91
|
component: React.createElement(AngleDownS, null)
|
|
83
92
|
}));
|
|
84
93
|
}, [addMode, handleClick, texts, triggerColor, triggerMode, selectedItem]);
|
|
85
|
-
return React.createElement(
|
|
94
|
+
return React.createElement("div", {
|
|
95
|
+
"data-popup-container": true
|
|
96
|
+
}, React.createElement(Dropdown, {
|
|
97
|
+
getPopupContainer: getPopupContainer,
|
|
86
98
|
trigger: trigger,
|
|
87
99
|
visible: dropdownVisible,
|
|
88
100
|
overlay: React.createElement(ContextSelectorDropdown, {
|
|
@@ -98,9 +110,12 @@ var ContextSelector = function ContextSelector(_ref) {
|
|
|
98
110
|
menuItemHeight: menuItemHeight,
|
|
99
111
|
dropdownWrapperStyles: dropdownWrapperStyles,
|
|
100
112
|
onClickOutsideEvents: onClickOutsideEvents,
|
|
101
|
-
onClickOutside: onClickOutside
|
|
113
|
+
onClickOutside: onClickOutside,
|
|
114
|
+
onSearch: onSearch,
|
|
115
|
+
hasMoreItems: hasMoreItems,
|
|
116
|
+
onFetchData: onFetchData
|
|
102
117
|
})
|
|
103
|
-
}, customTriggerComponent !== null && customTriggerComponent !== void 0 ? customTriggerComponent : triggerButton);
|
|
118
|
+
}, customTriggerComponent !== null && customTriggerComponent !== void 0 ? customTriggerComponent : triggerButton));
|
|
104
119
|
};
|
|
105
120
|
|
|
106
121
|
export default ContextSelector;
|
|
@@ -6,3 +6,4 @@ export declare const SearchResult: import("styled-components").StyledComponent<"
|
|
|
6
6
|
export declare const SearchResultHighlight: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
7
7
|
export declare const Title: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
8
8
|
export declare const ItemWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
9
|
+
export declare const LoaderWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -35,4 +35,8 @@ export var ItemWrapper = styled.div.withConfig({
|
|
|
35
35
|
componentId: "sc-1tuu6xk-6"
|
|
36
36
|
})(["max-width:200px;overflow:hidden;text-overflow:ellipsis;color:", ";"], function (props) {
|
|
37
37
|
return props.theme.palette.white;
|
|
38
|
-
});
|
|
38
|
+
});
|
|
39
|
+
export var LoaderWrapper = styled.div.withConfig({
|
|
40
|
+
displayName: "ContextSelectorstyles__LoaderWrapper",
|
|
41
|
+
componentId: "sc-1tuu6xk-7"
|
|
42
|
+
})(["width:100%;display:flex;align-items:center;justify-content:center;padding:32px 0;"]);
|
|
@@ -49,6 +49,11 @@ export declare type ContextProps = {
|
|
|
49
49
|
dropdownWrapperStyles?: CSSProperties;
|
|
50
50
|
onClickOutsideEvents?: HandledEventsType[];
|
|
51
51
|
onClickOutside?: () => void;
|
|
52
|
+
onSearch?: (query: string) => void;
|
|
53
|
+
onFetchData?: () => void;
|
|
54
|
+
onOpen?: () => void;
|
|
55
|
+
hasMoreItems?: boolean;
|
|
56
|
+
type?: 'default' | 'attribute' | 'event';
|
|
52
57
|
};
|
|
53
58
|
export declare type ContextDropdownProps = {
|
|
54
59
|
setDropdownVisible: (show: boolean) => void;
|
|
@@ -64,6 +69,10 @@ export declare type ContextDropdownProps = {
|
|
|
64
69
|
dropdownWrapperStyles?: CSSProperties;
|
|
65
70
|
onClickOutsideEvents?: HandledEventsType[];
|
|
66
71
|
onClickOutside?: () => void;
|
|
72
|
+
onSearch?: (query: string) => void;
|
|
73
|
+
onFetchData?: () => void;
|
|
74
|
+
hasMoreItems?: boolean;
|
|
75
|
+
style?: React.CSSProperties;
|
|
67
76
|
};
|
|
68
77
|
export declare type ContextSelectorDropdownItemProps = {
|
|
69
78
|
item: ContextItem | ContextGroup;
|
|
@@ -74,4 +83,20 @@ export declare type ContextSelectorDropdownItemProps = {
|
|
|
74
83
|
selected?: boolean;
|
|
75
84
|
className: string;
|
|
76
85
|
menuItemHeight?: 'large' | 'default';
|
|
86
|
+
style?: React.CSSProperties;
|
|
77
87
|
};
|
|
88
|
+
export declare type ListItem = {
|
|
89
|
+
className: string;
|
|
90
|
+
item: ContextItem | ContextGroup;
|
|
91
|
+
searchQuery: string;
|
|
92
|
+
select: (item: ContextItem | ContextGroup) => void;
|
|
93
|
+
menuItemHeight?: 'large' | 'default';
|
|
94
|
+
selected?: boolean;
|
|
95
|
+
clearSearch?: () => void;
|
|
96
|
+
hideDropdown?: () => void;
|
|
97
|
+
};
|
|
98
|
+
export declare type ListTitle = {
|
|
99
|
+
title?: string;
|
|
100
|
+
type?: string;
|
|
101
|
+
};
|
|
102
|
+
export declare type DropdownItemProps = ListTitle | ListItem;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
1
3
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
4
|
|
|
3
5
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -35,10 +37,15 @@ import Scrollbar from '@synerise/ds-scrollbar';
|
|
|
35
37
|
import Loader from '@synerise/ds-loader';
|
|
36
38
|
import theme from '@synerise/ds-core/dist/js/DSProvider/ThemeProvider/theme';
|
|
37
39
|
import { v4 as uuid } from 'uuid';
|
|
40
|
+
import { FixedSizeList as List } from 'react-window';
|
|
38
41
|
import * as S from '../ContextSelector.styles';
|
|
39
42
|
import ContextSelectorDropdownItem from './ContextSelectorDropdownItem';
|
|
40
43
|
var NO_GROUP_NAME = 'NO_GROUP_NAME';
|
|
41
44
|
|
|
45
|
+
function isListTitle(element) {
|
|
46
|
+
return element.title !== undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
42
49
|
var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
43
50
|
var texts = _ref.texts,
|
|
44
51
|
setSelected = _ref.setSelected,
|
|
@@ -52,7 +59,15 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
52
59
|
menuItemHeight = _ref.menuItemHeight,
|
|
53
60
|
dropdownWrapperStyles = _ref.dropdownWrapperStyles,
|
|
54
61
|
onClickOutsideEvents = _ref.onClickOutsideEvents,
|
|
55
|
-
onClickOutside = _ref.onClickOutside
|
|
62
|
+
onClickOutside = _ref.onClickOutside,
|
|
63
|
+
onSearch = _ref.onSearch,
|
|
64
|
+
onFetchData = _ref.onFetchData,
|
|
65
|
+
hasMoreItems = _ref.hasMoreItems;
|
|
66
|
+
var listRef = React.createRef();
|
|
67
|
+
var listStyle = {
|
|
68
|
+
overflowX: 'unset',
|
|
69
|
+
overflowY: 'unset'
|
|
70
|
+
};
|
|
56
71
|
var defaultTab = React.useMemo(function () {
|
|
57
72
|
var defaultIndex = groups === null || groups === void 0 ? void 0 : groups.findIndex(function (group) {
|
|
58
73
|
return group.defaultGroup;
|
|
@@ -92,76 +107,90 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
92
107
|
onClickOutside && onClickOutside();
|
|
93
108
|
setDropdownVisible(false);
|
|
94
109
|
}, onClickOutsideEvents);
|
|
110
|
+
var clearSearch = React.useCallback(function () {
|
|
111
|
+
setSearchQuery('');
|
|
112
|
+
}, []);
|
|
113
|
+
var hideDropdown = React.useCallback(function () {
|
|
114
|
+
setDropdownVisible(false);
|
|
115
|
+
}, [setDropdownVisible]);
|
|
116
|
+
var currentTabItems = React.useMemo(function () {
|
|
117
|
+
return groups === null || groups === void 0 ? void 0 : groups.find(function (group, index) {
|
|
118
|
+
return activeTab === index;
|
|
119
|
+
});
|
|
120
|
+
}, [groups, activeTab]);
|
|
95
121
|
var groupByGroupName = React.useCallback(function (activeItems) {
|
|
96
|
-
var
|
|
97
|
-
|
|
122
|
+
var itemsNumber = activeItems.length;
|
|
123
|
+
var groupedItems = {};
|
|
124
|
+
|
|
125
|
+
for (var i = 0; i < itemsNumber; i += 1) {
|
|
126
|
+
var item = activeItems[i];
|
|
98
127
|
var groupName = item.groupName || NO_GROUP_NAME;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
var group = groupedItems[groupName] || [];
|
|
129
|
+
group.push(item);
|
|
130
|
+
groupedItems[groupName] = group;
|
|
131
|
+
}
|
|
132
|
+
|
|
102
133
|
var resultItems = [];
|
|
103
134
|
Object.keys(groupedItems).forEach(function (key) {
|
|
104
135
|
if (key !== NO_GROUP_NAME && !activeGroup) {
|
|
105
|
-
resultItems.push(
|
|
136
|
+
resultItems.push({
|
|
137
|
+
type: 'title',
|
|
138
|
+
title: key
|
|
139
|
+
});
|
|
106
140
|
}
|
|
107
141
|
|
|
108
142
|
groupedItems[key].forEach(function (item) {
|
|
109
|
-
var resultItem = item.isGroup ?
|
|
143
|
+
var resultItem = item.isGroup ? {
|
|
110
144
|
className: classNames,
|
|
111
|
-
key: item.name + item.id,
|
|
112
145
|
item: item,
|
|
113
146
|
searchQuery: searchQuery,
|
|
114
147
|
select: handleOnSetGroup,
|
|
115
148
|
menuItemHeight: menuItemHeight
|
|
116
|
-
}
|
|
149
|
+
} : {
|
|
117
150
|
className: classNames,
|
|
118
|
-
key: item.name + item.id + item.groupId,
|
|
119
151
|
item: item,
|
|
120
152
|
searchQuery: searchQuery,
|
|
121
|
-
hideDropdown:
|
|
122
|
-
return setDropdownVisible(false);
|
|
123
|
-
},
|
|
153
|
+
hideDropdown: hideDropdown,
|
|
124
154
|
select: setSelected,
|
|
125
155
|
selected: Boolean(value) && item.id === (value === null || value === void 0 ? void 0 : value.id),
|
|
126
156
|
menuItemHeight: menuItemHeight
|
|
127
|
-
}
|
|
157
|
+
};
|
|
128
158
|
resultItems.push(resultItem);
|
|
129
159
|
});
|
|
130
160
|
});
|
|
131
161
|
return resultItems;
|
|
132
|
-
}, [activeGroup, classNames, searchQuery,
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
select: setSelected,
|
|
154
|
-
selected: Boolean(value) && item.id === (value === null || value === void 0 ? void 0 : value.id),
|
|
155
|
-
menuItemHeight: menuItemHeight
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
}, [items, searchQuery, setDropdownVisible, setSelected, value, classNames, menuItemHeight]);
|
|
159
|
-
var currentItems = React.useMemo(function () {
|
|
160
|
-
if (searchQuery) {
|
|
161
|
-
return filteredItems;
|
|
162
|
+
}, [activeGroup, classNames, searchQuery, handleOnSetGroup, menuItemHeight, hideDropdown, setSelected, value]);
|
|
163
|
+
var searchResults = React.useMemo(function () {
|
|
164
|
+
var result = [];
|
|
165
|
+
var itemsNumber = items.length;
|
|
166
|
+
|
|
167
|
+
for (var i = 0; i < itemsNumber; i += 1) {
|
|
168
|
+
var item = items[i];
|
|
169
|
+
var matching = !searchQuery || item.name.toLowerCase().includes(searchQuery.toLowerCase());
|
|
170
|
+
|
|
171
|
+
if (matching) {
|
|
172
|
+
result.push({
|
|
173
|
+
className: classNames,
|
|
174
|
+
item: item,
|
|
175
|
+
searchQuery: searchQuery,
|
|
176
|
+
clearSearch: clearSearch,
|
|
177
|
+
hideDropdown: hideDropdown,
|
|
178
|
+
select: setSelected,
|
|
179
|
+
selected: Boolean(value) && item.id === (value === null || value === void 0 ? void 0 : value.id),
|
|
180
|
+
menuItemHeight: menuItemHeight
|
|
181
|
+
});
|
|
182
|
+
}
|
|
162
183
|
}
|
|
163
184
|
|
|
164
|
-
|
|
185
|
+
return result;
|
|
186
|
+
}, [classNames, clearSearch, hideDropdown, items, menuItemHeight, searchQuery, setSelected, value]);
|
|
187
|
+
var hasSubgroups = React.useMemo(function () {
|
|
188
|
+
return Boolean(currentTabItems === null || currentTabItems === void 0 ? void 0 : currentTabItems.subGroups);
|
|
189
|
+
}, [currentTabItems]);
|
|
190
|
+
var activeItems = React.useMemo(function () {
|
|
191
|
+
if (!onSearch && searchQuery) {
|
|
192
|
+
return searchResults;
|
|
193
|
+
}
|
|
165
194
|
|
|
166
195
|
if (hasSubgroups && !activeGroup) {
|
|
167
196
|
var _currentTabItems$subG;
|
|
@@ -185,17 +214,22 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
185
214
|
|
|
186
215
|
if (activeGroup) {
|
|
187
216
|
return groupByGroupName(items === null || items === void 0 ? void 0 : items.filter(function (item) {
|
|
188
|
-
return item.groupId === activeGroup.id;
|
|
217
|
+
return activeGroup && item.groupId === activeGroup.id;
|
|
189
218
|
}));
|
|
190
219
|
}
|
|
191
220
|
|
|
192
|
-
|
|
193
|
-
return
|
|
194
|
-
|
|
195
|
-
|
|
221
|
+
if (activeTab && groups && groups[activeTab]) {
|
|
222
|
+
return groupByGroupName(items === null || items === void 0 ? void 0 : items.filter(function (item) {
|
|
223
|
+
return item.groupId === groups[activeTab].id;
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return groupByGroupName(items);
|
|
228
|
+
}, [activeGroup, activeTab, currentTabItems, groupByGroupName, groups, hasSubgroups, items, onSearch, searchQuery, searchResults]);
|
|
196
229
|
var handleSearch = React.useCallback(function (val) {
|
|
197
230
|
setSearchQuery(val);
|
|
198
|
-
|
|
231
|
+
onSearch && onSearch(val);
|
|
232
|
+
}, [onSearch]);
|
|
199
233
|
var getTabs = React.useMemo(function () {
|
|
200
234
|
return (groups === null || groups === void 0 ? void 0 : groups.map(function (group) {
|
|
201
235
|
return {
|
|
@@ -204,15 +238,22 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
204
238
|
})) || [];
|
|
205
239
|
}, [groups]);
|
|
206
240
|
var getNoResultContainer = React.useMemo(function () {
|
|
207
|
-
return
|
|
208
|
-
label: texts.loadingResults,
|
|
209
|
-
labelPosition: "bottom"
|
|
210
|
-
}) : React.createElement(Result, {
|
|
241
|
+
return React.createElement(Result, {
|
|
211
242
|
noSearchResults: true,
|
|
212
243
|
type: "no-results",
|
|
213
244
|
description: texts.noResults
|
|
214
245
|
});
|
|
215
|
-
}, [
|
|
246
|
+
}, [texts]);
|
|
247
|
+
|
|
248
|
+
var handleScroll = function handleScroll(_ref2) {
|
|
249
|
+
var currentTarget = _ref2.currentTarget;
|
|
250
|
+
var scrollTop = currentTarget.scrollTop;
|
|
251
|
+
|
|
252
|
+
if (listRef.current !== null) {
|
|
253
|
+
listRef.current.scrollTo(scrollTop);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
216
257
|
return React.createElement(Dropdown.Wrapper, {
|
|
217
258
|
style: _objectSpread({
|
|
218
259
|
width: '300px'
|
|
@@ -227,11 +268,13 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
227
268
|
}, React.createElement(Dropdown.SearchInput, {
|
|
228
269
|
onSearchChange: handleSearch,
|
|
229
270
|
onClearInput: function onClearInput() {
|
|
230
|
-
|
|
271
|
+
handleSearch('');
|
|
272
|
+
onSearch && onSearch('');
|
|
231
273
|
},
|
|
232
274
|
placeholder: texts.searchPlaceholder,
|
|
233
275
|
value: searchQuery,
|
|
234
276
|
autofocus: !searchQuery || searchInputCanBeFocused,
|
|
277
|
+
autofocusDelay: 50,
|
|
235
278
|
iconLeft: React.createElement(Icon, {
|
|
236
279
|
component: React.createElement(SearchM, null),
|
|
237
280
|
color: theme.palette['grey-600']
|
|
@@ -250,13 +293,35 @@ var ContextSelectorDropdown = function ContextSelectorDropdown(_ref) {
|
|
|
250
293
|
onClick: function onClick() {
|
|
251
294
|
return setActiveGroup(undefined);
|
|
252
295
|
}
|
|
253
|
-
}), React.createElement(S.
|
|
296
|
+
}), loading ? React.createElement(S.LoaderWrapper, null, React.createElement(Loader, {
|
|
297
|
+
label: texts.loadingResults,
|
|
298
|
+
labelPosition: "bottom"
|
|
299
|
+
})) : React.createElement(S.ItemsList, null, (activeItems === null || activeItems === void 0 ? void 0 : activeItems.length) ? React.createElement(Scrollbar, {
|
|
254
300
|
absolute: true,
|
|
255
|
-
maxHeight: 300,
|
|
256
301
|
style: {
|
|
257
302
|
padding: 8
|
|
258
|
-
}
|
|
259
|
-
|
|
303
|
+
},
|
|
304
|
+
loading: loading,
|
|
305
|
+
hasMore: hasMoreItems,
|
|
306
|
+
onYReachEnd: onFetchData,
|
|
307
|
+
onScroll: handleScroll
|
|
308
|
+
}, React.createElement(List, {
|
|
309
|
+
width: "100%",
|
|
310
|
+
height: 300,
|
|
311
|
+
itemCount: activeItems.length,
|
|
312
|
+
itemSize: 32,
|
|
313
|
+
style: listStyle,
|
|
314
|
+
ref: listRef
|
|
315
|
+
}, function (_ref3) {
|
|
316
|
+
var index = _ref3.index,
|
|
317
|
+
style = _ref3.style;
|
|
318
|
+
var item = activeItems[index];
|
|
319
|
+
return item && isListTitle(item) ? React.createElement(S.Title, {
|
|
320
|
+
style: style
|
|
321
|
+
}, item.title) : React.createElement(ContextSelectorDropdownItem, _extends({
|
|
322
|
+
style: style
|
|
323
|
+
}, item));
|
|
324
|
+
})) : getNoResultContainer));
|
|
260
325
|
};
|
|
261
326
|
|
|
262
327
|
export default ContextSelectorDropdown;
|
|
@@ -12,8 +12,10 @@ var ContextSelectorDropdownItem = function ContextSelectorDropdownItem(_ref) {
|
|
|
12
12
|
select = _ref.select,
|
|
13
13
|
selected = _ref.selected,
|
|
14
14
|
className = _ref.className,
|
|
15
|
-
menuItemHeight = _ref.menuItemHeight
|
|
15
|
+
menuItemHeight = _ref.menuItemHeight,
|
|
16
|
+
style = _ref.style;
|
|
16
17
|
return React.createElement(Menu.Item, {
|
|
18
|
+
style: style,
|
|
17
19
|
className: className,
|
|
18
20
|
key: item.name + item.id,
|
|
19
21
|
prefixel: item.useCustomIcon ? item.icon : React.createElement(Icon, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-context-selector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "ContextSelector UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -26,22 +26,23 @@
|
|
|
26
26
|
"test:watch": "npm run test -- --watchAll",
|
|
27
27
|
"types": "tsc --noEmit"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "1fdb5eb22cd9c4d5f786d33d75531c31eba7ece3",
|
|
30
30
|
"sideEffects": [
|
|
31
31
|
"dist/style/*",
|
|
32
32
|
"*.less"
|
|
33
33
|
],
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@synerise/ds-button": "^0.13.
|
|
37
|
-
"@synerise/ds-dropdown": "^0.16.
|
|
36
|
+
"@synerise/ds-button": "^0.13.67",
|
|
37
|
+
"@synerise/ds-dropdown": "^0.16.28",
|
|
38
38
|
"@synerise/ds-icon": "^0.45.0",
|
|
39
|
-
"@synerise/ds-menu": "^0.10.
|
|
40
|
-
"@synerise/ds-result": "^0.5.
|
|
41
|
-
"@synerise/ds-scrollbar": "^0.3.
|
|
42
|
-
"@synerise/ds-tabs": "^0.11.
|
|
43
|
-
"@synerise/ds-utils": "^0.
|
|
44
|
-
"classnames": "^2.2.6"
|
|
39
|
+
"@synerise/ds-menu": "^0.10.42",
|
|
40
|
+
"@synerise/ds-result": "^0.5.75",
|
|
41
|
+
"@synerise/ds-scrollbar": "^0.3.17",
|
|
42
|
+
"@synerise/ds-tabs": "^0.11.71",
|
|
43
|
+
"@synerise/ds-utils": "^0.19.0",
|
|
44
|
+
"classnames": "^2.2.6",
|
|
45
|
+
"react-window": "1.8.5"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"@synerise/ds-core": "*",
|