@orfium/ictinus 4.64.0 → 4.65.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.
|
@@ -12,6 +12,7 @@ export declare type SelectOption = {
|
|
|
12
12
|
helperText?: string;
|
|
13
13
|
tooltipInfo?: string;
|
|
14
14
|
options?: SelectOption[];
|
|
15
|
+
isCreated?: boolean;
|
|
15
16
|
} & SelectOptionValues;
|
|
16
17
|
export declare type Props = {
|
|
17
18
|
/** The function that is used to return the selected options */
|
|
@@ -48,6 +49,11 @@ export declare type Props = {
|
|
|
48
49
|
/** The selected options in case of multiSelect */
|
|
49
50
|
/** @TODO merge selectedOption with selectedOptions in v5 */
|
|
50
51
|
selectedOptions?: SelectOption[];
|
|
52
|
+
/**
|
|
53
|
+
* If true, then in the case of a searched option that is not found in the Options list of MultiSelect,
|
|
54
|
+
* the user can create this option.
|
|
55
|
+
* */
|
|
56
|
+
creatable?: boolean;
|
|
51
57
|
} & TextFieldProps;
|
|
52
58
|
declare const Select: React.ForwardRefExoticComponent<{
|
|
53
59
|
/** The function that is used to return the selected options */
|
|
@@ -84,6 +90,11 @@ declare const Select: React.ForwardRefExoticComponent<{
|
|
|
84
90
|
/** The selected options in case of multiSelect */
|
|
85
91
|
/** @TODO merge selectedOption with selectedOptions in v5 */
|
|
86
92
|
selectedOptions?: SelectOption[] | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* If true, then in the case of a searched option that is not found in the Options list of MultiSelect,
|
|
95
|
+
* the user can create this option.
|
|
96
|
+
* */
|
|
97
|
+
creatable?: boolean | undefined;
|
|
87
98
|
} & {
|
|
88
99
|
id?: string | undefined;
|
|
89
100
|
onBlur?: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement> | undefined;
|
|
@@ -35,7 +35,7 @@ var _PositionInScreen = _interopRequireDefault(require("../utils/PositionInScree
|
|
|
35
35
|
|
|
36
36
|
var _react2 = require("@emotion/react");
|
|
37
37
|
|
|
38
|
-
var _excluded = ["handleSelectedOption", "defaultValue", "selectedOption", "multi", "options", "isAsync", "isLoading", "asyncSearch", "status", "minCharactersToSearch", "highlightSearch", "isSearchable", "isVirtualized", "styleType", "disabled", "locked", "dataTestId", "onClear", "onOptionDelete", "selectedOptions"];
|
|
38
|
+
var _excluded = ["handleSelectedOption", "defaultValue", "selectedOption", "multi", "options", "isAsync", "isLoading", "asyncSearch", "status", "minCharactersToSearch", "highlightSearch", "isSearchable", "isVirtualized", "styleType", "disabled", "locked", "dataTestId", "onClear", "onOptionDelete", "selectedOptions", "creatable"];
|
|
39
39
|
|
|
40
40
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
41
41
|
|
|
@@ -88,6 +88,8 @@ var Select = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
88
88
|
onOptionDelete = _ref.onOptionDelete,
|
|
89
89
|
_ref$selectedOptions = _ref.selectedOptions,
|
|
90
90
|
selectedOptions = _ref$selectedOptions === void 0 ? [] : _ref$selectedOptions,
|
|
91
|
+
_ref$creatable = _ref.creatable,
|
|
92
|
+
creatable = _ref$creatable === void 0 ? false : _ref$creatable,
|
|
91
93
|
restInputProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
92
94
|
|
|
93
95
|
var theme = (0, _useTheme["default"])();
|
|
@@ -135,7 +137,14 @@ var Select = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
135
137
|
if (multi) {
|
|
136
138
|
handleMultiSelectOptionClick(option);
|
|
137
139
|
} else {
|
|
138
|
-
|
|
140
|
+
if (option.isCreated) {
|
|
141
|
+
setInputValue(_extends({}, option, {
|
|
142
|
+
label: option.value.toString()
|
|
143
|
+
}));
|
|
144
|
+
} else {
|
|
145
|
+
setInputValue(option);
|
|
146
|
+
}
|
|
147
|
+
|
|
139
148
|
setOpen(false);
|
|
140
149
|
}
|
|
141
150
|
|
|
@@ -180,27 +189,45 @@ var Select = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
180
189
|
|
|
181
190
|
var filteredOptions = (0, _react.useMemo)(function () {
|
|
182
191
|
var optionsToBeFiltered = multi ? availableMultiSelectOptions : options;
|
|
192
|
+
var finalOptions = [];
|
|
183
193
|
|
|
184
194
|
if (isAsync) {
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
var _option$options;
|
|
195
|
+
finalOptions.push.apply(finalOptions, optionsToBeFiltered);
|
|
196
|
+
} else {
|
|
197
|
+
finalOptions.push.apply(finalOptions, optionsToBeFiltered.filter(function (option) {
|
|
198
|
+
var _option$options;
|
|
190
199
|
|
|
191
|
-
|
|
192
|
-
|
|
200
|
+
return !searchValue || option.label.toLowerCase().includes(searchValue.toLowerCase()) || !!((_option$options = option.options) != null && _option$options.find(function (option) {
|
|
201
|
+
return option.label.toLowerCase().includes(searchValue.toLowerCase());
|
|
202
|
+
}));
|
|
203
|
+
}).map(function (option) {
|
|
204
|
+
var _option$options2;
|
|
205
|
+
|
|
206
|
+
return option.label.toLowerCase().includes(searchValue.toLowerCase()) ? option : _extends({}, option, {
|
|
207
|
+
options: (_option$options2 = option.options) == null ? void 0 : _option$options2.filter(function (option) {
|
|
208
|
+
return option.label.toLowerCase().includes(searchValue.toLowerCase());
|
|
209
|
+
})
|
|
210
|
+
});
|
|
193
211
|
}));
|
|
194
|
-
}
|
|
195
|
-
var _option$options2;
|
|
212
|
+
}
|
|
196
213
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
|
|
214
|
+
if (creatable) {
|
|
215
|
+
/** Check if the searchValue has an exact result (so no need for "Create..." option) */
|
|
216
|
+
var hasDistinctResult = finalOptions.map(function (item) {
|
|
217
|
+
return item.label.toLowerCase();
|
|
218
|
+
}).includes(searchValue.toLowerCase());
|
|
219
|
+
|
|
220
|
+
if (!hasDistinctResult && searchValue.length > 0) {
|
|
221
|
+
finalOptions.push({
|
|
222
|
+
value: searchValue,
|
|
223
|
+
label: "Create \"" + searchValue + "\"",
|
|
224
|
+
isCreated: true
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return finalOptions;
|
|
230
|
+
}, [multi, availableMultiSelectOptions, options, isAsync, creatable, searchValue]);
|
|
204
231
|
var rightIconNameSelector = (0, _react.useMemo)(function () {
|
|
205
232
|
if (isSearchable) {
|
|
206
233
|
return searchValue || inputValue.value ? 'close' : 'search';
|
|
@@ -250,7 +277,13 @@ var Select = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
250
277
|
combinedRefs == null ? void 0 : (_combinedRefs$current2 = combinedRefs.current) == null ? void 0 : _combinedRefs$current2.blur();
|
|
251
278
|
}
|
|
252
279
|
};
|
|
280
|
+
/**
|
|
281
|
+
* Boolean flag for the case where we have no options but create functionality - so
|
|
282
|
+
* we can hide the Select All option in that case
|
|
283
|
+
*/
|
|
284
|
+
|
|
253
285
|
|
|
286
|
+
var hasNoOptionsAndIsCreatable = creatable && filteredOptions.length === 1 && filteredOptions[0].isCreated;
|
|
254
287
|
return (0, _react2.jsx)(_ClickAwayListener["default"], {
|
|
255
288
|
onClick: function onClick() {
|
|
256
289
|
setOpen(false);
|
|
@@ -305,7 +338,7 @@ var Select = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
305
338
|
isLoading: isLoading,
|
|
306
339
|
isVirtualized: isVirtualized,
|
|
307
340
|
searchTerm: highlightSearch ? searchValue : undefined,
|
|
308
|
-
hasSelectAllOption: multi
|
|
341
|
+
hasSelectAllOption: multi && !hasNoOptionsAndIsCreatable
|
|
309
342
|
}))));
|
|
310
343
|
});
|
|
311
344
|
|
|
@@ -59,7 +59,10 @@ var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
|
59
59
|
setMultiSelectedOpts(multiSelectedOptions.filter(function (opt) {
|
|
60
60
|
return opt.value !== (option == null ? void 0 : option.value);
|
|
61
61
|
}));
|
|
62
|
-
|
|
62
|
+
|
|
63
|
+
if (!option.isCreated) {
|
|
64
|
+
setAvailableMultiSelectOptions([].concat(availableMultiSelectOptions, [option]));
|
|
65
|
+
}
|
|
63
66
|
|
|
64
67
|
if (onOptionDelete) {
|
|
65
68
|
onOptionDelete(option);
|
|
@@ -70,13 +73,18 @@ var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
|
70
73
|
setMultiSelectedOpts(multiSelectedOptions.filter(function (opt) {
|
|
71
74
|
return opt.value !== lastItem.value;
|
|
72
75
|
}));
|
|
73
|
-
|
|
76
|
+
|
|
77
|
+
if (!lastItem.isCreated) {
|
|
78
|
+
setAvailableMultiSelectOptions([].concat(availableMultiSelectOptions, [lastItem]));
|
|
79
|
+
}
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
82
|
};
|
|
77
83
|
|
|
78
84
|
var handleClearAllOptions = function handleClearAllOptions() {
|
|
79
|
-
setAvailableMultiSelectOptions([].concat(availableMultiSelectOptions, multiSelectedOptions)
|
|
85
|
+
setAvailableMultiSelectOptions([].concat(availableMultiSelectOptions, multiSelectedOptions.filter(function (item) {
|
|
86
|
+
return !item.isCreated;
|
|
87
|
+
})));
|
|
80
88
|
setMultiSelectedOpts([]);
|
|
81
89
|
|
|
82
90
|
if (onClear) {
|
|
@@ -101,6 +109,14 @@ var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
|
101
109
|
setMultiSelectedOpts([].concat(multiSelectedOptions, selected));
|
|
102
110
|
setAvailableMultiSelectOptions(remaining);
|
|
103
111
|
setOpen(false);
|
|
112
|
+
} else if (option.isCreated) {
|
|
113
|
+
/** If the option is created internally */
|
|
114
|
+
var newOption = {
|
|
115
|
+
value: option.value,
|
|
116
|
+
label: option.value.toString(),
|
|
117
|
+
isCreated: true
|
|
118
|
+
};
|
|
119
|
+
setMultiSelectedOpts([].concat(multiSelectedOptions, [newOption]));
|
|
104
120
|
} else {
|
|
105
121
|
setMultiSelectedOpts([].concat(multiSelectedOptions, [option]));
|
|
106
122
|
setAvailableMultiSelectOptions(availableMultiSelectOptions.filter(function (opt) {
|