@jetbrains/ring-ui-built 6.0.30 → 6.0.32
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/components/_helpers/_rollupPluginBabelHelpers.js +7 -629
- package/components/_helpers/anchor.js +7 -6
- package/components/_helpers/button__classes.js +16 -14
- package/components/_helpers/caption.js +14 -20
- package/components/_helpers/card.js +95 -105
- package/components/_helpers/dialog__body-scroll-preventer.js +11 -19
- package/components/_helpers/icon__svg.js +22 -25
- package/components/_helpers/input.js +146 -177
- package/components/_helpers/query-assist__suggestions.js +74 -90
- package/components/_helpers/select__filter.js +48 -69
- package/components/_helpers/services-link.js +29 -37
- package/components/_helpers/sidebar.js +99 -107
- package/components/_helpers/tab-link.js +7 -7
- package/components/_helpers/theme.js +31 -40
- package/components/_helpers/title.js +57 -72
- package/components/alert/alert.js +150 -202
- package/components/alert/container.js +32 -41
- package/components/alert-service/alert-service.js +105 -170
- package/components/analytics/analytics.js +12 -22
- package/components/analytics/analytics__custom-plugin.js +54 -75
- package/components/auth/auth.js +4 -36
- package/components/auth/auth__core.js +746 -1471
- package/components/auth/background-flow.js +87 -127
- package/components/auth/down-notification.js +30 -73
- package/components/auth/iframe-flow.js +75 -133
- package/components/auth/request-builder.js +46 -82
- package/components/auth/response-parser.js +86 -116
- package/components/auth/storage.js +171 -334
- package/components/auth/token-validator.js +137 -242
- package/components/auth/window-flow.js +92 -134
- package/components/auth-dialog/auth-dialog.js +114 -172
- package/components/auth-dialog-service/auth-dialog-service.js +8 -31
- package/components/avatar/avatar-example-datauri.js +23 -1
- package/components/avatar/avatar.js +119 -152
- package/components/avatar/fallback-avatar.js +22 -38
- package/components/badge/badge.js +35 -45
- package/components/button/button.js +86 -107
- package/components/button-group/button-group.js +19 -33
- package/components/button-set/button-set.js +20 -32
- package/components/button-toolbar/button-toolbar.js +19 -31
- package/components/caret/caret.js +186 -220
- package/components/checkbox/checkbox.js +76 -101
- package/components/clipboard/clipboard-fallback.js +10 -10
- package/components/clipboard/clipboard.js +35 -132
- package/components/code/code.js +92 -166
- package/components/collapse/collapse-content.js +42 -64
- package/components/collapse/collapse-context.js +2 -2
- package/components/collapse/collapse-control.js +12 -14
- package/components/collapse/collapse.js +11 -17
- package/components/collapse/consts.js +4 -4
- package/components/collapse/utils.js +1 -3
- package/components/confirm/confirm.js +66 -104
- package/components/confirm-service/confirm-service.js +37 -59
- package/components/content-layout/content-layout.js +43 -64
- package/components/content-layout/sidebar.js +0 -1
- package/components/contenteditable/contenteditable.js +50 -59
- package/components/control-label/control-label.js +9 -9
- package/components/data-list/data-list.js +129 -182
- package/components/data-list/data-list.mock.js +2 -6
- package/components/data-list/item.js +143 -170
- package/components/data-list/selection.js +76 -136
- package/components/data-list/title.js +1 -12
- package/components/date-picker/consts.js +19 -26
- package/components/date-picker/date-input.js +113 -144
- package/components/date-picker/date-picker.js +227 -282
- package/components/date-picker/date-popup.js +350 -395
- package/components/date-picker/day.js +87 -116
- package/components/date-picker/month-names.js +43 -66
- package/components/date-picker/month-slider.js +51 -76
- package/components/date-picker/month.js +16 -25
- package/components/date-picker/months.js +43 -50
- package/components/date-picker/weekdays.js +12 -22
- package/components/date-picker/years.js +83 -110
- package/components/dialog/dialog.js +142 -190
- package/components/dialog/dialog__body-scroll-preventer.js +0 -4
- package/components/dropdown/anchor.js +0 -9
- package/components/dropdown/dropdown.js +182 -213
- package/components/dropdown-menu/dropdown-menu.js +71 -97
- package/components/editable-heading/editable-heading.js +75 -127
- package/components/error-bubble/error-bubble.js +31 -60
- package/components/error-message/error-message.js +39 -59
- package/components/footer/footer.js +27 -30
- package/components/global/compose.js +1 -10
- package/components/global/composeRefs.js +7 -12
- package/components/global/controls-height.js +2 -2
- package/components/global/create-stateful-context.js +15 -15
- package/components/global/data-tests.js +6 -14
- package/components/global/dom.js +47 -86
- package/components/global/focus-sensor-hoc.js +122 -132
- package/components/global/fuzzy-highlight.js +22 -36
- package/components/global/get-event-key.js +8 -8
- package/components/global/get-uid.js +4 -8
- package/components/global/inject-styles.js +10 -15
- package/components/global/listeners.js +27 -51
- package/components/global/memoize.js +6 -12
- package/components/global/normalize-indent.js +19 -50
- package/components/global/promise-with-timeout.js +6 -8
- package/components/global/prop-types.js +3 -5
- package/components/global/react-dom-renderer.js +28 -44
- package/components/global/react-render-adapter.js +1 -1
- package/components/global/rerender-hoc.js +12 -30
- package/components/global/schedule-raf.js +5 -6
- package/components/global/sniffer.js +1 -1
- package/components/global/theme.js +0 -22
- package/components/global/trivial-template-tag.js +3 -10
- package/components/global/typescript-utils.js +2 -6
- package/components/global/url.js +20 -26
- package/components/global/use-event-callback.js +6 -4
- package/components/grid/col.js +35 -52
- package/components/grid/grid.js +17 -31
- package/components/grid/row.js +35 -47
- package/components/group/group.js +17 -25
- package/components/header/header.js +33 -78
- package/components/header/logo.js +20 -36
- package/components/header/profile.js +166 -199
- package/components/header/services-link.js +0 -4
- package/components/header/services.js +73 -116
- package/components/header/smart-profile.js +111 -203
- package/components/header/smart-services.js +62 -113
- package/components/header/tray-icon.js +21 -37
- package/components/header/tray.js +21 -32
- package/components/heading/heading.js +24 -25
- package/components/http/http.d.ts +1 -3
- package/components/http/http.js +203 -353
- package/components/http/http.mock.js +49 -101
- package/components/hub-source/hub-source.js +83 -190
- package/components/hub-source/hub-source__user.js +11 -44
- package/components/hub-source/hub-source__users-groups.js +37 -65
- package/components/i18n/i18n-context.js +7 -10
- package/components/i18n/i18n.js +7 -10
- package/components/icon/icon.js +76 -93
- package/components/icon/icon__svg.js +0 -8
- package/components/icon/index.js +0 -8
- package/components/input/input.js +0 -13
- package/components/island/adaptive-island-hoc.js +30 -43
- package/components/island/content.js +115 -132
- package/components/island/header.js +57 -70
- package/components/island/island.js +28 -40
- package/components/island-legacy/content-legacy.js +17 -25
- package/components/island-legacy/header-legacy.js +19 -27
- package/components/island-legacy/island-legacy.js +17 -25
- package/components/link/clickableLink.js +44 -59
- package/components/link/link.js +57 -68
- package/components/list/consts.js +2 -2
- package/components/list/list.js +611 -698
- package/components/list/list__custom.js +44 -62
- package/components/list/list__hint.js +10 -19
- package/components/list/list__item.js +133 -174
- package/components/list/list__link.js +37 -50
- package/components/list/list__separator.js +14 -24
- package/components/list/list__title.js +22 -32
- package/components/list/list__users-groups-source.js +54 -126
- package/components/loader/loader.js +43 -74
- package/components/loader/loader__core.js +198 -263
- package/components/loader-inline/loader-inline.js +23 -35
- package/components/loader-screen/loader-screen.js +25 -46
- package/components/login-dialog/login-dialog.js +111 -158
- package/components/login-dialog/service.js +8 -34
- package/components/markdown/markdown.js +15 -23
- package/components/message/message.js +161 -203
- package/components/old-browsers-message/old-browsers-message.js +11 -18
- package/components/old-browsers-message/old-browsers-message__stop.js +0 -7
- package/components/old-browsers-message/white-list.js +8 -16
- package/components/pager/pager.js +212 -271
- package/components/panel/panel.js +17 -25
- package/components/permissions/permissions.js +127 -172
- package/components/permissions/permissions__cache.js +194 -224
- package/components/popup/popup.consts.js +1 -1
- package/components/popup/popup.js +284 -343
- package/components/popup/popup.target.js +9 -8
- package/components/popup/position.js +96 -106
- package/components/popup-menu/popup-menu.js +44 -80
- package/components/progress-bar/progress-bar.js +87 -104
- package/components/query-assist/query-assist.js +838 -916
- package/components/query-assist/query-assist__suggestions.js +1 -30
- package/components/radio/radio.js +19 -34
- package/components/radio/radio__item.js +52 -69
- package/components/select/select.js +852 -957
- package/components/select/select__filter.js +0 -30
- package/components/select/select__popup.js +373 -487
- package/components/shortcuts/core.js +166 -217
- package/components/shortcuts/shortcut-title.js +6 -11
- package/components/shortcuts/shortcuts-hoc.js +19 -45
- package/components/shortcuts/shortcuts.js +50 -75
- package/components/slider/slider.js +99 -122
- package/components/slider/slider.utils.js +14 -24
- package/components/storage/storage.js +4 -33
- package/components/storage/storage__fallback.js +149 -224
- package/components/storage/storage__local.js +90 -153
- package/components/style.css +1 -1
- package/components/tab-trap/tab-trap.js +122 -153
- package/components/table/cell.js +14 -26
- package/components/table/disable-hover-hoc.js +33 -51
- package/components/table/header-cell.js +64 -89
- package/components/table/header.js +104 -132
- package/components/table/multitable.js +107 -125
- package/components/table/row-with-focus-sensor.js +25 -69
- package/components/table/row.js +175 -216
- package/components/table/selection-adapter.js +1 -3
- package/components/table/selection-shortcuts-hoc.js +180 -181
- package/components/table/selection.js +156 -226
- package/components/table/smart-table.js +50 -88
- package/components/table/table.js +289 -358
- package/components/tabs/collapsible-more.js +46 -79
- package/components/tabs/collapsible-tab.js +31 -38
- package/components/tabs/collapsible-tabs.js +88 -153
- package/components/tabs/custom-item.js +4 -2
- package/components/tabs/dumb-tabs.js +74 -117
- package/components/tabs/smart-tabs.js +29 -69
- package/components/tabs/tab-link.js +1 -5
- package/components/tabs/tab.js +19 -31
- package/components/tabs/tabs.js +0 -31
- package/components/tag/tag.js +133 -173
- package/components/tags-input/tags-input.js +329 -427
- package/components/tags-list/tags-list.js +57 -78
- package/components/text/text.js +28 -39
- package/components/toggle/toggle.js +56 -70
- package/components/tooltip/tooltip.js +146 -190
- package/components/user-agreement/service.js +228 -371
- package/components/user-agreement/toolbox.eula.js +160 -1
- package/components/user-agreement/user-agreement.js +85 -120
- package/components/user-card/card.js +0 -29
- package/components/user-card/smart-user-card-tooltip.js +51 -111
- package/components/user-card/tooltip.js +47 -84
- package/components/user-card/user-card.js +0 -29
- package/package.json +1 -1
@@ -1,19 +1,5 @@
|
|
1
|
-
import { _ as
|
2
|
-
import '
|
3
|
-
import 'core-js/modules/es.array.filter.js';
|
4
|
-
import 'core-js/modules/es.array.find.js';
|
5
|
-
import 'core-js/modules/es.array.index-of.js';
|
6
|
-
import 'core-js/modules/es.array.map.js';
|
7
|
-
import 'core-js/modules/es.array.reduce.js';
|
8
|
-
import 'core-js/modules/es.array.slice.js';
|
9
|
-
import 'core-js/modules/es.object.assign.js';
|
10
|
-
import 'core-js/modules/es.object.to-string.js';
|
11
|
-
import 'core-js/modules/es.object.values.js';
|
12
|
-
import 'core-js/modules/es.regexp.exec.js';
|
13
|
-
import 'core-js/modules/es.string.replace.js';
|
14
|
-
import 'core-js/modules/es.string.trim.js';
|
15
|
-
import 'core-js/modules/web.dom-collections.for-each.js';
|
16
|
-
import React, { Fragment, Component } from 'react';
|
1
|
+
import { _ as _extends } from '../_helpers/_rollupPluginBabelHelpers.js';
|
2
|
+
import React, { Component, Fragment } from 'react';
|
17
3
|
import classNames from 'classnames';
|
18
4
|
import PropTypes from 'prop-types';
|
19
5
|
import chevronDownIcon from '@jetbrains/icons/chevron-down';
|
@@ -36,47 +22,29 @@ import { I18nContext } from '../i18n/i18n-context.js';
|
|
36
22
|
import composeRefs from '../global/composeRefs.js';
|
37
23
|
import { refObject } from '../global/prop-types.js';
|
38
24
|
import { isArray } from '../global/typescript-utils.js';
|
39
|
-
import {
|
25
|
+
import { ControlsHeightContext, ControlsHeight } from '../global/controls-height.js';
|
40
26
|
import SelectPopup from './select__popup.js';
|
41
27
|
import { A as Anchor } from '../_helpers/anchor.js';
|
42
|
-
import 'core-js/modules/es.object.entries.js';
|
43
28
|
import '@jetbrains/icons/chevron-10px';
|
44
29
|
import '../icon/icon.js';
|
45
30
|
import 'util-deprecate';
|
46
31
|
import '../icon/icon__constants.js';
|
47
32
|
import '../_helpers/icon__svg.js';
|
48
|
-
import 'core-js/modules/es.string.starts-with.js';
|
49
|
-
import 'core-js/modules/es.array.iterator.js';
|
50
|
-
import 'core-js/modules/es.map.js';
|
51
|
-
import 'core-js/modules/es.weak-map.js';
|
52
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
53
33
|
import '../link/clickableLink.js';
|
54
34
|
import '../_helpers/button__classes.js';
|
55
35
|
import '../global/url.js';
|
56
|
-
import 'core-js/modules/es.string.match.js';
|
57
36
|
import '../global/dom.js';
|
58
|
-
import 'core-js/modules/es.set.js';
|
59
|
-
import 'core-js/modules/es.string.split.js';
|
60
37
|
import '../avatar/fallback-avatar.js';
|
61
|
-
import 'core-js/modules/es.array.from.js';
|
62
|
-
import 'core-js/modules/es.regexp.to-string.js';
|
63
38
|
import 'react-dom';
|
64
39
|
import '../global/schedule-raf.js';
|
65
40
|
import '../tab-trap/tab-trap.js';
|
66
41
|
import '../popup/position.js';
|
67
|
-
import 'core-js/modules/es.array.includes.js';
|
68
|
-
import 'core-js/modules/es.array.sort.js';
|
69
|
-
import 'core-js/modules/es.string.includes.js';
|
70
42
|
import '../popup/popup.consts.js';
|
71
43
|
import '../popup/popup.target.js';
|
72
44
|
import '../shortcuts/core.js';
|
73
|
-
import 'core-js/modules/es.array.find-index.js';
|
74
|
-
import 'core-js/modules/es.array.splice.js';
|
75
45
|
import 'combokeys';
|
76
46
|
import '../global/sniffer.js';
|
77
47
|
import 'sniffr';
|
78
|
-
import 'core-js/modules/es.symbol.js';
|
79
|
-
import 'core-js/modules/es.symbol.description.js';
|
80
48
|
import 'react-virtualized/dist/es/List';
|
81
49
|
import 'react-virtualized/dist/es/AutoSizer';
|
82
50
|
import 'react-virtualized/dist/es/WindowScroller';
|
@@ -124,16 +92,12 @@ var Type;
|
|
124
92
|
Type["INLINE"] = "INLINE";
|
125
93
|
Type["INPUT_WITHOUT_CONTROLS"] = "INPUT_WITHOUT_CONTROLS";
|
126
94
|
})(Type || (Type = {}));
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
});
|
134
|
-
var _isInputMode = function isInputMode(type) {
|
135
|
-
return type === Type.INPUT || type === Type.INPUT_WITHOUT_CONTROLS;
|
136
|
-
};
|
95
|
+
const ICONS_OFFSET = 5;
|
96
|
+
const ICON_WIDTH = 20;
|
97
|
+
const getStyle = memoize(iconsLength => ({
|
98
|
+
paddingRight: ICONS_OFFSET + iconsLength * ICON_WIDTH
|
99
|
+
}));
|
100
|
+
const isInputMode = type => type === Type.INPUT || type === Type.INPUT_WITHOUT_CONTROLS;
|
137
101
|
function getLowerCaseLabel(item) {
|
138
102
|
if (List.isItemType(List.ListProps.Type.SEPARATOR, item) || List.isItemType(List.ListProps.Type.HINT, item) || typeof item.label !== 'string') {
|
139
103
|
return null;
|
@@ -141,76 +105,65 @@ function getLowerCaseLabel(item) {
|
|
141
105
|
return item.label.toLowerCase();
|
142
106
|
}
|
143
107
|
function doesLabelMatch(itemToCheck, fn) {
|
144
|
-
|
108
|
+
const lowerCaseLabel = getLowerCaseLabel(itemToCheck);
|
145
109
|
if (lowerCaseLabel == null) {
|
146
110
|
return true;
|
147
111
|
}
|
148
112
|
return fn(lowerCaseLabel);
|
149
113
|
}
|
150
|
-
function
|
114
|
+
function getFilterFn(filter) {
|
151
115
|
if (typeof filter === 'object') {
|
152
116
|
if (filter.fn) {
|
153
117
|
return filter.fn;
|
154
118
|
}
|
155
119
|
if (filter.fuzzy) {
|
156
|
-
return
|
157
|
-
return doesLabelMatch(itemToCheck, function (lowerCaseLabel) {
|
158
|
-
return fuzzyHighlight(checkString, lowerCaseLabel).matched;
|
159
|
-
});
|
160
|
-
};
|
120
|
+
return (itemToCheck, checkString) => doesLabelMatch(itemToCheck, lowerCaseLabel => fuzzyHighlight(checkString, lowerCaseLabel).matched);
|
161
121
|
}
|
162
122
|
}
|
163
|
-
return
|
164
|
-
return doesLabelMatch(itemToCheck, function (lowerCaseLabel) {
|
165
|
-
return lowerCaseLabel.indexOf(checkString) >= 0;
|
166
|
-
});
|
167
|
-
};
|
123
|
+
return (itemToCheck, checkString) => doesLabelMatch(itemToCheck, lowerCaseLabel => lowerCaseLabel.indexOf(checkString) >= 0);
|
168
124
|
}
|
169
125
|
function buildMultipleMap(selected) {
|
170
|
-
return selected.reduce(
|
126
|
+
return selected.reduce((acc, item) => {
|
171
127
|
acc[item.key] = true;
|
172
128
|
return acc;
|
173
129
|
}, {});
|
174
130
|
}
|
175
|
-
function
|
176
|
-
|
177
|
-
|
178
|
-
if (
|
131
|
+
function getListItems(props, state, rawFilterString) {
|
132
|
+
let data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : props.data;
|
133
|
+
let filterString = rawFilterString.trim();
|
134
|
+
if (isInputMode(props.type) && !props.allowAny && state.selected && !Array.isArray(state.selected) && filterString === state.selected.label) {
|
179
135
|
filterString = ''; // ignore multiple if it is exactly the selected item
|
180
136
|
}
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
137
|
+
const lowerCaseString = filterString.toLowerCase();
|
138
|
+
const filteredData = [];
|
139
|
+
let exactMatch = false;
|
140
|
+
const check = getFilterFn(props.filter);
|
141
|
+
for (let i = 0; i < data.length; i++) {
|
142
|
+
const item = {
|
143
|
+
...data[i]
|
144
|
+
};
|
187
145
|
if (check(item, lowerCaseString, data)) {
|
188
|
-
var _state$multipleMap2;
|
189
146
|
exactMatch = item.label === filterString;
|
190
147
|
if (props.multiple && !(typeof props.multiple === 'object' && props.multiple.removeSelectedItems)) {
|
191
|
-
|
192
|
-
item.checkbox = !!((_state$multipleMap = state.multipleMap) !== null && _state$multipleMap !== void 0 && _state$multipleMap[item.key]);
|
148
|
+
item.checkbox = !!state.multipleMap?.[item.key];
|
193
149
|
}
|
194
150
|
if (props.multiple && typeof props.multiple === 'object' && props.multiple.limit && Array.isArray(state.selected)) {
|
195
|
-
item.disabled = props.multiple.limit === state.selected.length && !state.selected.find(
|
196
|
-
return selectedItem.key === item.key;
|
197
|
-
});
|
151
|
+
item.disabled = props.multiple.limit === state.selected.length && !state.selected.find(selectedItem => selectedItem.key === item.key);
|
198
152
|
}
|
199
153
|
// Ignore item if it's multiple and is already selected
|
200
|
-
if (!(props.multiple && typeof props.multiple === 'object' && props.multiple.removeSelectedItems &&
|
154
|
+
if (!(props.multiple && typeof props.multiple === 'object' && props.multiple.removeSelectedItems && state.multipleMap?.[item.key])) {
|
201
155
|
filteredData.push(item);
|
202
156
|
}
|
203
157
|
}
|
204
|
-
};
|
205
|
-
for (var i = 0; i < data.length; i++) {
|
206
|
-
_loop();
|
207
158
|
}
|
208
|
-
|
209
|
-
|
159
|
+
let addButton = null;
|
160
|
+
const {
|
161
|
+
add
|
162
|
+
} = props;
|
210
163
|
if (add && filterString && !exactMatch || add && add.alwaysVisible) {
|
211
164
|
if (!(add.regexp && !add.regexp.test(filterString)) && !(add.minlength && filterString.length < +add.minlength) || add.alwaysVisible) {
|
212
165
|
var _add$delayed;
|
213
|
-
|
166
|
+
let label;
|
214
167
|
if (add.label) {
|
215
168
|
label = typeof add.label === 'function' ? add.label(filterString) : add.label;
|
216
169
|
} else {
|
@@ -229,12 +182,12 @@ function _getListItems(props, state, rawFilterString) {
|
|
229
182
|
};
|
230
183
|
}
|
231
184
|
function getSelectedIndex(selected, data) {
|
232
|
-
|
185
|
+
const firstSelected = Array.isArray(selected) ? selected[0] : selected;
|
233
186
|
if (firstSelected == null) {
|
234
187
|
return null;
|
235
188
|
}
|
236
|
-
for (
|
237
|
-
|
189
|
+
for (let i = 0; i < data.length; i++) {
|
190
|
+
const item = data[i];
|
238
191
|
if (item.key === undefined) {
|
239
192
|
continue;
|
240
193
|
}
|
@@ -244,28 +197,26 @@ function getSelectedIndex(selected, data) {
|
|
244
197
|
}
|
245
198
|
return null;
|
246
199
|
}
|
247
|
-
|
248
|
-
|
249
|
-
|
200
|
+
const getItemLabel = _ref => {
|
201
|
+
let {
|
202
|
+
selectedLabel,
|
203
|
+
label
|
204
|
+
} = _ref;
|
250
205
|
if (selectedLabel != null) {
|
251
206
|
return selectedLabel;
|
252
207
|
}
|
253
208
|
return typeof label === 'string' ? label : '';
|
254
209
|
};
|
255
|
-
|
256
|
-
return selected && !isArray(selected) && _isInputMode(type) ? getItemLabel(selected) : filterValue;
|
257
|
-
};
|
210
|
+
const getValueForFilter = (selected, type, filterValue) => selected && !isArray(selected) && isInputMode(type) ? getItemLabel(selected) : filterValue;
|
258
211
|
function isSameSelected(prevSelected, selected) {
|
259
212
|
if (!prevSelected || !selected || prevSelected.length !== selected.length) {
|
260
213
|
return false;
|
261
214
|
}
|
262
|
-
|
215
|
+
const keysMap = selected.reduce((result, item) => {
|
263
216
|
result[item.key] = true;
|
264
217
|
return result;
|
265
218
|
}, {});
|
266
|
-
return prevSelected.every(
|
267
|
-
return keysMap[it.key];
|
268
|
-
});
|
219
|
+
return prevSelected.every(it => keysMap[it.key]);
|
269
220
|
}
|
270
221
|
/**
|
271
222
|
* @name Select
|
@@ -275,216 +226,538 @@ function isSameSelected(prevSelected, selected) {
|
|
275
226
|
/**
|
276
227
|
* Displays a select.
|
277
228
|
*/
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
229
|
+
class Select extends Component {
|
230
|
+
static defaultProps = {
|
231
|
+
data: [],
|
232
|
+
filter: false,
|
233
|
+
// enable filter (not in INPUT modes)
|
234
|
+
filterIcon: null,
|
235
|
+
filterRef: noop,
|
236
|
+
multiple: false,
|
237
|
+
// multiple can be an object - see demo for more information
|
238
|
+
clear: false,
|
239
|
+
// enable clear button that clears the "selected" state
|
240
|
+
loading: false,
|
241
|
+
// show a loading indicator while data is loading
|
242
|
+
disabled: false,
|
243
|
+
// disable select
|
244
|
+
type: Type.BUTTON,
|
245
|
+
size: Size.M,
|
246
|
+
targetElement: null,
|
247
|
+
// element to bind the popup to (select BUTTON or INPUT by default)
|
248
|
+
hideSelected: false,
|
249
|
+
// INPUT mode: clears the input after an option is selected (useful when the selection is displayed in some custom way elsewhere)
|
250
|
+
allowAny: false,
|
251
|
+
// INPUT mode: allows any value to be entered
|
252
|
+
hideArrow: false,
|
253
|
+
// hide dropdown arrow icon
|
254
|
+
showPopup: false,
|
255
|
+
maxHeight: 600,
|
256
|
+
// height of the options list, including the filter and the 'Add' button
|
257
|
+
directions: [Popup.PopupProps.Directions.BOTTOM_RIGHT, Popup.PopupProps.Directions.BOTTOM_LEFT, Popup.PopupProps.Directions.TOP_LEFT, Popup.PopupProps.Directions.TOP_RIGHT],
|
258
|
+
selected: null,
|
259
|
+
// current selection (item / array of items)
|
260
|
+
label: null,
|
261
|
+
// BUTTON or INPUT label (nothing selected)
|
262
|
+
selectedLabel: null,
|
263
|
+
// BUTTON or INPUT label (something selected)
|
264
|
+
inputPlaceholder: '',
|
265
|
+
// Placeholder for input modes
|
266
|
+
hint: null,
|
267
|
+
// hint text to display under the list
|
268
|
+
shortcutsEnabled: false,
|
269
|
+
onBeforeOpen: noop,
|
270
|
+
onLoadMore: noop,
|
271
|
+
onOpen: noop,
|
272
|
+
onClose: noop,
|
273
|
+
onFilter: noop,
|
274
|
+
// search string as first argument
|
275
|
+
onFocus: noop,
|
276
|
+
onBlur: noop,
|
277
|
+
onKeyDown: noop,
|
278
|
+
onSelect: noop,
|
279
|
+
// single + multi
|
280
|
+
onDeselect: noop,
|
281
|
+
// multi
|
282
|
+
onOutsideClick: noop,
|
283
|
+
// multi
|
284
|
+
onChange: noop,
|
285
|
+
// multi
|
286
|
+
onAdd: noop,
|
287
|
+
// search string as first argument
|
288
|
+
onDone: noop,
|
289
|
+
onReset: noop,
|
290
|
+
tags: null,
|
291
|
+
ringPopupTarget: null,
|
292
|
+
dir: 'ltr'
|
293
|
+
};
|
294
|
+
static getDerivedStateFromProps(nextProps, prevState) {
|
295
|
+
const {
|
296
|
+
multiple,
|
297
|
+
data,
|
298
|
+
type
|
299
|
+
} = nextProps;
|
300
|
+
const {
|
301
|
+
prevSelected,
|
302
|
+
prevData,
|
303
|
+
prevMultiple,
|
304
|
+
filterValue
|
305
|
+
} = prevState;
|
306
|
+
const nextState = {
|
307
|
+
prevData: data,
|
308
|
+
prevSelected: nextProps.selected,
|
309
|
+
prevMultiple: multiple
|
310
|
+
};
|
311
|
+
if ('data' in nextProps && data !== prevData) {
|
312
|
+
const {
|
313
|
+
filteredData,
|
314
|
+
addButton
|
315
|
+
} = getListItems(nextProps, prevState, filterValue, data);
|
316
|
+
Object.assign(nextState, {
|
317
|
+
shownData: filteredData,
|
318
|
+
addButton
|
309
319
|
});
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
if (_this._popup && _this._popup.isVisible() && !_this._popup.isClickingPopup) {
|
315
|
-
window.setTimeout(function () {
|
316
|
-
_this.setState({
|
317
|
-
showPopup: false
|
318
|
-
});
|
319
|
-
});
|
320
|
-
}
|
321
|
-
if (!((_this$_popup = _this._popup) !== null && _this$_popup !== void 0 && _this$_popup.isClickingPopup)) {
|
322
|
-
_this.setState({
|
323
|
-
shortcutsEnabled: false,
|
324
|
-
focused: false
|
320
|
+
if (prevState.selected) {
|
321
|
+
Object.assign(nextState, {
|
322
|
+
selectedIndex: getSelectedIndex(prevState.selected, data),
|
323
|
+
filterValue: getValueForFilter(prevState.selected, type, filterValue)
|
325
324
|
});
|
326
325
|
}
|
327
|
-
}
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
_defineProperty(_this, "_popup", null);
|
333
|
-
_defineProperty(_this, "onEmptyPopupEnter", function () {
|
334
|
-
if (_this.state.addButton) {
|
335
|
-
_this.addHandler();
|
336
|
-
}
|
337
|
-
});
|
338
|
-
_defineProperty(_this, "focus", function () {
|
339
|
-
var _this$node;
|
340
|
-
var focusableSelectExists = (_this$node = _this.node) === null || _this$node === void 0 ? void 0 : _this$node.querySelector('[data-test~=ring-select__focus]');
|
341
|
-
var restoreFocusNode = _this.props.targetElement || focusableSelectExists;
|
342
|
-
restoreFocusNode === null || restoreFocusNode === void 0 || restoreFocusNode.focus();
|
343
|
-
});
|
344
|
-
_defineProperty(_this, "_onEnter", function () {
|
345
|
-
var _this$_popup2;
|
346
|
-
if (_this.state.addButton && _this.state.shownData.length === 0) {
|
347
|
-
_this.addHandler();
|
348
|
-
}
|
349
|
-
_this.props.onDone();
|
350
|
-
if (!((_this$_popup2 = _this._popup) !== null && _this$_popup2 !== void 0 && _this$_popup2.isVisible()) && _this.props.allowAny) {
|
351
|
-
return true;
|
352
|
-
}
|
353
|
-
return undefined;
|
354
|
-
});
|
355
|
-
_defineProperty(_this, "_onEsc", function (event) {
|
356
|
-
var _this$_popup3;
|
357
|
-
if (!((_this$_popup3 = _this._popup) !== null && _this$_popup3 !== void 0 && _this$_popup3.isVisible())) {
|
358
|
-
return true;
|
359
|
-
} else if (_this.props.multiple || !_this.props.getInitial) {
|
360
|
-
return false;
|
361
|
-
}
|
362
|
-
var selected = {
|
363
|
-
key: Math.random(),
|
364
|
-
label: _this.props.getInitial()
|
365
|
-
};
|
366
|
-
_this.setState({
|
326
|
+
}
|
327
|
+
if ('selected' in nextProps && nextProps.selected !== prevSelected) {
|
328
|
+
const selected = nextProps.selected || (multiple ? [] : null);
|
329
|
+
const selectedIndex = getSelectedIndex(selected, data || prevData);
|
330
|
+
Object.assign(nextState, {
|
367
331
|
selected,
|
368
|
-
filterValue:
|
369
|
-
}, function () {
|
370
|
-
_this.props.onChange(selected, event);
|
371
|
-
_this.props.onReset();
|
332
|
+
filterValue: getValueForFilter(selected, type, filterValue)
|
372
333
|
});
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
_this._clickHandler();
|
378
|
-
}
|
379
|
-
});
|
380
|
-
_defineProperty(_this, "popupRef", function (el) {
|
381
|
-
_this._popup = el;
|
382
|
-
});
|
383
|
-
_defineProperty(_this, "_showPopup", function () {
|
384
|
-
if (!_this.node) {
|
385
|
-
return;
|
334
|
+
if (!Array.isArray(prevSelected) || !Array.isArray(selected) || !isSameSelected(prevSelected, selected)) {
|
335
|
+
Object.assign(nextState, {
|
336
|
+
selectedIndex
|
337
|
+
});
|
386
338
|
}
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
339
|
+
}
|
340
|
+
if (prevMultiple !== multiple && !deepEqual(prevMultiple, multiple)) {
|
341
|
+
nextState.selected = multiple ? [] : null;
|
342
|
+
}
|
343
|
+
if (multiple && !nextState.selected) {
|
344
|
+
nextState.selected = prevState.selected;
|
345
|
+
}
|
346
|
+
const {
|
347
|
+
selected
|
348
|
+
} = {
|
349
|
+
...prevState,
|
350
|
+
...nextState
|
351
|
+
};
|
352
|
+
if (selected && Array.isArray(selected)) {
|
353
|
+
nextState.multipleMap = buildMultipleMap(selected);
|
354
|
+
const {
|
355
|
+
filteredData,
|
356
|
+
addButton
|
357
|
+
} = getListItems(nextProps, nextState, filterValue, data);
|
358
|
+
Object.assign(nextState, {
|
359
|
+
shownData: filteredData,
|
360
|
+
addButton
|
391
361
|
});
|
362
|
+
}
|
363
|
+
return nextState;
|
364
|
+
}
|
365
|
+
state = {
|
366
|
+
data: [],
|
367
|
+
shownData: [],
|
368
|
+
selected: this.props.multiple ? [] : null,
|
369
|
+
selectedIndex: null,
|
370
|
+
filterValue: this.props.filter && typeof this.props.filter === 'object' && this.props.filter.value || '',
|
371
|
+
shortcutsEnabled: false,
|
372
|
+
popupShortcuts: false,
|
373
|
+
showPopup: this.props.showPopup,
|
374
|
+
prevData: this.props.data,
|
375
|
+
prevSelected: null,
|
376
|
+
prevMultiple: this.props.multiple,
|
377
|
+
multipleMap: {},
|
378
|
+
addButton: null
|
379
|
+
};
|
380
|
+
componentDidUpdate(prevProps, prevState) {
|
381
|
+
const {
|
382
|
+
showPopup,
|
383
|
+
selected
|
384
|
+
} = this.state;
|
385
|
+
const {
|
386
|
+
onClose,
|
387
|
+
onOpen,
|
388
|
+
onChange,
|
389
|
+
multiple
|
390
|
+
} = this.props;
|
391
|
+
if (prevState.showPopup && !showPopup) {
|
392
|
+
onClose(selected);
|
393
|
+
} else if (!prevState.showPopup && showPopup) {
|
394
|
+
onOpen();
|
395
|
+
}
|
396
|
+
if (multiple !== prevProps.multiple && !deepEqual(multiple, prevProps.multiple)) {
|
397
|
+
onChange(selected);
|
398
|
+
}
|
399
|
+
}
|
400
|
+
static contextType = ControlsHeightContext;
|
401
|
+
static Type = Type;
|
402
|
+
static Size = Size;
|
403
|
+
id = getUID('select-');
|
404
|
+
shortcutsScope = this.id;
|
405
|
+
listId = `${this.id}:list`;
|
406
|
+
_focusHandler = e => {
|
407
|
+
this.props.onFocus(e);
|
408
|
+
this.setState({
|
409
|
+
shortcutsEnabled: true,
|
410
|
+
focused: true
|
392
411
|
});
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
412
|
+
};
|
413
|
+
_blurHandler = () => {
|
414
|
+
this.props.onBlur();
|
415
|
+
if (this._popup && this._popup.isVisible() && !this._popup.isClickingPopup) {
|
416
|
+
window.setTimeout(() => {
|
417
|
+
this.setState({
|
418
|
+
showPopup: false
|
400
419
|
});
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
420
|
+
});
|
421
|
+
}
|
422
|
+
if (!this._popup?.isClickingPopup) {
|
423
|
+
this.setState({
|
424
|
+
shortcutsEnabled: false,
|
425
|
+
focused: false
|
426
|
+
});
|
427
|
+
}
|
428
|
+
};
|
429
|
+
node;
|
430
|
+
nodeRef = el => {
|
431
|
+
this.node = el;
|
432
|
+
};
|
433
|
+
_popup = null;
|
434
|
+
onEmptyPopupEnter = () => {
|
435
|
+
if (this.state.addButton) {
|
436
|
+
this.addHandler();
|
437
|
+
}
|
438
|
+
};
|
439
|
+
focus = () => {
|
440
|
+
const focusableSelectExists = this.node?.querySelector('[data-test~=ring-select__focus]');
|
441
|
+
const restoreFocusNode = this.props.targetElement || focusableSelectExists;
|
442
|
+
restoreFocusNode?.focus();
|
443
|
+
};
|
444
|
+
_onEnter = () => {
|
445
|
+
if (this.state.addButton && this.state.shownData.length === 0) {
|
446
|
+
this.addHandler();
|
447
|
+
}
|
448
|
+
this.props.onDone();
|
449
|
+
if (!this._popup?.isVisible() && this.props.allowAny) {
|
450
|
+
return true;
|
451
|
+
}
|
452
|
+
return undefined;
|
453
|
+
};
|
454
|
+
_onEsc = event => {
|
455
|
+
if (!this._popup?.isVisible()) {
|
456
|
+
return true;
|
457
|
+
} else if (this.props.multiple || !this.props.getInitial) {
|
458
|
+
return false;
|
459
|
+
}
|
460
|
+
const selected = {
|
461
|
+
key: Math.random(),
|
462
|
+
label: this.props.getInitial()
|
463
|
+
};
|
464
|
+
this.setState({
|
465
|
+
selected,
|
466
|
+
filterValue: this.getValueForFilter(selected)
|
467
|
+
}, () => {
|
468
|
+
this.props.onChange(selected, event);
|
469
|
+
this.props.onReset();
|
410
470
|
});
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
471
|
+
return undefined;
|
472
|
+
};
|
473
|
+
_inputShortcutHandler = () => {
|
474
|
+
if (this.state.focused && this._popup && !this._popup.isVisible()) {
|
475
|
+
this._clickHandler();
|
476
|
+
}
|
477
|
+
};
|
478
|
+
getValueForFilter(selected) {
|
479
|
+
return getValueForFilter(selected, this.props.type, this.state.filterValue);
|
480
|
+
}
|
481
|
+
_getSelectedIndex(selected, data) {
|
482
|
+
return getSelectedIndex(selected, data);
|
483
|
+
}
|
484
|
+
popupRef = el => {
|
485
|
+
this._popup = el;
|
486
|
+
};
|
487
|
+
_getResetOption() {
|
488
|
+
const isOptionsSelected = Array.isArray(this.state.selected) && this.state.selected.length;
|
489
|
+
const reset = this.props.tags && typeof this.props.tags === 'object' ? this.props.tags.reset : null;
|
490
|
+
if (!isOptionsSelected || !reset) {
|
491
|
+
return null;
|
492
|
+
}
|
493
|
+
const resetHandler = (item, event) => {
|
494
|
+
this.clear(event);
|
495
|
+
this.clearFilter();
|
496
|
+
this.props.onFilter('');
|
497
|
+
this.setState(prevState => ({
|
498
|
+
shownData: prevState.shownData.slice(reset.separator ? 2 : 1),
|
499
|
+
multipleMap: {}
|
500
|
+
}));
|
501
|
+
this._redrawPopup();
|
502
|
+
};
|
503
|
+
return {
|
504
|
+
isResetItem: true,
|
505
|
+
separator: reset.separator,
|
506
|
+
key: reset.label,
|
507
|
+
rgItemType: List.ListProps.Type.CUSTOM,
|
508
|
+
template: /*#__PURE__*/React.createElement(Button, {
|
509
|
+
text: true,
|
510
|
+
className: modules_9d0de074.button,
|
511
|
+
"data-test": "ring-select-reset-tags-button",
|
512
|
+
height: ControlsHeight.S
|
513
|
+
}, reset.label),
|
514
|
+
glyph: reset.glyph,
|
515
|
+
onClick: resetHandler
|
516
|
+
};
|
517
|
+
}
|
518
|
+
_prependResetOption(shownData) {
|
519
|
+
const resetOption = this._getResetOption();
|
520
|
+
if (resetOption) {
|
521
|
+
const resetItems = [resetOption];
|
522
|
+
if (resetOption.separator) {
|
523
|
+
resetItems.push({
|
524
|
+
rgItemType: List.ListProps.Type.SEPARATOR
|
525
|
+
});
|
421
526
|
}
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
527
|
+
return resetItems.concat(shownData);
|
528
|
+
}
|
529
|
+
return shownData;
|
530
|
+
}
|
531
|
+
_renderPopup() {
|
532
|
+
const anchorElement = this.props.targetElement || this.node;
|
533
|
+
const {
|
534
|
+
showPopup,
|
535
|
+
shownData
|
536
|
+
} = this.state;
|
537
|
+
const _shownData = this._prependResetOption(shownData);
|
538
|
+
return /*#__PURE__*/React.createElement(I18nContext.Consumer, null, _ref2 => {
|
539
|
+
let {
|
540
|
+
translate
|
541
|
+
} = _ref2;
|
542
|
+
let message;
|
543
|
+
if (this.props.loading) {
|
544
|
+
var _this$props$loadingMe;
|
545
|
+
message = (_this$props$loadingMe = this.props.loadingMessage) !== null && _this$props$loadingMe !== void 0 ? _this$props$loadingMe : translate('loading');
|
546
|
+
} else if (!shownData.length) {
|
547
|
+
var _this$props$notFoundM;
|
548
|
+
message = (_this$props$notFoundM = this.props.notFoundMessage) !== null && _this$props$notFoundM !== void 0 ? _this$props$notFoundM : translate('noOptionsFound');
|
426
549
|
}
|
427
|
-
|
428
|
-
|
550
|
+
return /*#__PURE__*/React.createElement(SelectPopup, {
|
551
|
+
data: _shownData,
|
552
|
+
message: message,
|
553
|
+
toolbar: showPopup && this.getToolbar(),
|
554
|
+
topbar: this.getTopbar(),
|
555
|
+
loading: this.props.loading,
|
556
|
+
activeIndex: this.state.selectedIndex,
|
557
|
+
hidden: !showPopup,
|
558
|
+
ref: this.popupRef,
|
559
|
+
maxHeight: this.props.maxHeight,
|
560
|
+
minWidth: this.props.minWidth,
|
561
|
+
directions: this.props.directions,
|
562
|
+
className: this.props.popupClassName,
|
563
|
+
style: this.props.popupStyle,
|
564
|
+
top: this.props.top,
|
565
|
+
left: this.props.left,
|
566
|
+
filter: this.isInputMode() ? false : this.props.filter // disable popup filter in INPUT mode
|
567
|
+
,
|
568
|
+
filterIcon: this.props.filterIcon,
|
569
|
+
filterRef: this.props.filterRef,
|
570
|
+
multiple: this.props.multiple,
|
571
|
+
filterValue: this.state.filterValue,
|
572
|
+
anchorElement: anchorElement,
|
573
|
+
onCloseAttempt: this._onCloseAttempt,
|
574
|
+
onOutsideClick: this.props.onOutsideClick,
|
575
|
+
onSelect: this._listSelectHandler,
|
576
|
+
onSelectAll: this._listSelectAllHandler,
|
577
|
+
onFilter: this._filterChangeHandler,
|
578
|
+
onClear: this.clearFilter,
|
579
|
+
onLoadMore: this.props.onLoadMore,
|
580
|
+
isInputMode: this.isInputMode(),
|
581
|
+
selected: this.state.selected,
|
582
|
+
tags: this.props.tags,
|
583
|
+
compact: this.props.compact,
|
584
|
+
renderOptimization: this.props.renderOptimization,
|
585
|
+
ringPopupTarget: this.props.ringPopupTarget,
|
586
|
+
disableMoveOverflow: this.props.disableMoveOverflow,
|
587
|
+
disableScrollToActive: this.props.disableScrollToActive,
|
588
|
+
dir: this.props.dir,
|
589
|
+
onEmptyPopupEnter: this.onEmptyPopupEnter,
|
590
|
+
listId: this.listId,
|
591
|
+
preventListOverscroll: this.props.preventListOverscroll
|
592
|
+
});
|
429
593
|
});
|
430
|
-
|
431
|
-
|
594
|
+
}
|
595
|
+
_showPopup = () => {
|
596
|
+
if (!this.node) {
|
597
|
+
return;
|
598
|
+
}
|
599
|
+
const shownData = this.getListItems(this.filterValue());
|
600
|
+
this.setState({
|
601
|
+
showPopup: true,
|
602
|
+
shownData
|
432
603
|
});
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
_this.props.onFilter(filterValue);
|
443
|
-
if (_this.props.allowAny) {
|
444
|
-
var fakeSelected = {
|
445
|
-
key: Math.random(),
|
446
|
-
label: filterValue
|
447
|
-
};
|
448
|
-
_this.setState({
|
449
|
-
selected: filterValue === '' ? null : fakeSelected,
|
450
|
-
selectedIndex: null
|
451
|
-
}, function () {
|
452
|
-
_this.props.onSelect(fakeSelected, event);
|
453
|
-
_this.props.onChange(fakeSelected, event);
|
454
|
-
});
|
604
|
+
};
|
605
|
+
_hidePopup = tryFocusAnchor => {
|
606
|
+
if (this.node && this.state.showPopup) {
|
607
|
+
this.setState(prevState => ({
|
608
|
+
showPopup: false,
|
609
|
+
filterValue: this.props.allowAny ? prevState.filterValue : ''
|
610
|
+
}));
|
611
|
+
if (tryFocusAnchor) {
|
612
|
+
this.focus();
|
455
613
|
}
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
614
|
+
}
|
615
|
+
};
|
616
|
+
addHandler = () => {
|
617
|
+
const value = this.filterValue();
|
618
|
+
this._hidePopup();
|
619
|
+
this.props.onAdd(value);
|
620
|
+
};
|
621
|
+
getToolbar() {
|
622
|
+
const {
|
623
|
+
hint,
|
624
|
+
renderBottomToolbar
|
625
|
+
} = this.props;
|
626
|
+
const {
|
627
|
+
prefix,
|
628
|
+
label,
|
629
|
+
delayed
|
630
|
+
} = this.state.addButton || {};
|
631
|
+
const isToolbarHasElements = this.state.addButton || hint || renderBottomToolbar;
|
632
|
+
if (!isToolbarHasElements) {
|
633
|
+
return null;
|
634
|
+
}
|
635
|
+
return /*#__PURE__*/React.createElement("div", {
|
636
|
+
className: classNames({
|
637
|
+
[modules_9d0de074.toolbar]: Boolean(this.state.addButton || renderBottomToolbar)
|
638
|
+
}),
|
639
|
+
"data-test": "ring-select-toolbar"
|
640
|
+
}, renderBottomToolbar && renderBottomToolbar(), this.state.addButton && /*#__PURE__*/React.createElement(Button, {
|
641
|
+
text: true,
|
642
|
+
delayed: delayed,
|
643
|
+
className: classNames(modules_9d0de074.button, modules_9d0de074.buttonSpaced),
|
644
|
+
onClick: this.addHandler,
|
645
|
+
"data-test": "ring-select-toolbar-button"
|
646
|
+
}, prefix ? `${prefix} ${label}` : label), hint && /*#__PURE__*/React.createElement(List.ListHint, {
|
647
|
+
label: hint,
|
648
|
+
"data-test": "ring-select-toolbar-hint"
|
649
|
+
}));
|
650
|
+
}
|
651
|
+
getTopbar() {
|
652
|
+
return this.props.renderTopToolbar?.();
|
653
|
+
}
|
654
|
+
getLowerCaseLabel = getLowerCaseLabel;
|
655
|
+
doesLabelMatch = doesLabelMatch;
|
656
|
+
getFilterFn() {
|
657
|
+
return getFilterFn(this.props.filter);
|
658
|
+
}
|
659
|
+
getListItems(rawFilterString, data) {
|
660
|
+
const {
|
661
|
+
filteredData,
|
662
|
+
addButton
|
663
|
+
} = getListItems(this.props, this.state, rawFilterString, data);
|
664
|
+
this.setState({
|
665
|
+
addButton
|
462
666
|
});
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
667
|
+
return filteredData;
|
668
|
+
}
|
669
|
+
filterValue(setValue) {
|
670
|
+
if (typeof setValue === 'string' || typeof setValue === 'number') {
|
671
|
+
this.setState({
|
672
|
+
filterValue: setValue
|
673
|
+
});
|
674
|
+
return undefined;
|
675
|
+
} else {
|
676
|
+
return this.state.filterValue;
|
677
|
+
}
|
678
|
+
}
|
679
|
+
isInputMode() {
|
680
|
+
return isInputMode(this.props.type);
|
681
|
+
}
|
682
|
+
_clickHandler = () => {
|
683
|
+
if (!this.props.disabled) {
|
684
|
+
if (this.state.showPopup) {
|
685
|
+
this._hidePopup();
|
686
|
+
} else {
|
687
|
+
this.props.onBeforeOpen();
|
688
|
+
this._showPopup();
|
469
689
|
}
|
690
|
+
}
|
691
|
+
};
|
692
|
+
_openPopupIfClosed = () => {
|
693
|
+
if (this.props.disabled || this.state.showPopup) {
|
694
|
+
return;
|
695
|
+
}
|
696
|
+
this.props.onBeforeOpen();
|
697
|
+
this._showPopup();
|
698
|
+
};
|
699
|
+
_filterChangeHandler = e => {
|
700
|
+
this._setFilter(e.currentTarget.value, e);
|
701
|
+
};
|
702
|
+
_setFilter = (value, event) => {
|
703
|
+
if (this.isInputMode() && !this.state.focused) {
|
704
|
+
return;
|
705
|
+
}
|
706
|
+
if (value === this.state.filterValue) {
|
707
|
+
return;
|
708
|
+
}
|
709
|
+
const filterValue = value.replace(/^\s+/g, '');
|
710
|
+
this.props.onFilter(filterValue);
|
711
|
+
if (this.props.allowAny) {
|
712
|
+
const fakeSelected = {
|
713
|
+
key: Math.random(),
|
714
|
+
label: filterValue
|
715
|
+
};
|
716
|
+
this.setState({
|
717
|
+
selected: filterValue === '' ? null : fakeSelected,
|
718
|
+
selectedIndex: null
|
719
|
+
}, () => {
|
720
|
+
this.props.onSelect(fakeSelected, event);
|
721
|
+
this.props.onChange(fakeSelected, event);
|
722
|
+
});
|
723
|
+
}
|
724
|
+
!this._popup?.isVisible() && this.props.onBeforeOpen();
|
725
|
+
this.setState({
|
726
|
+
filterValue
|
727
|
+
}, () => {
|
728
|
+
this._showPopup();
|
470
729
|
});
|
471
|
-
|
730
|
+
};
|
731
|
+
_rebuildMultipleMap(selected) {
|
732
|
+
if (Array.isArray(selected)) {
|
733
|
+
this.setState({
|
734
|
+
multipleMap: buildMultipleMap(selected)
|
735
|
+
});
|
736
|
+
}
|
737
|
+
}
|
738
|
+
_redrawPopup = () => {
|
739
|
+
if (this.props.multiple) {
|
740
|
+
setTimeout(() => {
|
741
|
+
this.isInputMode() && this.clearFilter();
|
742
|
+
this._showPopup();
|
743
|
+
}, 0);
|
744
|
+
}
|
745
|
+
};
|
746
|
+
_listSelectHandler = (() => {
|
747
|
+
var _this = this;
|
748
|
+
return function (selected, event) {
|
472
749
|
var _this$props$tryKeepOp;
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
var isCustomItem = function isCustomItem(item) {
|
478
|
-
return List.isItemType(List.ListProps.Type.CUSTOM, item);
|
479
|
-
};
|
480
|
-
var isSelectItemEvent = event && (event.type === 'select' || event.type === 'keydown');
|
750
|
+
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
751
|
+
const isItem = item => List.isItemType(List.ListProps.Type.ITEM, item);
|
752
|
+
const isCustomItem = item => List.isItemType(List.ListProps.Type.CUSTOM, item);
|
753
|
+
const isSelectItemEvent = event && (event.type === 'select' || event.type === 'keydown');
|
481
754
|
if (isSelectItemEvent) {
|
482
755
|
event.preventDefault();
|
483
756
|
}
|
484
757
|
if (!isItem(selected) && !isCustomItem(selected) || selected.disabled || selected.isResetItem) {
|
485
758
|
return;
|
486
759
|
}
|
487
|
-
|
760
|
+
const tryKeepOpen = (_this$props$tryKeepOp = _this.props.tryKeepOpen) !== null && _this$props$tryKeepOp !== void 0 ? _this$props$tryKeepOp : opts.tryKeepOpen;
|
488
761
|
if (!_this.props.multiple) {
|
489
762
|
if (!tryKeepOpen) {
|
490
763
|
_this._hidePopup(isSelectItemEvent);
|
@@ -492,8 +765,8 @@ var Select = /*#__PURE__*/function (_Component) {
|
|
492
765
|
_this.setState({
|
493
766
|
selected,
|
494
767
|
selectedIndex: _this._getSelectedIndex(selected, _this.props.data)
|
495
|
-
},
|
496
|
-
|
768
|
+
}, () => {
|
769
|
+
const newFilterValue = _this.isInputMode() && !_this.props.hideSelected ? getItemLabel(selected) : '';
|
497
770
|
_this.filterValue(newFilterValue);
|
498
771
|
_this.props.onFilter(newFilterValue);
|
499
772
|
_this.props.onSelect(selected, event);
|
@@ -506,737 +779,359 @@ var Select = /*#__PURE__*/function (_Component) {
|
|
506
779
|
if (selected.key == null) {
|
507
780
|
throw new Error('Multiple selection requires each item to have the "key" property');
|
508
781
|
}
|
509
|
-
_this.setState(
|
510
|
-
|
511
|
-
|
782
|
+
_this.setState(prevState => {
|
783
|
+
const currentSelection = prevState.selected;
|
784
|
+
let nextSelection;
|
512
785
|
if (!prevState.multipleMap[selected.key]) {
|
513
786
|
nextSelection = currentSelection.concat(selected);
|
514
787
|
_this.props.onSelect && _this.props.onSelect(selected, event);
|
515
788
|
} else {
|
516
|
-
nextSelection = currentSelection.filter(
|
517
|
-
return item.key !== selected.key;
|
518
|
-
});
|
789
|
+
nextSelection = currentSelection.filter(item => item.key !== selected.key);
|
519
790
|
_this.props.onDeselect && _this.props.onDeselect(selected);
|
520
791
|
}
|
521
792
|
_this.props.onChange(nextSelection, event);
|
522
|
-
|
793
|
+
const nextState = {
|
523
794
|
filterValue: '',
|
524
795
|
selected: nextSelection,
|
525
796
|
selectedIndex: _this._getSelectedIndex(selected, _this.props.data)
|
526
797
|
};
|
527
798
|
if (typeof _this.props.multiple === 'object' && _this.props.multiple.limit && nextSelection.length === _this.props.multiple.limit) {
|
528
|
-
nextState.shownData = prevState.shownData.map(
|
529
|
-
|
530
|
-
|
531
|
-
}) ? item : _objectSpread2(_objectSpread2({}, item), {}, {
|
532
|
-
disabled: true
|
533
|
-
});
|
799
|
+
nextState.shownData = prevState.shownData.map(item => nextSelection.find(selectedItem => selectedItem.key === item.key) ? item : {
|
800
|
+
...item,
|
801
|
+
disabled: true
|
534
802
|
});
|
535
803
|
}
|
536
804
|
if (!prevState.multipleMap[selected.key]) {
|
537
|
-
nextState.multipleMap =
|
805
|
+
nextState.multipleMap = {
|
806
|
+
...prevState.multipleMap,
|
538
807
|
[selected.key]: true
|
539
|
-
}
|
808
|
+
};
|
540
809
|
} else {
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
810
|
+
const {
|
811
|
+
[selected.key]: _,
|
812
|
+
...restMultipleMap
|
813
|
+
} = prevState.multipleMap;
|
545
814
|
nextState.multipleMap = restMultipleMap;
|
546
815
|
}
|
547
|
-
return
|
548
|
-
|
816
|
+
return {
|
817
|
+
...prevState,
|
818
|
+
...nextState
|
819
|
+
};
|
820
|
+
}, () => {
|
549
821
|
if (tryKeepOpen) {
|
550
822
|
_this._redrawPopup();
|
551
823
|
}
|
552
824
|
});
|
553
825
|
}
|
554
|
-
}
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
var nextSelection;
|
826
|
+
};
|
827
|
+
})();
|
828
|
+
_listSelectAllHandler = (() => {
|
829
|
+
var _this2 = this;
|
830
|
+
return function () {
|
831
|
+
let isSelectAll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
832
|
+
const isItem = item => List.isItemType(List.ListProps.Type.ITEM, item);
|
833
|
+
const isCustomItem = item => List.isItemType(List.ListProps.Type.CUSTOM, item);
|
834
|
+
_this2.setState(prevState => {
|
835
|
+
const currentSelection = prevState.selected;
|
836
|
+
let nextSelection;
|
566
837
|
if (isSelectAll) {
|
567
|
-
nextSelection =
|
568
|
-
|
569
|
-
|
570
|
-
nextSelection.filter(function (item) {
|
571
|
-
return !_this.props.selected.find(function (selectedItem) {
|
572
|
-
return item.key === selectedItem.key;
|
573
|
-
});
|
574
|
-
}).forEach(function (item) {
|
575
|
-
_this.props.onSelect && _this.props.onSelect(item);
|
838
|
+
nextSelection = _this2.props.data.filter(item => (isItem(item) || isCustomItem(item)) && !item.disabled);
|
839
|
+
nextSelection.filter(item => !_this2.props.selected.find(selectedItem => item.key === selectedItem.key)).forEach(item => {
|
840
|
+
_this2.props.onSelect && _this2.props.onSelect(item);
|
576
841
|
});
|
577
842
|
} else {
|
578
843
|
nextSelection = [];
|
579
|
-
currentSelection.forEach(
|
580
|
-
|
844
|
+
currentSelection.forEach(item => {
|
845
|
+
_this2.props.onDeselect && _this2.props.onDeselect(item);
|
581
846
|
});
|
582
847
|
}
|
583
|
-
|
848
|
+
_this2.props.onChange(nextSelection, event);
|
584
849
|
return {
|
585
850
|
filterValue: '',
|
586
851
|
selected: nextSelection,
|
587
|
-
selectedIndex: isSelectAll ?
|
588
|
-
shownData: prevState.shownData.map(
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
}
|
593
|
-
multipleMap: isSelectAll ? buildMultipleMap(_this.props.data.filter(function (item) {
|
594
|
-
return !item.disabled;
|
595
|
-
})) : {}
|
852
|
+
selectedIndex: isSelectAll ? _this2._getSelectedIndex(nextSelection, _this2.props.data) : null,
|
853
|
+
shownData: prevState.shownData.map(item => ({
|
854
|
+
...item,
|
855
|
+
checkbox: isSelectAll
|
856
|
+
})),
|
857
|
+
multipleMap: isSelectAll ? buildMultipleMap(_this2.props.data.filter(item => !item.disabled)) : {}
|
596
858
|
};
|
597
|
-
},
|
598
|
-
}
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
}
|
608
|
-
}
|
609
|
-
var isTagRemoved = _this.props.tags && event && event.target && event.target instanceof Element && event.target.matches('[data-test="ring-tag-remove"]');
|
610
|
-
if (!isTagRemoved) {
|
611
|
-
_this._hidePopup(isEsc);
|
612
|
-
}
|
613
|
-
});
|
614
|
-
_defineProperty(_this, "clearFilter", function (e) {
|
615
|
-
_this._setFilter('', e);
|
616
|
-
});
|
617
|
-
_defineProperty(_this, "clear", function (event) {
|
618
|
-
if (event) {
|
619
|
-
event.stopPropagation();
|
620
|
-
}
|
621
|
-
var empty = _this.props.multiple ? [] : null;
|
622
|
-
_this.setState({
|
623
|
-
selected: empty,
|
624
|
-
selectedIndex: null,
|
625
|
-
filterValue: ''
|
626
|
-
}, function () {
|
627
|
-
if (_this.props.onChange) {
|
628
|
-
_this.props.onChange(empty, event);
|
859
|
+
}, _this2._redrawPopup);
|
860
|
+
};
|
861
|
+
})();
|
862
|
+
_onCloseAttempt = (event, isEsc) => {
|
863
|
+
if (this.isInputMode()) {
|
864
|
+
if (!this.props.allowAny) {
|
865
|
+
if (this.props.hideSelected || !this.state.selected || this.props.multiple) {
|
866
|
+
this.clearFilter();
|
867
|
+
} else if (this.state.selected && !Array.isArray(this.state.selected)) {
|
868
|
+
this.filterValue(getItemLabel(this.state.selected));
|
629
869
|
}
|
630
|
-
});
|
631
|
-
return false;
|
632
|
-
});
|
633
|
-
_defineProperty(_this, "filter", void 0);
|
634
|
-
_defineProperty(_this, "filterRef", function (el) {
|
635
|
-
_this.filter = el;
|
636
|
-
});
|
637
|
-
return _this;
|
638
|
-
}
|
639
|
-
_inherits(Select, _Component);
|
640
|
-
return _createClass(Select, [{
|
641
|
-
key: "componentDidUpdate",
|
642
|
-
value: function componentDidUpdate(prevProps, prevState) {
|
643
|
-
var _this$state = this.state,
|
644
|
-
showPopup = _this$state.showPopup,
|
645
|
-
selected = _this$state.selected;
|
646
|
-
var _this$props = this.props,
|
647
|
-
onClose = _this$props.onClose,
|
648
|
-
onOpen = _this$props.onOpen,
|
649
|
-
onChange = _this$props.onChange,
|
650
|
-
multiple = _this$props.multiple;
|
651
|
-
if (prevState.showPopup && !showPopup) {
|
652
|
-
onClose(selected);
|
653
|
-
} else if (!prevState.showPopup && showPopup) {
|
654
|
-
onOpen();
|
655
|
-
}
|
656
|
-
if (multiple !== prevProps.multiple && !deepEqual(multiple, prevProps.multiple)) {
|
657
|
-
onChange(selected);
|
658
870
|
}
|
659
871
|
}
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
return _getValueForFilter(selected, this.props.type, this.state.filterValue);
|
872
|
+
const isTagRemoved = this.props.tags && event && event.target && event.target instanceof Element && event.target.matches('[data-test="ring-tag-remove"]');
|
873
|
+
if (!isTagRemoved) {
|
874
|
+
this._hidePopup(isEsc);
|
664
875
|
}
|
665
|
-
}
|
666
|
-
|
667
|
-
|
668
|
-
|
876
|
+
};
|
877
|
+
clearFilter = e => {
|
878
|
+
this._setFilter('', e);
|
879
|
+
};
|
880
|
+
clear = event => {
|
881
|
+
if (event) {
|
882
|
+
event.stopPropagation();
|
669
883
|
}
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
if (
|
677
|
-
|
884
|
+
const empty = this.props.multiple ? [] : null;
|
885
|
+
this.setState({
|
886
|
+
selected: empty,
|
887
|
+
selectedIndex: null,
|
888
|
+
filterValue: ''
|
889
|
+
}, () => {
|
890
|
+
if (this.props.onChange) {
|
891
|
+
this.props.onChange(empty, event);
|
678
892
|
}
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
separator: reset.separator,
|
694
|
-
key: reset.label,
|
695
|
-
rgItemType: List.ListProps.Type.CUSTOM,
|
696
|
-
template: /*#__PURE__*/React.createElement(Button, {
|
697
|
-
text: true,
|
698
|
-
className: modules_9d0de074.button,
|
699
|
-
"data-test": "ring-select-reset-tags-button",
|
700
|
-
height: ControlsHeight.S
|
701
|
-
}, reset.label),
|
702
|
-
glyph: reset.glyph,
|
703
|
-
onClick: resetHandler
|
704
|
-
};
|
893
|
+
});
|
894
|
+
return false;
|
895
|
+
};
|
896
|
+
_selectionIsEmpty() {
|
897
|
+
return Array.isArray(this.state.selected) && !this.state.selected.length || !this.state.selected;
|
898
|
+
}
|
899
|
+
_getLabel() {
|
900
|
+
var _ref3, _this$props$label;
|
901
|
+
return (_ref3 = (_this$props$label = this.props.label) !== null && _this$props$label !== void 0 ? _this$props$label : this.props.selectedLabel) !== null && _ref3 !== void 0 ? _ref3 : 'Select an option';
|
902
|
+
}
|
903
|
+
_getPlaceholder() {
|
904
|
+
if (this._selectionIsEmpty()) {
|
905
|
+
var _this$props$label2;
|
906
|
+
return (_this$props$label2 = this.props.label) !== null && _this$props$label2 !== void 0 ? _this$props$label2 : 'Select an option';
|
705
907
|
}
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
resetItems.push({
|
714
|
-
rgItemType: List.ListProps.Type.SEPARATOR
|
715
|
-
});
|
716
|
-
}
|
717
|
-
return resetItems.concat(shownData);
|
908
|
+
return this._getSelectedString();
|
909
|
+
}
|
910
|
+
_getSelectedString() {
|
911
|
+
if (Array.isArray(this.state.selected)) {
|
912
|
+
const labels = [];
|
913
|
+
for (let i = 0; i < this.state.selected.length; i++) {
|
914
|
+
labels.push(getItemLabel(this.state.selected[i]));
|
718
915
|
}
|
719
|
-
return
|
916
|
+
return labels.filter(Boolean).join(', ');
|
917
|
+
} else {
|
918
|
+
return this.state.selected != null ? getItemLabel(this.state.selected) : null;
|
720
919
|
}
|
721
|
-
}
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
920
|
+
}
|
921
|
+
_getIcons() {
|
922
|
+
const {
|
923
|
+
selected
|
924
|
+
} = this.state;
|
925
|
+
const {
|
926
|
+
disabled,
|
927
|
+
clear,
|
928
|
+
hideArrow
|
929
|
+
} = this.props;
|
930
|
+
const icons = [];
|
931
|
+
const height = this.props.height || this.context;
|
932
|
+
if (!Array.isArray(selected) && selected?.icon) {
|
933
|
+
icons.push( /*#__PURE__*/React.createElement("button", {
|
934
|
+
title: "Toggle options popup",
|
935
|
+
type: "button",
|
936
|
+
className: modules_9d0de074.selectedIcon,
|
937
|
+
key: "selected",
|
938
|
+
disabled: this.props.disabled,
|
939
|
+
onClick: this._clickHandler,
|
940
|
+
style: {
|
941
|
+
backgroundImage: `url(${selected.icon})`
|
739
942
|
}
|
740
|
-
return /*#__PURE__*/React.createElement(SelectPopup, {
|
741
|
-
data: _shownData,
|
742
|
-
message: message,
|
743
|
-
toolbar: showPopup && _this3.getToolbar(),
|
744
|
-
topbar: _this3.getTopbar(),
|
745
|
-
loading: _this3.props.loading,
|
746
|
-
activeIndex: _this3.state.selectedIndex,
|
747
|
-
hidden: !showPopup,
|
748
|
-
ref: _this3.popupRef,
|
749
|
-
maxHeight: _this3.props.maxHeight,
|
750
|
-
minWidth: _this3.props.minWidth,
|
751
|
-
directions: _this3.props.directions,
|
752
|
-
className: _this3.props.popupClassName,
|
753
|
-
style: _this3.props.popupStyle,
|
754
|
-
top: _this3.props.top,
|
755
|
-
left: _this3.props.left,
|
756
|
-
filter: _this3.isInputMode() ? false : _this3.props.filter // disable popup filter in INPUT mode
|
757
|
-
,
|
758
|
-
filterIcon: _this3.props.filterIcon,
|
759
|
-
filterRef: _this3.props.filterRef,
|
760
|
-
multiple: _this3.props.multiple,
|
761
|
-
filterValue: _this3.state.filterValue,
|
762
|
-
anchorElement: anchorElement,
|
763
|
-
onCloseAttempt: _this3._onCloseAttempt,
|
764
|
-
onOutsideClick: _this3.props.onOutsideClick,
|
765
|
-
onSelect: _this3._listSelectHandler,
|
766
|
-
onSelectAll: _this3._listSelectAllHandler,
|
767
|
-
onFilter: _this3._filterChangeHandler,
|
768
|
-
onClear: _this3.clearFilter,
|
769
|
-
onLoadMore: _this3.props.onLoadMore,
|
770
|
-
isInputMode: _this3.isInputMode(),
|
771
|
-
selected: _this3.state.selected,
|
772
|
-
tags: _this3.props.tags,
|
773
|
-
compact: _this3.props.compact,
|
774
|
-
renderOptimization: _this3.props.renderOptimization,
|
775
|
-
ringPopupTarget: _this3.props.ringPopupTarget,
|
776
|
-
disableMoveOverflow: _this3.props.disableMoveOverflow,
|
777
|
-
disableScrollToActive: _this3.props.disableScrollToActive,
|
778
|
-
dir: _this3.props.dir,
|
779
|
-
onEmptyPopupEnter: _this3.onEmptyPopupEnter,
|
780
|
-
listId: _this3.listId,
|
781
|
-
preventListOverscroll: _this3.props.preventListOverscroll
|
782
|
-
});
|
783
|
-
});
|
784
|
-
}
|
785
|
-
}, {
|
786
|
-
key: "getToolbar",
|
787
|
-
value: function getToolbar() {
|
788
|
-
var _this$props2 = this.props,
|
789
|
-
hint = _this$props2.hint,
|
790
|
-
renderBottomToolbar = _this$props2.renderBottomToolbar;
|
791
|
-
var _ref3 = this.state.addButton || {},
|
792
|
-
prefix = _ref3.prefix,
|
793
|
-
label = _ref3.label,
|
794
|
-
delayed = _ref3.delayed;
|
795
|
-
var isToolbarHasElements = this.state.addButton || hint || renderBottomToolbar;
|
796
|
-
if (!isToolbarHasElements) {
|
797
|
-
return null;
|
798
|
-
}
|
799
|
-
return /*#__PURE__*/React.createElement("div", {
|
800
|
-
className: classNames({
|
801
|
-
[modules_9d0de074.toolbar]: Boolean(this.state.addButton || renderBottomToolbar)
|
802
|
-
}),
|
803
|
-
"data-test": "ring-select-toolbar"
|
804
|
-
}, renderBottomToolbar && renderBottomToolbar(), this.state.addButton && /*#__PURE__*/React.createElement(Button, {
|
805
|
-
text: true,
|
806
|
-
delayed: delayed,
|
807
|
-
className: classNames(modules_9d0de074.button, modules_9d0de074.buttonSpaced),
|
808
|
-
onClick: this.addHandler,
|
809
|
-
"data-test": "ring-select-toolbar-button"
|
810
|
-
}, prefix ? "".concat(prefix, " ").concat(label) : label), hint && /*#__PURE__*/React.createElement(List.ListHint, {
|
811
|
-
label: hint,
|
812
|
-
"data-test": "ring-select-toolbar-hint"
|
813
943
|
}));
|
814
944
|
}
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
}, {
|
827
|
-
key: "getListItems",
|
828
|
-
value: function getListItems(rawFilterString, data) {
|
829
|
-
var _getListItems2 = _getListItems(this.props, this.state, rawFilterString, data),
|
830
|
-
filteredData = _getListItems2.filteredData,
|
831
|
-
addButton = _getListItems2.addButton;
|
832
|
-
this.setState({
|
833
|
-
addButton
|
834
|
-
});
|
835
|
-
return filteredData;
|
836
|
-
}
|
837
|
-
}, {
|
838
|
-
key: "filterValue",
|
839
|
-
value: function filterValue(setValue) {
|
840
|
-
if (typeof setValue === 'string' || typeof setValue === 'number') {
|
841
|
-
this.setState({
|
842
|
-
filterValue: setValue
|
843
|
-
});
|
844
|
-
return undefined;
|
845
|
-
} else {
|
846
|
-
return this.state.filterValue;
|
847
|
-
}
|
848
|
-
}
|
849
|
-
}, {
|
850
|
-
key: "isInputMode",
|
851
|
-
value: function isInputMode() {
|
852
|
-
return _isInputMode(this.props.type);
|
853
|
-
}
|
854
|
-
}, {
|
855
|
-
key: "_rebuildMultipleMap",
|
856
|
-
value: function _rebuildMultipleMap(selected) {
|
857
|
-
if (Array.isArray(selected)) {
|
858
|
-
this.setState({
|
859
|
-
multipleMap: buildMultipleMap(selected)
|
860
|
-
});
|
861
|
-
}
|
862
|
-
}
|
863
|
-
}, {
|
864
|
-
key: "_selectionIsEmpty",
|
865
|
-
value: function _selectionIsEmpty() {
|
866
|
-
return Array.isArray(this.state.selected) && !this.state.selected.length || !this.state.selected;
|
867
|
-
}
|
868
|
-
}, {
|
869
|
-
key: "_getLabel",
|
870
|
-
value: function _getLabel() {
|
871
|
-
var _ref4, _this$props$label;
|
872
|
-
return (_ref4 = (_this$props$label = this.props.label) !== null && _this$props$label !== void 0 ? _this$props$label : this.props.selectedLabel) !== null && _ref4 !== void 0 ? _ref4 : 'Select an option';
|
873
|
-
}
|
874
|
-
}, {
|
875
|
-
key: "_getPlaceholder",
|
876
|
-
value: function _getPlaceholder() {
|
877
|
-
if (this._selectionIsEmpty()) {
|
878
|
-
var _this$props$label2;
|
879
|
-
return (_this$props$label2 = this.props.label) !== null && _this$props$label2 !== void 0 ? _this$props$label2 : 'Select an option';
|
880
|
-
}
|
881
|
-
return this._getSelectedString();
|
945
|
+
if (clear && !disabled && !this._selectionIsEmpty()) {
|
946
|
+
icons.push( /*#__PURE__*/React.createElement(Button, {
|
947
|
+
title: "Clear selection",
|
948
|
+
"data-test": "ring-clear-select",
|
949
|
+
className: modules_9d0de074.clearIcon,
|
950
|
+
key: "close",
|
951
|
+
disabled: this.props.disabled,
|
952
|
+
onClick: this.clear,
|
953
|
+
height: height,
|
954
|
+
icon: closeIcon
|
955
|
+
}));
|
882
956
|
}
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
}
|
957
|
+
if (!hideArrow) {
|
958
|
+
icons.push( /*#__PURE__*/React.createElement(Button, {
|
959
|
+
title: "Toggle options popup",
|
960
|
+
className: modules_9d0de074.chevron,
|
961
|
+
iconClassName: modules_9d0de074.chevronIcon,
|
962
|
+
icon: chevronDownIcon,
|
963
|
+
key: "hide",
|
964
|
+
disabled: this.props.disabled,
|
965
|
+
height: height,
|
966
|
+
onClick: this._clickHandler
|
967
|
+
}));
|
895
968
|
}
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
969
|
+
return icons;
|
970
|
+
}
|
971
|
+
_getAvatar() {
|
972
|
+
return !Array.isArray(this.state.selected) && (this.state.selected?.avatar || this.state.selected?.showGeneratedAvatar) && /*#__PURE__*/React.createElement(Avatar, {
|
973
|
+
className: modules_9d0de074.avatar,
|
974
|
+
url: this.state.selected.avatar,
|
975
|
+
username: this.state.selected.username,
|
976
|
+
size: Size$1.Size20
|
977
|
+
});
|
978
|
+
}
|
979
|
+
filter;
|
980
|
+
filterRef = el => {
|
981
|
+
this.filter = el;
|
982
|
+
};
|
983
|
+
getShortcutsMap() {
|
984
|
+
return {
|
985
|
+
enter: this._onEnter,
|
986
|
+
esc: this._onEsc,
|
987
|
+
up: this._inputShortcutHandler,
|
988
|
+
down: this._inputShortcutHandler,
|
989
|
+
right: noop,
|
990
|
+
left: noop,
|
991
|
+
'shift+up': noop,
|
992
|
+
'shift+down': noop,
|
993
|
+
space: noop
|
994
|
+
};
|
995
|
+
}
|
996
|
+
renderSelect(activeItemId) {
|
997
|
+
var _this$props$label3, _this$props$label4, _this$props$buttonCla;
|
998
|
+
const dataTest = this.props['data-test'];
|
999
|
+
const {
|
1000
|
+
selectedLabel
|
1001
|
+
} = this.props;
|
1002
|
+
const {
|
1003
|
+
shortcutsEnabled
|
1004
|
+
} = this.state;
|
1005
|
+
const classes = classNames(modules_9d0de074.select, 'ring-js-shortcuts', this.props.className, modules_9d0de074[`height${this.props.height || this.context}`], {
|
1006
|
+
[modules_9d0de074[`size${this.props.size}`]]: this.props.type !== Type.INLINE,
|
1007
|
+
[modules_9d0de074.disabled]: this.props.disabled
|
1008
|
+
});
|
1009
|
+
const icons = this._getIcons();
|
1010
|
+
const style = getStyle(icons.length);
|
1011
|
+
const iconsNode = /*#__PURE__*/React.createElement("div", {
|
1012
|
+
className: modules_9d0de074.icons
|
1013
|
+
}, icons);
|
1014
|
+
const ariaProps = this.state.showPopup ? {
|
1015
|
+
'aria-owns': this.listId,
|
1016
|
+
'aria-activedescendant': activeItemId,
|
1017
|
+
'aria-label': (_this$props$label3 = this.props.label) !== null && _this$props$label3 !== void 0 ? _this$props$label3 : undefined
|
1018
|
+
} : {
|
1019
|
+
'aria-label': (_this$props$label4 = this.props.label) !== null && _this$props$label4 !== void 0 ? _this$props$label4 : undefined
|
1020
|
+
};
|
1021
|
+
switch (this.props.type) {
|
1022
|
+
case Type.INPUT_WITHOUT_CONTROLS:
|
1023
|
+
case Type.INPUT:
|
1024
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
1025
|
+
ref: this.nodeRef,
|
1026
|
+
className: classNames(classes, modules_9d0de074.inputMode),
|
1027
|
+
"data-test": joinDataTestAttributes('ring-select', dataTest)
|
1028
|
+
}, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
|
1029
|
+
map: this.getShortcutsMap(),
|
1030
|
+
scope: this.shortcutsScope
|
1031
|
+
}), /*#__PURE__*/React.createElement(Input, _extends({}, ariaProps, {
|
1032
|
+
height: this.props.height,
|
1033
|
+
autoComplete: "off",
|
1034
|
+
id: this.props.id,
|
1035
|
+
onClick: this._clickHandler,
|
1036
|
+
inputRef: composeRefs(this.filterRef, this.props.filterRef),
|
1037
|
+
disabled: this.props.disabled,
|
1038
|
+
value: this.state.filterValue,
|
1039
|
+
borderless: this.props.type === Type.INPUT_WITHOUT_CONTROLS,
|
1040
|
+
style: style,
|
1041
|
+
size: Size.FULL,
|
1042
|
+
onChange: this._filterChangeHandler,
|
1043
|
+
onFocus: this._focusHandler,
|
1044
|
+
onBlur: this._blurHandler
|
1045
|
+
// Input with error style without description
|
1046
|
+
,
|
1047
|
+
error: this.props.error != null ? '' : null,
|
1048
|
+
label: this.props.type === Type.INPUT ? this._getLabel() : null,
|
1049
|
+
placeholder: this.props.inputPlaceholder,
|
1050
|
+
onKeyDown: this.props.onKeyDown,
|
1051
|
+
"data-test": "ring-select__focus",
|
1052
|
+
enableShortcuts: shortcutsEnabled ? Object.keys({
|
1053
|
+
...this.getShortcutsMap(),
|
1054
|
+
...this._popup?.list?.shortcutsMap
|
1055
|
+
}) : undefined,
|
1056
|
+
icon: this.props.filterIcon,
|
1057
|
+
afterInput: this.props.type === Type.INPUT && iconsNode
|
1058
|
+
})), this._renderPopup()), this.props.error && /*#__PURE__*/React.createElement("div", {
|
1059
|
+
className: classNames(modules_88cfaf40.errorText, modules_88cfaf40[`size${this.props.size}`])
|
1060
|
+
}, this.props.error));
|
1061
|
+
case Type.BUTTON:
|
1062
|
+
return /*#__PURE__*/React.createElement("div", {
|
1063
|
+
ref: this.nodeRef,
|
1064
|
+
className: classNames(classes, modules_9d0de074.buttonMode),
|
1065
|
+
"data-test": joinDataTestAttributes('ring-select', dataTest)
|
1066
|
+
}, selectedLabel && /*#__PURE__*/React.createElement(ControlLabel, {
|
1067
|
+
type: this.props.labelType,
|
912
1068
|
disabled: this.props.disabled,
|
1069
|
+
htmlFor: this.props.id
|
1070
|
+
}, selectedLabel), shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
|
1071
|
+
map: this.getShortcutsMap(),
|
1072
|
+
scope: this.shortcutsScope
|
1073
|
+
}), /*#__PURE__*/React.createElement("div", {
|
1074
|
+
className: modules_9d0de074.buttonContainer
|
1075
|
+
}, /*#__PURE__*/React.createElement(Button, _extends({}, ariaProps, {
|
1076
|
+
height: this.props.height,
|
1077
|
+
id: this.props.id,
|
913
1078
|
onClick: this._clickHandler,
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
}
|
919
|
-
if (clear && !disabled && !this._selectionIsEmpty()) {
|
920
|
-
icons.push( /*#__PURE__*/React.createElement(Button, {
|
921
|
-
title: "Clear selection",
|
922
|
-
"data-test": "ring-clear-select",
|
923
|
-
className: modules_9d0de074.clearIcon,
|
924
|
-
key: "close",
|
1079
|
+
className: classNames(this.props.buttonClassName, modules_9d0de074.buttonValue, {
|
1080
|
+
[modules_9d0de074.buttonValueOpen]: this.state.showPopup,
|
1081
|
+
[modules_9d0de074.buttonValueEmpty]: this._selectionIsEmpty()
|
1082
|
+
}),
|
925
1083
|
disabled: this.props.disabled,
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
1084
|
+
style: style,
|
1085
|
+
"data-test": "ring-select__button ring-select__focus"
|
1086
|
+
}), this._getAvatar(), this._getPlaceholder()), iconsNode), this._renderPopup());
|
1087
|
+
case Type.INLINE:
|
1088
|
+
return /*#__PURE__*/React.createElement("div", {
|
1089
|
+
className: classes,
|
1090
|
+
ref: this.nodeRef,
|
1091
|
+
"data-test": joinDataTestAttributes('ring-select', dataTest)
|
1092
|
+
}, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
|
1093
|
+
map: this.getShortcutsMap(),
|
1094
|
+
scope: this.shortcutsScope
|
1095
|
+
}), /*#__PURE__*/React.createElement(Anchor, _extends({}, ariaProps, {
|
1096
|
+
className: (_this$props$buttonCla = this.props.buttonClassName) !== null && _this$props$buttonCla !== void 0 ? _this$props$buttonCla : undefined,
|
1097
|
+
id: this.props.id,
|
1098
|
+
onClick: this._clickHandler,
|
1099
|
+
"data-test": "ring-select__focus",
|
938
1100
|
disabled: this.props.disabled,
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
}
|
945
|
-
}, {
|
946
|
-
key: "_getAvatar",
|
947
|
-
value: function _getAvatar() {
|
948
|
-
var _this$state$selected, _this$state$selected2;
|
949
|
-
return !Array.isArray(this.state.selected) && (((_this$state$selected = this.state.selected) === null || _this$state$selected === void 0 ? void 0 : _this$state$selected.avatar) || ((_this$state$selected2 = this.state.selected) === null || _this$state$selected2 === void 0 ? void 0 : _this$state$selected2.showGeneratedAvatar)) && /*#__PURE__*/React.createElement(Avatar, {
|
950
|
-
className: modules_9d0de074.avatar,
|
951
|
-
url: this.state.selected.avatar,
|
952
|
-
username: this.state.selected.username,
|
953
|
-
size: Size$1.Size20
|
954
|
-
});
|
955
|
-
}
|
956
|
-
}, {
|
957
|
-
key: "getShortcutsMap",
|
958
|
-
value: function getShortcutsMap() {
|
959
|
-
return {
|
960
|
-
enter: this._onEnter,
|
961
|
-
esc: this._onEsc,
|
962
|
-
up: this._inputShortcutHandler,
|
963
|
-
down: this._inputShortcutHandler,
|
964
|
-
right: noop,
|
965
|
-
left: noop,
|
966
|
-
'shift+up': noop,
|
967
|
-
'shift+down': noop,
|
968
|
-
space: noop
|
969
|
-
};
|
970
|
-
}
|
971
|
-
}, {
|
972
|
-
key: "renderSelect",
|
973
|
-
value: function renderSelect(activeItemId) {
|
974
|
-
var _this$props$label3, _this$props$label4, _this$_popup5, _this$props$buttonCla;
|
975
|
-
var dataTest = this.props['data-test'];
|
976
|
-
var selectedLabel = this.props.selectedLabel;
|
977
|
-
var shortcutsEnabled = this.state.shortcutsEnabled;
|
978
|
-
var classes = classNames(modules_9d0de074.select, 'ring-js-shortcuts', this.props.className, modules_9d0de074["height".concat(this.props.height || this.context)], {
|
979
|
-
[modules_9d0de074["size".concat(this.props.size)]]: this.props.type !== Type.INLINE,
|
980
|
-
[modules_9d0de074.disabled]: this.props.disabled
|
981
|
-
});
|
982
|
-
var icons = this._getIcons();
|
983
|
-
var style = getStyle(icons.length);
|
984
|
-
var iconsNode = /*#__PURE__*/React.createElement("div", {
|
985
|
-
className: modules_9d0de074.icons
|
986
|
-
}, icons);
|
987
|
-
var ariaProps = this.state.showPopup ? {
|
988
|
-
'aria-owns': this.listId,
|
989
|
-
'aria-activedescendant': activeItemId,
|
990
|
-
'aria-label': (_this$props$label3 = this.props.label) !== null && _this$props$label3 !== void 0 ? _this$props$label3 : undefined
|
991
|
-
} : {
|
992
|
-
'aria-label': (_this$props$label4 = this.props.label) !== null && _this$props$label4 !== void 0 ? _this$props$label4 : undefined
|
993
|
-
};
|
994
|
-
switch (this.props.type) {
|
995
|
-
case Type.INPUT_WITHOUT_CONTROLS:
|
996
|
-
case Type.INPUT:
|
997
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
998
|
-
ref: this.nodeRef,
|
999
|
-
className: classNames(classes, modules_9d0de074.inputMode),
|
1000
|
-
"data-test": joinDataTestAttributes('ring-select', dataTest)
|
1001
|
-
}, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
|
1002
|
-
map: this.getShortcutsMap(),
|
1003
|
-
scope: this.shortcutsScope
|
1004
|
-
}), /*#__PURE__*/React.createElement(Input, _extends({}, ariaProps, {
|
1005
|
-
height: this.props.height,
|
1006
|
-
autoComplete: "off",
|
1007
|
-
id: this.props.id,
|
1008
|
-
onClick: this._clickHandler,
|
1009
|
-
inputRef: composeRefs(this.filterRef, this.props.filterRef),
|
1010
|
-
disabled: this.props.disabled,
|
1011
|
-
value: this.state.filterValue,
|
1012
|
-
borderless: this.props.type === Type.INPUT_WITHOUT_CONTROLS,
|
1013
|
-
style: style,
|
1014
|
-
size: Size.FULL,
|
1015
|
-
onChange: this._filterChangeHandler,
|
1016
|
-
onFocus: this._focusHandler,
|
1017
|
-
onBlur: this._blurHandler
|
1018
|
-
// Input with error style without description
|
1019
|
-
,
|
1020
|
-
error: this.props.error != null ? '' : null,
|
1021
|
-
label: this.props.type === Type.INPUT ? this._getLabel() : null,
|
1022
|
-
placeholder: this.props.inputPlaceholder,
|
1023
|
-
onKeyDown: this.props.onKeyDown,
|
1024
|
-
"data-test": "ring-select__focus",
|
1025
|
-
enableShortcuts: shortcutsEnabled ? Object.keys(_objectSpread2(_objectSpread2({}, this.getShortcutsMap()), (_this$_popup5 = this._popup) === null || _this$_popup5 === void 0 || (_this$_popup5 = _this$_popup5.list) === null || _this$_popup5 === void 0 ? void 0 : _this$_popup5.shortcutsMap)) : undefined,
|
1026
|
-
icon: this.props.filterIcon,
|
1027
|
-
afterInput: this.props.type === Type.INPUT && iconsNode
|
1028
|
-
})), this._renderPopup()), this.props.error && /*#__PURE__*/React.createElement("div", {
|
1029
|
-
className: classNames(modules_88cfaf40.errorText, modules_88cfaf40["size".concat(this.props.size)])
|
1030
|
-
}, this.props.error));
|
1031
|
-
case Type.BUTTON:
|
1032
|
-
return /*#__PURE__*/React.createElement("div", {
|
1033
|
-
ref: this.nodeRef,
|
1034
|
-
className: classNames(classes, modules_9d0de074.buttonMode),
|
1035
|
-
"data-test": joinDataTestAttributes('ring-select', dataTest)
|
1036
|
-
}, selectedLabel && /*#__PURE__*/React.createElement(ControlLabel, {
|
1037
|
-
type: this.props.labelType,
|
1038
|
-
disabled: this.props.disabled,
|
1039
|
-
htmlFor: this.props.id
|
1040
|
-
}, selectedLabel), shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
|
1041
|
-
map: this.getShortcutsMap(),
|
1042
|
-
scope: this.shortcutsScope
|
1043
|
-
}), /*#__PURE__*/React.createElement("div", {
|
1044
|
-
className: modules_9d0de074.buttonContainer
|
1045
|
-
}, /*#__PURE__*/React.createElement(Button, _extends({}, ariaProps, {
|
1046
|
-
height: this.props.height,
|
1047
|
-
id: this.props.id,
|
1048
|
-
onClick: this._clickHandler,
|
1049
|
-
className: classNames(this.props.buttonClassName, modules_9d0de074.buttonValue, {
|
1050
|
-
[modules_9d0de074.buttonValueOpen]: this.state.showPopup,
|
1051
|
-
[modules_9d0de074.buttonValueEmpty]: this._selectionIsEmpty()
|
1052
|
-
}),
|
1053
|
-
disabled: this.props.disabled,
|
1054
|
-
style: style,
|
1055
|
-
"data-test": "ring-select__button ring-select__focus"
|
1056
|
-
}), this._getAvatar(), this._getPlaceholder()), iconsNode), this._renderPopup());
|
1057
|
-
case Type.INLINE:
|
1058
|
-
return /*#__PURE__*/React.createElement("div", {
|
1059
|
-
className: classes,
|
1060
|
-
ref: this.nodeRef,
|
1061
|
-
"data-test": joinDataTestAttributes('ring-select', dataTest)
|
1062
|
-
}, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
|
1101
|
+
active: this.state.showPopup
|
1102
|
+
}), this._getPlaceholder()), this._renderPopup());
|
1103
|
+
default:
|
1104
|
+
if (this.props.customAnchor) {
|
1105
|
+
return /*#__PURE__*/React.createElement(Fragment, null, shortcutsEnabled && /*#__PURE__*/React.createElement(Shortcuts, {
|
1063
1106
|
map: this.getShortcutsMap(),
|
1064
1107
|
scope: this.shortcutsScope
|
1065
|
-
}),
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
ref: this.nodeRef,
|
1081
|
-
'data-test': joinDataTestAttributes('ring-select', dataTest)
|
1082
|
-
},
|
1083
|
-
buttonProps: _objectSpread2(_objectSpread2({}, ariaProps), {}, {
|
1084
|
-
id: this.props.id,
|
1085
|
-
onClick: this._clickHandler,
|
1086
|
-
disabled: this.props.disabled,
|
1087
|
-
children: this._getPlaceholder(),
|
1088
|
-
'data-test': 'ring-select__focus'
|
1089
|
-
}),
|
1090
|
-
popup: this._renderPopup()
|
1091
|
-
}));
|
1092
|
-
}
|
1093
|
-
return /*#__PURE__*/React.createElement("span", {
|
1094
|
-
id: this.props.id,
|
1095
|
-
ref: this.nodeRef,
|
1096
|
-
"data-test": "ring-select"
|
1097
|
-
}, this._renderPopup());
|
1098
|
-
}
|
1099
|
-
}
|
1100
|
-
}, {
|
1101
|
-
key: "render",
|
1102
|
-
value: function render() {
|
1103
|
-
var _this4 = this;
|
1104
|
-
return /*#__PURE__*/React.createElement(ActiveItemContext.Provider, null, /*#__PURE__*/React.createElement(ActiveItemContext.ValueContext.Consumer, null, function (activeItemId) {
|
1105
|
-
return _this4.renderSelect(activeItemId);
|
1106
|
-
}));
|
1107
|
-
}
|
1108
|
-
}], [{
|
1109
|
-
key: "getDerivedStateFromProps",
|
1110
|
-
value: function getDerivedStateFromProps(nextProps, prevState) {
|
1111
|
-
var multiple = nextProps.multiple,
|
1112
|
-
data = nextProps.data,
|
1113
|
-
type = nextProps.type;
|
1114
|
-
var prevSelected = prevState.prevSelected,
|
1115
|
-
prevData = prevState.prevData,
|
1116
|
-
prevMultiple = prevState.prevMultiple,
|
1117
|
-
filterValue = prevState.filterValue;
|
1118
|
-
var nextState = {
|
1119
|
-
prevData: data,
|
1120
|
-
prevSelected: nextProps.selected,
|
1121
|
-
prevMultiple: multiple
|
1122
|
-
};
|
1123
|
-
if ('data' in nextProps && data !== prevData) {
|
1124
|
-
var _getListItems3 = _getListItems(nextProps, prevState, filterValue, data),
|
1125
|
-
filteredData = _getListItems3.filteredData,
|
1126
|
-
addButton = _getListItems3.addButton;
|
1127
|
-
Object.assign(nextState, {
|
1128
|
-
shownData: filteredData,
|
1129
|
-
addButton
|
1130
|
-
});
|
1131
|
-
if (prevState.selected) {
|
1132
|
-
Object.assign(nextState, {
|
1133
|
-
selectedIndex: getSelectedIndex(prevState.selected, data),
|
1134
|
-
filterValue: _getValueForFilter(prevState.selected, type, filterValue)
|
1135
|
-
});
|
1136
|
-
}
|
1137
|
-
}
|
1138
|
-
if ('selected' in nextProps && nextProps.selected !== prevSelected) {
|
1139
|
-
var _selected = nextProps.selected || (multiple ? [] : null);
|
1140
|
-
var selectedIndex = getSelectedIndex(_selected, data || prevData);
|
1141
|
-
Object.assign(nextState, {
|
1142
|
-
selected: _selected,
|
1143
|
-
filterValue: _getValueForFilter(_selected, type, filterValue)
|
1144
|
-
});
|
1145
|
-
if (!Array.isArray(prevSelected) || !Array.isArray(_selected) || !isSameSelected(prevSelected, _selected)) {
|
1146
|
-
Object.assign(nextState, {
|
1147
|
-
selectedIndex
|
1148
|
-
});
|
1108
|
+
}), this.props.customAnchor({
|
1109
|
+
wrapperProps: {
|
1110
|
+
ref: this.nodeRef,
|
1111
|
+
'data-test': joinDataTestAttributes('ring-select', dataTest)
|
1112
|
+
},
|
1113
|
+
buttonProps: {
|
1114
|
+
...ariaProps,
|
1115
|
+
id: this.props.id,
|
1116
|
+
onClick: this._clickHandler,
|
1117
|
+
disabled: this.props.disabled,
|
1118
|
+
children: this._getPlaceholder(),
|
1119
|
+
'data-test': 'ring-select__focus'
|
1120
|
+
},
|
1121
|
+
popup: this._renderPopup()
|
1122
|
+
}));
|
1149
1123
|
}
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
nextState.selected = prevState.selected;
|
1156
|
-
}
|
1157
|
-
var _prevState$nextState = _objectSpread2(_objectSpread2({}, prevState), nextState),
|
1158
|
-
selected = _prevState$nextState.selected;
|
1159
|
-
if (selected && Array.isArray(selected)) {
|
1160
|
-
nextState.multipleMap = buildMultipleMap(selected);
|
1161
|
-
var _getListItems4 = _getListItems(nextProps, nextState, filterValue, data),
|
1162
|
-
_filteredData = _getListItems4.filteredData,
|
1163
|
-
_addButton = _getListItems4.addButton;
|
1164
|
-
Object.assign(nextState, {
|
1165
|
-
shownData: _filteredData,
|
1166
|
-
addButton: _addButton
|
1167
|
-
});
|
1168
|
-
}
|
1169
|
-
return nextState;
|
1124
|
+
return /*#__PURE__*/React.createElement("span", {
|
1125
|
+
id: this.props.id,
|
1126
|
+
ref: this.nodeRef,
|
1127
|
+
"data-test": "ring-select"
|
1128
|
+
}, this._renderPopup());
|
1170
1129
|
}
|
1171
|
-
}
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
// enable filter (not in INPUT modes)
|
1177
|
-
filterIcon: null,
|
1178
|
-
filterRef: noop,
|
1179
|
-
multiple: false,
|
1180
|
-
// multiple can be an object - see demo for more information
|
1181
|
-
clear: false,
|
1182
|
-
// enable clear button that clears the "selected" state
|
1183
|
-
loading: false,
|
1184
|
-
// show a loading indicator while data is loading
|
1185
|
-
disabled: false,
|
1186
|
-
// disable select
|
1187
|
-
type: Type.BUTTON,
|
1188
|
-
size: Size.M,
|
1189
|
-
targetElement: null,
|
1190
|
-
// element to bind the popup to (select BUTTON or INPUT by default)
|
1191
|
-
hideSelected: false,
|
1192
|
-
// INPUT mode: clears the input after an option is selected (useful when the selection is displayed in some custom way elsewhere)
|
1193
|
-
allowAny: false,
|
1194
|
-
// INPUT mode: allows any value to be entered
|
1195
|
-
hideArrow: false,
|
1196
|
-
// hide dropdown arrow icon
|
1197
|
-
showPopup: false,
|
1198
|
-
maxHeight: 600,
|
1199
|
-
// height of the options list, including the filter and the 'Add' button
|
1200
|
-
directions: [Popup.PopupProps.Directions.BOTTOM_RIGHT, Popup.PopupProps.Directions.BOTTOM_LEFT, Popup.PopupProps.Directions.TOP_LEFT, Popup.PopupProps.Directions.TOP_RIGHT],
|
1201
|
-
selected: null,
|
1202
|
-
// current selection (item / array of items)
|
1203
|
-
label: null,
|
1204
|
-
// BUTTON or INPUT label (nothing selected)
|
1205
|
-
selectedLabel: null,
|
1206
|
-
// BUTTON or INPUT label (something selected)
|
1207
|
-
inputPlaceholder: '',
|
1208
|
-
// Placeholder for input modes
|
1209
|
-
hint: null,
|
1210
|
-
// hint text to display under the list
|
1211
|
-
shortcutsEnabled: false,
|
1212
|
-
onBeforeOpen: noop,
|
1213
|
-
onLoadMore: noop,
|
1214
|
-
onOpen: noop,
|
1215
|
-
onClose: noop,
|
1216
|
-
onFilter: noop,
|
1217
|
-
// search string as first argument
|
1218
|
-
onFocus: noop,
|
1219
|
-
onBlur: noop,
|
1220
|
-
onKeyDown: noop,
|
1221
|
-
onSelect: noop,
|
1222
|
-
// single + multi
|
1223
|
-
onDeselect: noop,
|
1224
|
-
// multi
|
1225
|
-
onOutsideClick: noop,
|
1226
|
-
// multi
|
1227
|
-
onChange: noop,
|
1228
|
-
// multi
|
1229
|
-
onAdd: noop,
|
1230
|
-
// search string as first argument
|
1231
|
-
onDone: noop,
|
1232
|
-
onReset: noop,
|
1233
|
-
tags: null,
|
1234
|
-
ringPopupTarget: null,
|
1235
|
-
dir: 'ltr'
|
1236
|
-
});
|
1237
|
-
_defineProperty(Select, "contextType", ControlsHeightContext);
|
1238
|
-
_defineProperty(Select, "Type", Type);
|
1239
|
-
_defineProperty(Select, "Size", Size);
|
1130
|
+
}
|
1131
|
+
render() {
|
1132
|
+
return /*#__PURE__*/React.createElement(ActiveItemContext.Provider, null, /*#__PURE__*/React.createElement(ActiveItemContext.ValueContext.Consumer, null, activeItemId => this.renderSelect(activeItemId)));
|
1133
|
+
}
|
1134
|
+
}
|
1240
1135
|
Select.propTypes = {
|
1241
1136
|
className: PropTypes.string,
|
1242
1137
|
buttonClassName: PropTypes.string,
|
@@ -1300,6 +1195,6 @@ Select.propTypes = {
|
|
1300
1195
|
dir: PropTypes.oneOf(['ltr', 'rtl']),
|
1301
1196
|
'data-test': PropTypes.string
|
1302
1197
|
};
|
1303
|
-
|
1198
|
+
const RerenderableSelect = rerenderHOC(Select);
|
1304
1199
|
|
1305
1200
|
export { RerenderableSelect, Type, Select as default };
|