ab-ui-library 1.41.0 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/MultiTextareaWithChips/MultiTextareaWithChips.d.ts +1 -1
- package/components/MultiTextareaWithChips/MultiTextareaWithChips.js +148 -253
- package/components/MultiTextareaWithChips/hooks/index.d.ts +4 -0
- package/components/MultiTextareaWithChips/hooks/index.js +8 -0
- package/components/MultiTextareaWithChips/hooks/useChipManagement.d.ts +21 -0
- package/components/MultiTextareaWithChips/hooks/useChipManagement.js +81 -0
- package/components/MultiTextareaWithChips/hooks/useChipValidation.d.ts +13 -0
- package/components/MultiTextareaWithChips/hooks/useChipValidation.js +65 -0
- package/components/MultiTextareaWithChips/hooks/useDropdownLogic.d.ts +17 -0
- package/components/MultiTextareaWithChips/hooks/useDropdownLogic.js +91 -0
- package/components/MultiTextareaWithChips/hooks/useKeyboardNavigation.d.ts +23 -0
- package/components/MultiTextareaWithChips/hooks/useKeyboardNavigation.js +72 -0
- package/components/MultiTextareaWithChips/index.d.ts +1 -1
- package/components/MultiTextareaWithChips/index.js +6 -3
- package/components/MultiTextareaWithChips/types.d.ts +25 -31
- package/components/Select/Select/Select.js +4 -1
- package/components/Select/types.d.ts +1 -0
- package/index.js +4 -1
- package/package.json +1 -1
- package/stories/MultiTextareaWithChips.stories.d.ts +1 -11
- package/components/MultiTextareaWithChips/InputWrapper.d.ts +0 -7
- package/components/MultiTextareaWithChips/InputWrapper.js +0 -13
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { TMultiTextareaWithChipsProps } from './types';
|
|
3
|
-
export declare const MultiTextareaWithChips: React.
|
|
3
|
+
export declare const MultiTextareaWithChips: React.NamedExoticComponent<TMultiTextareaWithChipsProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _extends } from '../../extends-cc60c71c.js';
|
|
2
|
-
import { _ as
|
|
2
|
+
import { _ as _typeof } from '../../typeof-e9310111.js';
|
|
3
3
|
import { _ as _slicedToArray } from '../../slicedToArray-093df980.js';
|
|
4
|
-
import React, { useState, useRef, useMemo
|
|
4
|
+
import React, { memo, useState, useRef, useMemo } from 'react';
|
|
5
5
|
import { Chips } from '../Chips/Chips.js';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
import { ErrorMessage } from '../../helperComponents/ErrorMessage/ErrorMessage.js';
|
|
@@ -12,12 +12,15 @@ import '../../hooks/useScreenSize.js';
|
|
|
12
12
|
import 'react-hook-form';
|
|
13
13
|
import '../Radio/Radio.js';
|
|
14
14
|
import 'react-syntax-highlighter';
|
|
15
|
+
import { useChipManagement } from './hooks/useChipManagement.js';
|
|
16
|
+
import { useChipValidation } from './hooks/useChipValidation.js';
|
|
17
|
+
import { useDropdownLogic } from './hooks/useDropdownLogic.js';
|
|
18
|
+
import { useKeyboardNavigation } from './hooks/useKeyboardNavigation.js';
|
|
15
19
|
import '../Text/Text.js';
|
|
16
20
|
import '../../utils/helpers.js';
|
|
17
21
|
import '../Chips/types.js';
|
|
18
22
|
import '../SVGIcons/IconDismissCircleFilled.js';
|
|
19
23
|
import '../../defineProperty-109927cc.js';
|
|
20
|
-
import '../../typeof-e9310111.js';
|
|
21
24
|
import '../Chips/consts.js';
|
|
22
25
|
import '../../helperComponents/IconDynamicComponent/IconDynamicComponent.js';
|
|
23
26
|
import '../../helperComponents/IconDynamicComponent/constants.js';
|
|
@@ -34,8 +37,9 @@ import '../../hooks/useOnOutsideClick.js';
|
|
|
34
37
|
import '../Link/Link.js';
|
|
35
38
|
import '../SVGIcons/IconInfo.js';
|
|
36
39
|
import '../../context/types.js';
|
|
40
|
+
import '../../toConsumableArray-d592cd83.js';
|
|
37
41
|
|
|
38
|
-
var
|
|
42
|
+
var MultiTextareaWithChipsComponent = function MultiTextareaWithChipsComponent(_ref) {
|
|
39
43
|
var label = _ref.label,
|
|
40
44
|
placeholder = _ref.placeholder,
|
|
41
45
|
helperText = _ref.helperText,
|
|
@@ -56,321 +60,212 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
56
60
|
chipValidationErrorMessage = _ref.chipValidationErrorMessage,
|
|
57
61
|
_ref$allowInvalidChip = _ref.allowInvalidChips,
|
|
58
62
|
allowInvalidChips = _ref$allowInvalidChip === void 0 ? false : _ref$allowInvalidChip,
|
|
59
|
-
_ref$fieldName = _ref.fieldName,
|
|
60
|
-
fieldName = _ref$fieldName === void 0 ? 'skills' : _ref$fieldName,
|
|
61
63
|
_ref$searchPlaceholde = _ref.searchPlaceholderText,
|
|
62
64
|
searchPlaceholderText = _ref$searchPlaceholde === void 0 ? 'Search and select...' : _ref$searchPlaceholde,
|
|
63
65
|
_ref$typeAndEnterPlac = _ref.typeAndEnterPlaceholderText,
|
|
64
66
|
typeAndEnterPlaceholderText = _ref$typeAndEnterPlac === void 0 ? 'Type and press Enter...' : _ref$typeAndEnterPlac,
|
|
65
67
|
_ref$noOptionsPlaceho = _ref.noOptionsPlaceholderText,
|
|
66
68
|
noOptionsPlaceholderText = _ref$noOptionsPlaceho === void 0 ? 'No more options available' : _ref$noOptionsPlaceho,
|
|
67
|
-
|
|
69
|
+
_ref$fieldName = _ref.fieldName,
|
|
70
|
+
fieldName = _ref$fieldName === void 0 ? 'skills' : _ref$fieldName,
|
|
71
|
+
formProps = _ref.formProps,
|
|
72
|
+
minChipLength = _ref.minChipLength,
|
|
73
|
+
maxChipLength = _ref.maxChipLength;
|
|
68
74
|
var _useState = useState(''),
|
|
69
75
|
_useState2 = _slicedToArray(_useState, 2),
|
|
70
76
|
inputValue = _useState2[0],
|
|
71
77
|
setInputValue = _useState2[1];
|
|
72
|
-
var _useState3 = useState(
|
|
78
|
+
var _useState3 = useState(''),
|
|
73
79
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var _useState5 = useState([]),
|
|
77
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
78
|
-
filteredOptions = _useState6[0],
|
|
79
|
-
setFilteredOptions = _useState6[1];
|
|
80
|
-
var _useState7 = useState(''),
|
|
81
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
82
|
-
selectedOption = _useState8[0],
|
|
83
|
-
setSelectedOption = _useState8[1];
|
|
84
|
-
var _useState9 = useState(''),
|
|
85
|
-
_useState0 = _slicedToArray(_useState9, 2),
|
|
86
|
-
chipError = _useState0[0],
|
|
87
|
-
setChipError = _useState0[1];
|
|
88
|
-
var _useState1 = useState(chips),
|
|
89
|
-
_useState10 = _slicedToArray(_useState1, 2),
|
|
90
|
-
localChips = _useState10[0],
|
|
91
|
-
setLocalChips = _useState10[1];
|
|
80
|
+
chipError = _useState4[0],
|
|
81
|
+
setChipError = _useState4[1];
|
|
92
82
|
var inputRef = useRef(null);
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (disabled) return;
|
|
128
|
-
if (e.key === 'Enter') {
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
if (selectedOption) {
|
|
131
|
-
handleSelectOption(selectedOption);
|
|
132
|
-
} else if (filteredOptions.length > 0) {
|
|
133
|
-
handleSelectOption(filteredOptions[0]);
|
|
134
|
-
setFilteredOptions([]);
|
|
135
|
-
} else if (allowCustomValues && inputValue.trim()) {
|
|
136
|
-
handleAddCustomValue(inputValue.trim());
|
|
137
|
-
}
|
|
138
|
-
} else if (e.key === ',' && allowCustomValues && inputValue.trim()) {
|
|
139
|
-
e.preventDefault();
|
|
140
|
-
handleAddCustomValue(inputValue.trim());
|
|
141
|
-
} else if (e.key === 'Escape') {
|
|
142
|
-
var _inputRef$current;
|
|
143
|
-
setShowDropdown(false);
|
|
144
|
-
setSelectedOption('');
|
|
145
|
-
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.blur();
|
|
146
|
-
} else if (e.key === 'ArrowDown') {
|
|
147
|
-
e.preventDefault();
|
|
148
|
-
if (filteredOptions.length > 0) {
|
|
149
|
-
var currentIndex = selectedOption ? filteredOptions.indexOf(selectedOption) : -1;
|
|
150
|
-
var nextIndex = currentIndex < filteredOptions.length - 1 ? currentIndex + 1 : 0;
|
|
151
|
-
setSelectedOption(filteredOptions[nextIndex]);
|
|
83
|
+
var containerRef = useRef(null);
|
|
84
|
+
var _useFormProps = useFormProps(),
|
|
85
|
+
setValue = _useFormProps.setValue;
|
|
86
|
+
var chipManagement = useChipManagement({
|
|
87
|
+
initialChips: chips,
|
|
88
|
+
fieldName: fieldName,
|
|
89
|
+
formProps: formProps,
|
|
90
|
+
setValue: setValue,
|
|
91
|
+
onAddChip: onAddChip,
|
|
92
|
+
onRemoveChip: onRemoveChip
|
|
93
|
+
});
|
|
94
|
+
var chipValidation = useChipValidation({
|
|
95
|
+
validationSchema: chipValidationSchema,
|
|
96
|
+
errorMessage: chipValidationErrorMessage,
|
|
97
|
+
allowInvalidChips: allowInvalidChips,
|
|
98
|
+
minChipLength: minChipLength,
|
|
99
|
+
maxChipLength: maxChipLength
|
|
100
|
+
});
|
|
101
|
+
var dropdownLogic = useDropdownLogic({
|
|
102
|
+
availableOptions: availableOptions,
|
|
103
|
+
chipTexts: chipManagement.getChipTexts(),
|
|
104
|
+
containerRef: containerRef
|
|
105
|
+
});
|
|
106
|
+
var handleSelectOption = function handleSelectOption(option) {
|
|
107
|
+
if (chipManagement.getChipTexts().includes(option)) return;
|
|
108
|
+
try {
|
|
109
|
+
var validatedChip = chipValidation.createValidatedChip(option);
|
|
110
|
+
chipManagement.addChip(validatedChip);
|
|
111
|
+
setInputValue('');
|
|
112
|
+
dropdownLogic.closeDropdown();
|
|
113
|
+
setChipError('');
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!allowInvalidChips) {
|
|
116
|
+
setChipError(error instanceof Error ? error.message : 'Invalid value');
|
|
152
117
|
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var handleAddCustomValue = function handleAddCustomValue(value) {
|
|
121
|
+
if (chipManagement.getChipTexts().includes(value)) return;
|
|
122
|
+
try {
|
|
123
|
+
var validatedChip = chipValidation.createValidatedChip(value);
|
|
124
|
+
chipManagement.addChip(validatedChip);
|
|
125
|
+
setInputValue('');
|
|
126
|
+
setChipError('');
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (!allowInvalidChips) {
|
|
129
|
+
setChipError(error instanceof Error ? error.message : 'Invalid value');
|
|
159
130
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var handleRemoveLastChip = function handleRemoveLastChip() {
|
|
134
|
+
var lastChip = chipManagement.chips[chipManagement.chips.length - 1];
|
|
135
|
+
if (lastChip) {
|
|
163
136
|
var chipText = typeof lastChip === 'string' ? lastChip : lastChip.text;
|
|
164
|
-
|
|
137
|
+
chipManagement.removeChip(chipText);
|
|
165
138
|
}
|
|
166
139
|
};
|
|
167
140
|
var handleInputChange = function handleInputChange(e) {
|
|
168
141
|
if (disabled) return;
|
|
169
|
-
|
|
170
|
-
|
|
142
|
+
var value = e.target.value;
|
|
143
|
+
setInputValue(value);
|
|
144
|
+
dropdownLogic.handleInputChange(value);
|
|
171
145
|
};
|
|
172
146
|
var handleInputFocus = function handleInputFocus() {
|
|
173
|
-
|
|
174
|
-
setShowDropdown(true);
|
|
175
|
-
}
|
|
147
|
+
dropdownLogic.handleInputFocus(inputValue);
|
|
176
148
|
};
|
|
177
|
-
var
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
};
|
|
194
|
-
var handleSelectOption = function handleSelectOption(option) {
|
|
195
|
-
// Check if option already exists in chips using memoized chipTexts
|
|
196
|
-
if (!chipTexts.includes(option)) {
|
|
197
|
-
if (chipValidationSchema) {
|
|
198
|
-
try {
|
|
199
|
-
chipValidationSchema.validateSync(option);
|
|
200
|
-
} catch (e) {
|
|
201
|
-
var message = chipValidationErrorMessage || e.message || 'Invalid value';
|
|
202
|
-
if (allowInvalidChips) {
|
|
203
|
-
var item = {
|
|
204
|
-
text: option,
|
|
205
|
-
hasError: true,
|
|
206
|
-
errorMessage: message
|
|
207
|
-
};
|
|
208
|
-
var _newChips = [].concat(_toConsumableArray(localChips), [item]);
|
|
209
|
-
setLocalChips(_newChips);
|
|
210
|
-
// Sync with form state - only valid chips (strings)
|
|
211
|
-
if (setValue) {
|
|
212
|
-
var validChips = _newChips.filter(function (chip) {
|
|
213
|
-
return typeof chip === 'string';
|
|
214
|
-
});
|
|
215
|
-
setValue(fieldName, validChips);
|
|
216
|
-
}
|
|
217
|
-
setInputValue('');
|
|
218
|
-
setShowDropdown(false);
|
|
219
|
-
setSelectedOption('');
|
|
220
|
-
return;
|
|
221
|
-
} else {
|
|
222
|
-
setChipError(message);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
onAddChip === null || onAddChip === void 0 || onAddChip(option);
|
|
228
|
-
var newChips = [].concat(_toConsumableArray(localChips), [option]);
|
|
229
|
-
setLocalChips(newChips);
|
|
230
|
-
// Sync with form state - only valid chips (strings)
|
|
231
|
-
if (setValue) {
|
|
232
|
-
var _validChips = newChips.filter(function (chip) {
|
|
233
|
-
return typeof chip === 'string';
|
|
234
|
-
});
|
|
235
|
-
setValue(fieldName, _validChips);
|
|
236
|
-
}
|
|
237
|
-
setInputValue('');
|
|
238
|
-
setShowDropdown(false);
|
|
239
|
-
setSelectedOption('');
|
|
240
|
-
setChipError('');
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
var handleAddCustomValue = function handleAddCustomValue(value) {
|
|
244
|
-
// Check if value already exists in chips
|
|
245
|
-
var chipTexts = localChips.map(function (chip) {
|
|
246
|
-
return typeof chip === 'string' ? chip : chip.text;
|
|
247
|
-
});
|
|
248
|
-
if (!chipTexts.includes(value)) {
|
|
249
|
-
// validate value if schema provided
|
|
250
|
-
if (chipValidationSchema) {
|
|
251
|
-
try {
|
|
252
|
-
chipValidationSchema.validateSync(value);
|
|
253
|
-
var item = {
|
|
254
|
-
text: value,
|
|
255
|
-
hasError: false,
|
|
256
|
-
errorMessage: ''
|
|
257
|
-
};
|
|
258
|
-
var newChips = [].concat(_toConsumableArray(localChips), [item]);
|
|
259
|
-
setLocalChips(newChips);
|
|
260
|
-
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
261
|
-
formProps.setFieldValue(fieldName, newChips);
|
|
262
|
-
}
|
|
263
|
-
if (setValue) {
|
|
264
|
-
var validChips = newChips.filter(function (chip) {
|
|
265
|
-
return !chip.hasError;
|
|
266
|
-
});
|
|
267
|
-
setValue(fieldName, validChips);
|
|
268
|
-
}
|
|
269
|
-
} catch (e) {
|
|
270
|
-
var message = chipValidationErrorMessage || e.message || 'Invalid value';
|
|
271
|
-
if (allowInvalidChips) {
|
|
272
|
-
var _item = {
|
|
273
|
-
text: value,
|
|
274
|
-
hasError: true,
|
|
275
|
-
errorMessage: message
|
|
276
|
-
};
|
|
277
|
-
var _newChips2 = [].concat(_toConsumableArray(localChips), [_item]);
|
|
278
|
-
setLocalChips(_newChips2);
|
|
279
|
-
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
280
|
-
formProps === null || formProps === void 0 || formProps.setFieldValue(fieldName, _newChips2);
|
|
281
|
-
}
|
|
282
|
-
if (setValue) {
|
|
283
|
-
var _validChips2 = _newChips2.filter(function (chip) {
|
|
284
|
-
return !chip.hasError;
|
|
285
|
-
});
|
|
286
|
-
setValue(fieldName, _validChips2);
|
|
287
|
-
}
|
|
288
|
-
} else {
|
|
289
|
-
setChipError(message);
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
} else {
|
|
294
|
-
var _newChips3 = [].concat(_toConsumableArray(localChips), [value]);
|
|
295
|
-
setLocalChips(_newChips3);
|
|
296
|
-
if (setValue) {
|
|
297
|
-
setValue(fieldName, _newChips3);
|
|
298
|
-
}
|
|
149
|
+
var keyboardNavigation = useKeyboardNavigation({
|
|
150
|
+
disabled: disabled,
|
|
151
|
+
inputValue: inputValue,
|
|
152
|
+
allowCustomValues: allowCustomValues,
|
|
153
|
+
chips: chipManagement.chips,
|
|
154
|
+
filteredOptions: dropdownLogic.filteredOptions,
|
|
155
|
+
selectedOption: dropdownLogic.selectedOption,
|
|
156
|
+
onEnter: function onEnter() {
|
|
157
|
+
// Default behavior for Enter key when no options are available
|
|
158
|
+
},
|
|
159
|
+
onAddCustomValue: handleAddCustomValue,
|
|
160
|
+
onNavigateOptions: dropdownLogic.navigateOptions,
|
|
161
|
+
onSelectOption: function onSelectOption(option) {
|
|
162
|
+
var selected = dropdownLogic.selectOption(option);
|
|
163
|
+
if (selected) {
|
|
164
|
+
handleSelectOption(selected);
|
|
299
165
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
166
|
+
},
|
|
167
|
+
onCloseDropdown: dropdownLogic.closeDropdown,
|
|
168
|
+
onRemoveLastChip: handleRemoveLastChip,
|
|
169
|
+
inputRef: inputRef
|
|
170
|
+
});
|
|
171
|
+
var inputPlaceholder = useMemo(function () {
|
|
172
|
+
if (chipManagement.chips.length === 0) return placeholder;
|
|
306
173
|
if (availableOptions.length > 0) return searchPlaceholder || searchPlaceholderText;
|
|
307
174
|
if (allowCustomValues) return typeAndEnterPlaceholderText;
|
|
308
175
|
return noOptionsPlaceholderText;
|
|
309
|
-
};
|
|
176
|
+
}, [chipManagement.chips.length, placeholder, availableOptions.length, searchPlaceholder, searchPlaceholderText, allowCustomValues, typeAndEnterPlaceholderText, noOptionsPlaceholderText]);
|
|
177
|
+
var hasError = chipError || chipManagement.hasErrorChips;
|
|
178
|
+
var errorMessage = chipError || chipManagement.getErrorMessage();
|
|
179
|
+
var containerClassName = useMemo(function () {
|
|
180
|
+
return classNames('multi-textarea-chips', className, {
|
|
181
|
+
'multi-textarea-chips--disabled': disabled,
|
|
182
|
+
'multi-textarea-chips--error': hasError
|
|
183
|
+
});
|
|
184
|
+
}, [className, disabled, hasError]);
|
|
185
|
+
var inputWrapperClassName = useMemo(function () {
|
|
186
|
+
return classNames('multi-textarea-input-wrapper', {
|
|
187
|
+
'with-error-styles': hasError
|
|
188
|
+
});
|
|
189
|
+
}, [hasError]);
|
|
310
190
|
return /*#__PURE__*/React.createElement("div", {
|
|
311
|
-
className:
|
|
312
|
-
|
|
313
|
-
|
|
191
|
+
className: containerClassName,
|
|
192
|
+
ref: containerRef
|
|
193
|
+
}, label && /*#__PURE__*/React.createElement("label", {
|
|
194
|
+
className: "multi-textarea-chips__label",
|
|
195
|
+
htmlFor: "".concat(fieldName, "-input")
|
|
314
196
|
}, label), /*#__PURE__*/React.createElement("div", {
|
|
315
|
-
className:
|
|
316
|
-
'with-error-styles': !!chipError
|
|
317
|
-
})
|
|
197
|
+
className: inputWrapperClassName
|
|
318
198
|
}, /*#__PURE__*/React.createElement("div", {
|
|
319
199
|
className: "multi-textarea-chips__content"
|
|
320
|
-
},
|
|
321
|
-
var isItem =
|
|
200
|
+
}, chipManagement.chips.map(function (chip, index) {
|
|
201
|
+
var isItem = _typeof(chip) === 'object';
|
|
322
202
|
var text = isItem ? chip.text : chip;
|
|
323
203
|
var hasError = isItem ? Boolean(chip.hasError) : false;
|
|
324
204
|
return /*#__PURE__*/React.createElement(Chips, {
|
|
325
205
|
key: "".concat(text, "-").concat(index),
|
|
326
206
|
text: text,
|
|
327
|
-
withAction:
|
|
207
|
+
withAction: !disabled,
|
|
328
208
|
onClick: function onClick() {
|
|
329
|
-
return
|
|
209
|
+
return chipManagement.removeChip(text);
|
|
330
210
|
},
|
|
331
211
|
size: "medium",
|
|
332
212
|
color: hasError ? 'danger' : 'primary',
|
|
333
213
|
type: "accent",
|
|
334
|
-
disabled: disabled
|
|
214
|
+
disabled: disabled,
|
|
215
|
+
"aria-label": "Remove ".concat(text, " chip")
|
|
335
216
|
});
|
|
336
217
|
}), /*#__PURE__*/React.createElement("div", {
|
|
337
218
|
className: "multi-textarea-chips__input-container"
|
|
338
|
-
}, /*#__PURE__*/React.createElement("input", _extends({
|
|
219
|
+
}, /*#__PURE__*/React.createElement("input", _extends({
|
|
220
|
+
id: "".concat(fieldName, "-input")
|
|
221
|
+
}, formProps, {
|
|
222
|
+
autoComplete: "off",
|
|
339
223
|
ref: inputRef,
|
|
340
224
|
type: "text",
|
|
341
225
|
value: inputValue,
|
|
342
226
|
onChange: handleInputChange,
|
|
343
|
-
onKeyDown: handleKeyDown,
|
|
227
|
+
onKeyDown: keyboardNavigation.handleKeyDown,
|
|
344
228
|
onFocus: handleInputFocus,
|
|
345
|
-
placeholder:
|
|
229
|
+
placeholder: inputPlaceholder,
|
|
346
230
|
className: "multi-textarea-chips__input",
|
|
347
|
-
disabled: disabled
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
231
|
+
disabled: disabled,
|
|
232
|
+
"aria-describedby": hasError ? "".concat(fieldName, "-error") : helperText ? "".concat(fieldName, "-helper") : undefined,
|
|
233
|
+
"aria-invalid": hasError ? 'true' : 'false',
|
|
234
|
+
"aria-expanded": dropdownLogic.showDropdown,
|
|
235
|
+
"aria-autocomplete": "list",
|
|
236
|
+
role: "combobox"
|
|
237
|
+
})), dropdownLogic.showDropdown && /*#__PURE__*/React.createElement("div", {
|
|
238
|
+
className: "multi-textarea-chips__dropdown",
|
|
239
|
+
role: "listbox",
|
|
240
|
+
"aria-label": "Available options"
|
|
241
|
+
}, dropdownLogic.filteredOptions.map(function (option) {
|
|
351
242
|
return /*#__PURE__*/React.createElement("div", {
|
|
352
243
|
key: option,
|
|
353
244
|
className: classNames('multi-textarea-chips__dropdown-item', {
|
|
354
|
-
'multi-textarea-chips__dropdown-item--selected': selectedOption === option
|
|
245
|
+
'multi-textarea-chips__dropdown-item--selected': dropdownLogic.selectedOption === option
|
|
355
246
|
}),
|
|
356
247
|
onClick: function onClick() {
|
|
357
248
|
return handleSelectOption(option);
|
|
358
|
-
}
|
|
249
|
+
},
|
|
250
|
+
role: "option",
|
|
251
|
+
"aria-selected": dropdownLogic.selectedOption === option
|
|
359
252
|
}, /*#__PURE__*/React.createElement("div", {
|
|
360
253
|
className: "multi-textarea-chips__radio"
|
|
361
254
|
}, /*#__PURE__*/React.createElement("div", {
|
|
362
255
|
className: classNames('multi-textarea-chips__radio-button', {
|
|
363
|
-
'multi-textarea-chips__radio-button--selected': selectedOption === option
|
|
256
|
+
'multi-textarea-chips__radio-button--selected': dropdownLogic.selectedOption === option
|
|
364
257
|
})
|
|
365
258
|
})), /*#__PURE__*/React.createElement("span", {
|
|
366
259
|
className: "multi-textarea-chips__option-text"
|
|
367
260
|
}, option));
|
|
368
|
-
}))))),
|
|
369
|
-
message:
|
|
370
|
-
}), helperText && !
|
|
261
|
+
}))))), hasError && /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
262
|
+
message: errorMessage
|
|
263
|
+
}), helperText && !hasError && /*#__PURE__*/React.createElement("div", {
|
|
264
|
+
id: "".concat(fieldName, "-helper"),
|
|
371
265
|
className: "multi-textarea-chips__helper"
|
|
372
266
|
}, helperText));
|
|
373
267
|
};
|
|
268
|
+
var MultiTextareaWithChips = /*#__PURE__*/memo(MultiTextareaWithChipsComponent);
|
|
374
269
|
MultiTextareaWithChips.displayName = 'MultiTextareaWithChips';
|
|
375
270
|
|
|
376
271
|
export { MultiTextareaWithChips };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useChipManagement } from './useChipManagement.js';
|
|
2
|
+
export { useChipValidation } from './useChipValidation.js';
|
|
3
|
+
export { useDropdownLogic } from './useDropdownLogic.js';
|
|
4
|
+
export { useKeyboardNavigation } from './useKeyboardNavigation.js';
|
|
5
|
+
import '../../../typeof-e9310111.js';
|
|
6
|
+
import '../../../toConsumableArray-d592cd83.js';
|
|
7
|
+
import '../../../slicedToArray-093df980.js';
|
|
8
|
+
import 'react';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChipValue } from '../types';
|
|
2
|
+
interface UseChipManagementProps {
|
|
3
|
+
initialChips: ChipValue[];
|
|
4
|
+
fieldName: string;
|
|
5
|
+
formProps?: {
|
|
6
|
+
setFieldValue?: (fieldName: string, value: TFormValue) => void;
|
|
7
|
+
[key: string]: TFormValue | ((fieldName: string, value: TFormValue) => void) | undefined;
|
|
8
|
+
};
|
|
9
|
+
setValue?: (fieldName: string, value: TFormValue) => void;
|
|
10
|
+
onAddChip?: (chip: string) => void;
|
|
11
|
+
onRemoveChip?: (chip: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const useChipManagement: ({ initialChips, fieldName, formProps, setValue, onAddChip, onRemoveChip }: UseChipManagementProps) => {
|
|
14
|
+
chips: ChipValue[];
|
|
15
|
+
addChip: (chip: ChipValue) => void;
|
|
16
|
+
removeChip: (chipText: string) => void;
|
|
17
|
+
getChipTexts: () => string[];
|
|
18
|
+
hasErrorChips: boolean;
|
|
19
|
+
getErrorMessage: () => string;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { _ as _typeof } from '../../../typeof-e9310111.js';
|
|
2
|
+
import { _ as _toConsumableArray } from '../../../toConsumableArray-d592cd83.js';
|
|
3
|
+
import { _ as _slicedToArray } from '../../../slicedToArray-093df980.js';
|
|
4
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
5
|
+
|
|
6
|
+
var useChipManagement = function useChipManagement(_ref) {
|
|
7
|
+
var initialChips = _ref.initialChips,
|
|
8
|
+
fieldName = _ref.fieldName,
|
|
9
|
+
formProps = _ref.formProps,
|
|
10
|
+
setValue = _ref.setValue,
|
|
11
|
+
onAddChip = _ref.onAddChip,
|
|
12
|
+
onRemoveChip = _ref.onRemoveChip;
|
|
13
|
+
var _useState = useState(initialChips),
|
|
14
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
15
|
+
chips = _useState2[0],
|
|
16
|
+
setChips = _useState2[1];
|
|
17
|
+
var isUserInteraction = useRef(false);
|
|
18
|
+
useEffect(function () {
|
|
19
|
+
if (!isUserInteraction.current) {
|
|
20
|
+
setChips(initialChips);
|
|
21
|
+
}
|
|
22
|
+
}, [initialChips]);
|
|
23
|
+
var updateFormValue = useCallback(function (newChips) {
|
|
24
|
+
if (isUserInteraction.current) {
|
|
25
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
26
|
+
formProps.setFieldValue(fieldName, newChips);
|
|
27
|
+
}
|
|
28
|
+
if (setValue) {
|
|
29
|
+
setValue(fieldName, newChips);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}, [formProps, setValue, fieldName]);
|
|
33
|
+
var addChip = useCallback(function (chip) {
|
|
34
|
+
isUserInteraction.current = true;
|
|
35
|
+
var newChips = [].concat(_toConsumableArray(chips), [chip]);
|
|
36
|
+
setChips(newChips);
|
|
37
|
+
updateFormValue(newChips);
|
|
38
|
+
if (typeof chip === 'string') {
|
|
39
|
+
onAddChip === null || onAddChip === void 0 || onAddChip(chip);
|
|
40
|
+
} else {
|
|
41
|
+
onAddChip === null || onAddChip === void 0 || onAddChip(chip.text);
|
|
42
|
+
}
|
|
43
|
+
}, [chips, updateFormValue, onAddChip]);
|
|
44
|
+
var removeChip = useCallback(function (chipText) {
|
|
45
|
+
isUserInteraction.current = true;
|
|
46
|
+
var newChips = chips.filter(function (chip) {
|
|
47
|
+
var text = typeof chip === 'string' ? chip : chip.text;
|
|
48
|
+
return text !== chipText;
|
|
49
|
+
});
|
|
50
|
+
setChips(newChips);
|
|
51
|
+
updateFormValue(newChips);
|
|
52
|
+
onRemoveChip === null || onRemoveChip === void 0 || onRemoveChip(chipText);
|
|
53
|
+
}, [chips, updateFormValue, onRemoveChip]);
|
|
54
|
+
var getChipTexts = useCallback(function () {
|
|
55
|
+
return chips.map(function (chip) {
|
|
56
|
+
return typeof chip === 'string' ? chip : chip.text;
|
|
57
|
+
});
|
|
58
|
+
}, [chips]);
|
|
59
|
+
var hasErrorChips = chips.some(function (chip) {
|
|
60
|
+
return _typeof(chip) === 'object' && chip.hasError;
|
|
61
|
+
});
|
|
62
|
+
var getErrorMessage = useCallback(function () {
|
|
63
|
+
var errorChips = chips.filter(function (chip) {
|
|
64
|
+
return _typeof(chip) === 'object' && chip.hasError;
|
|
65
|
+
});
|
|
66
|
+
var firstError = errorChips.find(function (chip) {
|
|
67
|
+
return chip.errorMessage;
|
|
68
|
+
});
|
|
69
|
+
return (firstError === null || firstError === void 0 ? void 0 : firstError.errorMessage) || '';
|
|
70
|
+
}, [chips]);
|
|
71
|
+
return {
|
|
72
|
+
chips: chips,
|
|
73
|
+
addChip: addChip,
|
|
74
|
+
removeChip: removeChip,
|
|
75
|
+
getChipTexts: getChipTexts,
|
|
76
|
+
hasErrorChips: hasErrorChips,
|
|
77
|
+
getErrorMessage: getErrorMessage
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { useChipManagement };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AnySchema } from 'yup';
|
|
2
|
+
import type { TChipItem } from '../types';
|
|
3
|
+
interface UseChipValidationProps {
|
|
4
|
+
validationSchema?: AnySchema;
|
|
5
|
+
errorMessage?: string;
|
|
6
|
+
allowInvalidChips?: boolean;
|
|
7
|
+
minChipLength?: number;
|
|
8
|
+
maxChipLength?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const useChipValidation: ({ validationSchema, errorMessage, allowInvalidChips, minChipLength, maxChipLength }: UseChipValidationProps) => {
|
|
11
|
+
createValidatedChip: (chipText: string) => TChipItem;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
var useChipValidation = function useChipValidation(_ref) {
|
|
4
|
+
var validationSchema = _ref.validationSchema,
|
|
5
|
+
errorMessage = _ref.errorMessage,
|
|
6
|
+
_ref$allowInvalidChip = _ref.allowInvalidChips,
|
|
7
|
+
allowInvalidChips = _ref$allowInvalidChip === void 0 ? false : _ref$allowInvalidChip,
|
|
8
|
+
minChipLength = _ref.minChipLength,
|
|
9
|
+
maxChipLength = _ref.maxChipLength;
|
|
10
|
+
var createValidatedChip = useCallback(function (chipText) {
|
|
11
|
+
var trimmedText = chipText.trim();
|
|
12
|
+
if (minChipLength && trimmedText.length < minChipLength) {
|
|
13
|
+
var message = "Chip must be at least ".concat(minChipLength, " characters long");
|
|
14
|
+
if (!allowInvalidChips) {
|
|
15
|
+
throw new Error(message);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
text: trimmedText,
|
|
19
|
+
hasError: true,
|
|
20
|
+
errorMessage: message
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (maxChipLength && trimmedText.length > maxChipLength) {
|
|
24
|
+
var _message = "Chip must be no more than ".concat(maxChipLength, " characters long");
|
|
25
|
+
if (!allowInvalidChips) {
|
|
26
|
+
throw new Error(_message);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
text: trimmedText,
|
|
30
|
+
hasError: true,
|
|
31
|
+
errorMessage: _message
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (validationSchema) {
|
|
35
|
+
try {
|
|
36
|
+
validationSchema.validateSync(trimmedText);
|
|
37
|
+
return {
|
|
38
|
+
text: trimmedText,
|
|
39
|
+
hasError: false,
|
|
40
|
+
errorMessage: ''
|
|
41
|
+
};
|
|
42
|
+
} catch (error) {
|
|
43
|
+
var _message2 = errorMessage || error.message || 'Invalid value';
|
|
44
|
+
if (!allowInvalidChips) {
|
|
45
|
+
throw new Error(_message2);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
text: trimmedText,
|
|
49
|
+
hasError: true,
|
|
50
|
+
errorMessage: _message2
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
text: trimmedText,
|
|
56
|
+
hasError: false,
|
|
57
|
+
errorMessage: ''
|
|
58
|
+
};
|
|
59
|
+
}, [validationSchema, errorMessage, allowInvalidChips, minChipLength, maxChipLength]);
|
|
60
|
+
return {
|
|
61
|
+
createValidatedChip: createValidatedChip
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { useChipValidation };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface UseDropdownLogicProps {
|
|
3
|
+
availableOptions: string[];
|
|
4
|
+
chipTexts: string[];
|
|
5
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
6
|
+
}
|
|
7
|
+
export declare const useDropdownLogic: ({ availableOptions, chipTexts, containerRef }: UseDropdownLogicProps) => {
|
|
8
|
+
showDropdown: boolean;
|
|
9
|
+
filteredOptions: string[];
|
|
10
|
+
selectedOption: string;
|
|
11
|
+
handleInputFocus: (inputValue: string) => void;
|
|
12
|
+
handleInputChange: (inputValue: string) => void;
|
|
13
|
+
navigateOptions: (direction: 'up' | 'down') => void;
|
|
14
|
+
selectOption: (option?: string) => string | null;
|
|
15
|
+
closeDropdown: () => void;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { _ as _slicedToArray } from '../../../slicedToArray-093df980.js';
|
|
2
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
var useDropdownLogic = function useDropdownLogic(_ref) {
|
|
5
|
+
var availableOptions = _ref.availableOptions,
|
|
6
|
+
chipTexts = _ref.chipTexts,
|
|
7
|
+
containerRef = _ref.containerRef;
|
|
8
|
+
var _useState = useState(false),
|
|
9
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
10
|
+
showDropdown = _useState2[0],
|
|
11
|
+
setShowDropdown = _useState2[1];
|
|
12
|
+
var _useState3 = useState([]),
|
|
13
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
14
|
+
filteredOptions = _useState4[0],
|
|
15
|
+
setFilteredOptions = _useState4[1];
|
|
16
|
+
var _useState5 = useState(''),
|
|
17
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
18
|
+
selectedOption = _useState6[0],
|
|
19
|
+
setSelectedOption = _useState6[1];
|
|
20
|
+
var filterOptions = useCallback(function (inputValue) {
|
|
21
|
+
if (availableOptions.length === 0) return;
|
|
22
|
+
var filtered = availableOptions.filter(function (option) {
|
|
23
|
+
return option.toLowerCase().includes(inputValue.toLowerCase()) && !chipTexts.includes(option);
|
|
24
|
+
});
|
|
25
|
+
setFilteredOptions(filtered);
|
|
26
|
+
}, [availableOptions, chipTexts]);
|
|
27
|
+
var handleInputFocus = useCallback(function (inputValue) {
|
|
28
|
+
if (availableOptions.length > 0) {
|
|
29
|
+
if (inputValue.trim()) {
|
|
30
|
+
setShowDropdown(true);
|
|
31
|
+
} else {
|
|
32
|
+
filterOptions('');
|
|
33
|
+
setShowDropdown(true);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, [availableOptions.length, filterOptions]);
|
|
37
|
+
var handleInputChange = useCallback(function (inputValue) {
|
|
38
|
+
setSelectedOption('');
|
|
39
|
+
filterOptions(inputValue);
|
|
40
|
+
setShowDropdown(availableOptions.length > 0 && inputValue.trim().length > 0);
|
|
41
|
+
}, [filterOptions, availableOptions.length]);
|
|
42
|
+
var navigateOptions = useCallback(function (direction) {
|
|
43
|
+
if (filteredOptions.length === 0) return;
|
|
44
|
+
var currentIndex = selectedOption ? filteredOptions.indexOf(selectedOption) : -1;
|
|
45
|
+
var nextIndex;
|
|
46
|
+
if (direction === 'down') {
|
|
47
|
+
nextIndex = currentIndex < filteredOptions.length - 1 ? currentIndex + 1 : 0;
|
|
48
|
+
} else {
|
|
49
|
+
nextIndex = currentIndex > 0 ? currentIndex - 1 : filteredOptions.length - 1;
|
|
50
|
+
}
|
|
51
|
+
setSelectedOption(filteredOptions[nextIndex]);
|
|
52
|
+
}, [filteredOptions, selectedOption]);
|
|
53
|
+
var selectOption = useCallback(function (option) {
|
|
54
|
+
var optionToSelect = option || selectedOption || filteredOptions[0];
|
|
55
|
+
if (optionToSelect) {
|
|
56
|
+
setShowDropdown(false);
|
|
57
|
+
setSelectedOption('');
|
|
58
|
+
return optionToSelect;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}, [selectedOption, filteredOptions]);
|
|
62
|
+
var closeDropdown = useCallback(function () {
|
|
63
|
+
setShowDropdown(false);
|
|
64
|
+
setSelectedOption('');
|
|
65
|
+
}, []);
|
|
66
|
+
useEffect(function () {
|
|
67
|
+
var handleClickOutside = function handleClickOutside(event) {
|
|
68
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
69
|
+
closeDropdown();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
if (showDropdown) {
|
|
73
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
74
|
+
}
|
|
75
|
+
return function () {
|
|
76
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
77
|
+
};
|
|
78
|
+
}, [showDropdown, closeDropdown, containerRef]);
|
|
79
|
+
return {
|
|
80
|
+
showDropdown: showDropdown,
|
|
81
|
+
filteredOptions: filteredOptions,
|
|
82
|
+
selectedOption: selectedOption,
|
|
83
|
+
handleInputFocus: handleInputFocus,
|
|
84
|
+
handleInputChange: handleInputChange,
|
|
85
|
+
navigateOptions: navigateOptions,
|
|
86
|
+
selectOption: selectOption,
|
|
87
|
+
closeDropdown: closeDropdown
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export { useDropdownLogic };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { KeyboardEvent } from 'react';
|
|
2
|
+
interface UseKeyboardNavigationProps {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
inputValue: string;
|
|
5
|
+
allowCustomValues: boolean;
|
|
6
|
+
chips: Array<string | {
|
|
7
|
+
text: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}>;
|
|
10
|
+
filteredOptions: string[];
|
|
11
|
+
selectedOption: string;
|
|
12
|
+
onEnter: () => void;
|
|
13
|
+
onAddCustomValue: (value: string) => void;
|
|
14
|
+
onNavigateOptions: (direction: 'up' | 'down') => void;
|
|
15
|
+
onSelectOption: (option?: string) => void;
|
|
16
|
+
onCloseDropdown: () => void;
|
|
17
|
+
onRemoveLastChip: () => void;
|
|
18
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
19
|
+
}
|
|
20
|
+
export declare const useKeyboardNavigation: ({ disabled, inputValue, allowCustomValues, chips, filteredOptions, selectedOption, onEnter, onAddCustomValue, onNavigateOptions, onSelectOption, onCloseDropdown, onRemoveLastChip, inputRef }: UseKeyboardNavigationProps) => {
|
|
21
|
+
handleKeyDown: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
var useKeyboardNavigation = function useKeyboardNavigation(_ref) {
|
|
4
|
+
var disabled = _ref.disabled,
|
|
5
|
+
inputValue = _ref.inputValue,
|
|
6
|
+
allowCustomValues = _ref.allowCustomValues,
|
|
7
|
+
chips = _ref.chips,
|
|
8
|
+
filteredOptions = _ref.filteredOptions,
|
|
9
|
+
selectedOption = _ref.selectedOption,
|
|
10
|
+
onEnter = _ref.onEnter,
|
|
11
|
+
onAddCustomValue = _ref.onAddCustomValue,
|
|
12
|
+
onNavigateOptions = _ref.onNavigateOptions,
|
|
13
|
+
onSelectOption = _ref.onSelectOption,
|
|
14
|
+
onCloseDropdown = _ref.onCloseDropdown,
|
|
15
|
+
onRemoveLastChip = _ref.onRemoveLastChip,
|
|
16
|
+
inputRef = _ref.inputRef;
|
|
17
|
+
var handleKeyDown = useCallback(function (e) {
|
|
18
|
+
var _inputRef$current;
|
|
19
|
+
if (disabled) return;
|
|
20
|
+
var trimmedInput = inputValue.trim();
|
|
21
|
+
switch (e.key) {
|
|
22
|
+
case 'Enter':
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
if (selectedOption) {
|
|
25
|
+
onSelectOption(selectedOption);
|
|
26
|
+
} else if (filteredOptions.length > 0) {
|
|
27
|
+
onSelectOption(filteredOptions[0]);
|
|
28
|
+
} else if (allowCustomValues && trimmedInput) {
|
|
29
|
+
onAddCustomValue(trimmedInput);
|
|
30
|
+
} else {
|
|
31
|
+
onEnter();
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case ',':
|
|
35
|
+
if (allowCustomValues && trimmedInput) {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
onAddCustomValue(trimmedInput);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
case ' ':
|
|
41
|
+
case 'Space':
|
|
42
|
+
if (allowCustomValues && trimmedInput) {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
onAddCustomValue(trimmedInput);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case 'Escape':
|
|
48
|
+
onCloseDropdown();
|
|
49
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.blur();
|
|
50
|
+
break;
|
|
51
|
+
case 'ArrowDown':
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
onNavigateOptions('down');
|
|
54
|
+
break;
|
|
55
|
+
case 'ArrowUp':
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
onNavigateOptions('up');
|
|
58
|
+
break;
|
|
59
|
+
case 'Backspace':
|
|
60
|
+
if (!inputValue && chips.length > 0) {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
onRemoveLastChip();
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}, [disabled, inputValue, allowCustomValues, chips.length, filteredOptions, selectedOption, onEnter, onAddCustomValue, onNavigateOptions, onSelectOption, onCloseDropdown, onRemoveLastChip, inputRef]);
|
|
67
|
+
return {
|
|
68
|
+
handleKeyDown: handleKeyDown
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { useKeyboardNavigation };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { MultiTextareaWithChips } from './MultiTextareaWithChips.js';
|
|
2
|
-
export {
|
|
2
|
+
export { useChipManagement } from './hooks/useChipManagement.js';
|
|
3
|
+
export { useChipValidation } from './hooks/useChipValidation.js';
|
|
4
|
+
export { useDropdownLogic } from './hooks/useDropdownLogic.js';
|
|
5
|
+
export { useKeyboardNavigation } from './hooks/useKeyboardNavigation.js';
|
|
3
6
|
import '../../extends-cc60c71c.js';
|
|
4
|
-
import '../../
|
|
7
|
+
import '../../typeof-e9310111.js';
|
|
5
8
|
import '../../slicedToArray-093df980.js';
|
|
6
9
|
import 'react';
|
|
7
10
|
import '../Chips/Chips.js';
|
|
@@ -12,7 +15,6 @@ import 'dayjs';
|
|
|
12
15
|
import '../Chips/types.js';
|
|
13
16
|
import '../SVGIcons/IconDismissCircleFilled.js';
|
|
14
17
|
import '../../defineProperty-109927cc.js';
|
|
15
|
-
import '../../typeof-e9310111.js';
|
|
16
18
|
import '../Chips/consts.js';
|
|
17
19
|
import '../../helperComponents/ErrorMessage/ErrorMessage.js';
|
|
18
20
|
import '../../helperComponents/IconDynamicComponent/IconDynamicComponent.js';
|
|
@@ -36,3 +38,4 @@ import '../SVGIcons/IconInfo.js';
|
|
|
36
38
|
import 'react-syntax-highlighter';
|
|
37
39
|
import '../../hooks/useFormProps.js';
|
|
38
40
|
import '../../context/types.js';
|
|
41
|
+
import '../../toConsumableArray-d592cd83.js';
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import type { AnySchema } from 'yup';
|
|
2
|
+
export interface TChipItem {
|
|
3
|
+
text: string;
|
|
4
|
+
hasError?: boolean;
|
|
5
|
+
errorMessage?: string;
|
|
6
|
+
id?: string | number;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export type ChipValue = string | TChipItem;
|
|
2
10
|
export interface TMultiTextareaWithChipsProps extends IFormCompProps {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
chips?: Array<string | TChipItem>;
|
|
11
|
+
label: string;
|
|
12
|
+
placeholder: string;
|
|
13
|
+
helperText?: string;
|
|
14
|
+
chips?: ChipValue[];
|
|
15
|
+
onAddChip?: (chip: string) => void;
|
|
16
|
+
onRemoveChip?: (chip: string) => void;
|
|
10
17
|
className?: string;
|
|
11
18
|
disabled?: boolean;
|
|
12
|
-
|
|
19
|
+
availableOptions?: string[];
|
|
20
|
+
allowCustomValues?: boolean;
|
|
21
|
+
searchPlaceholder?: string;
|
|
22
|
+
chipValidationSchema?: AnySchema;
|
|
23
|
+
chipValidationErrorMessage?: string;
|
|
24
|
+
allowInvalidChips?: boolean;
|
|
25
|
+
minChipLength?: number;
|
|
26
|
+
maxChipLength?: number;
|
|
27
|
+
searchPlaceholderText?: string;
|
|
28
|
+
typeAndEnterPlaceholderText?: string;
|
|
29
|
+
noOptionsPlaceholderText?: string;
|
|
13
30
|
fieldName?: string;
|
|
14
31
|
formProps?: {
|
|
15
32
|
setFieldValue?: (fieldName: string, value: TFormValue, shouldValidate?: {
|
|
@@ -19,27 +36,4 @@ export interface TMultiTextareaWithChipsProps extends IFormCompProps {
|
|
|
19
36
|
shouldValidate: boolean;
|
|
20
37
|
}) => void) | undefined;
|
|
21
38
|
};
|
|
22
|
-
helperText?: string;
|
|
23
|
-
label: string;
|
|
24
|
-
maxChipLength?: number;
|
|
25
|
-
maxChips?: number;
|
|
26
|
-
minChipLength?: number;
|
|
27
|
-
minChips?: number;
|
|
28
|
-
noOptionsPlaceholderText?: string;
|
|
29
|
-
onAddChip?: (chip: string) => void;
|
|
30
|
-
onAddChipItem?: (chip: TChipItem) => void;
|
|
31
|
-
onRemoveChip?: (chip: string) => void;
|
|
32
|
-
onRemoveChipItem?: (chip: TChipItem) => void;
|
|
33
|
-
placeholder: string;
|
|
34
|
-
required?: boolean;
|
|
35
|
-
searchPlaceholder?: string;
|
|
36
|
-
searchPlaceholderText?: string;
|
|
37
|
-
typeAndEnterPlaceholderText?: string;
|
|
38
|
-
validateChip?: (chip: string) => void;
|
|
39
39
|
}
|
|
40
|
-
export type TChipItem = {
|
|
41
|
-
text: string;
|
|
42
|
-
hasError?: boolean;
|
|
43
|
-
errorMessage?: string;
|
|
44
|
-
id?: string | number;
|
|
45
|
-
};
|
|
@@ -94,6 +94,8 @@ var Select = function Select(props) {
|
|
|
94
94
|
isSearchable = _props$isSearchable === void 0 ? false : _props$isSearchable,
|
|
95
95
|
_props$isDynamicSearc = props.isDynamicSearchable,
|
|
96
96
|
isDynamicSearchable = _props$isDynamicSearc === void 0 ? false : _props$isDynamicSearc,
|
|
97
|
+
_props$trimSearchValu = props.trimSearchValue,
|
|
98
|
+
trimSearchValue = _props$trimSearchValu === void 0 ? false : _props$trimSearchValu,
|
|
97
99
|
disabled = props.disabled,
|
|
98
100
|
_props$dataId = props.dataId,
|
|
99
101
|
dataId = _props$dataId === void 0 ? '' : _props$dataId,
|
|
@@ -212,8 +214,9 @@ var Select = function Select(props) {
|
|
|
212
214
|
if (!searchValue) {
|
|
213
215
|
return options;
|
|
214
216
|
}
|
|
217
|
+
var processedSearchValue = trimSearchValue ? searchValue.trim().toLowerCase() : searchValue.toLowerCase();
|
|
215
218
|
return options.filter(function (dataItem) {
|
|
216
|
-
return typeof dataItem.label === 'string' && dataItem.label.toLowerCase().includes(
|
|
219
|
+
return typeof dataItem.label === 'string' && dataItem.label.toLowerCase().includes(processedSearchValue);
|
|
217
220
|
});
|
|
218
221
|
}, [searchValue, options]);
|
|
219
222
|
var onItemSelect = function onItemSelect(value) {
|
|
@@ -127,6 +127,7 @@ export interface TSingleSelectPropTypes extends IFormCompProps, TSelectBaseProps
|
|
|
127
127
|
onInputFormatting?: (value: string) => string;
|
|
128
128
|
isSearchable?: boolean;
|
|
129
129
|
isDynamicSearchable?: boolean;
|
|
130
|
+
trimSearchValue?: boolean;
|
|
130
131
|
outerHelperText?: string;
|
|
131
132
|
innerHelperText?: string;
|
|
132
133
|
labelAddons?: JSX.Element;
|
package/index.js
CHANGED
|
@@ -473,7 +473,10 @@ export { IconArrowCircleDownSplit } from './components/SVGIcons/IconArrowCircleD
|
|
|
473
473
|
export { OneTimePassword } from './components/OneTimePassword/OneTimePassword.js';
|
|
474
474
|
export { OptionItem } from './helperComponents/OptionItem/OptionItem.js';
|
|
475
475
|
export { MultiTextareaWithChips } from './components/MultiTextareaWithChips/MultiTextareaWithChips.js';
|
|
476
|
-
export {
|
|
476
|
+
export { useChipManagement } from './components/MultiTextareaWithChips/hooks/useChipManagement.js';
|
|
477
|
+
export { useChipValidation } from './components/MultiTextareaWithChips/hooks/useChipValidation.js';
|
|
478
|
+
export { useDropdownLogic } from './components/MultiTextareaWithChips/hooks/useDropdownLogic.js';
|
|
479
|
+
export { useKeyboardNavigation } from './components/MultiTextareaWithChips/hooks/useKeyboardNavigation.js';
|
|
477
480
|
export { FormContext } from './context/types.js';
|
|
478
481
|
import 'react';
|
|
479
482
|
export { useFormProps } from './hooks/useFormProps.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { JSX } from 'react';
|
|
2
2
|
declare const _default: {
|
|
3
3
|
title: string;
|
|
4
|
-
component: React.
|
|
4
|
+
component: React.NamedExoticComponent<import("../components/MultiTextareaWithChips").TMultiTextareaWithChipsProps>;
|
|
5
5
|
parameters: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: {
|
|
@@ -11,14 +11,4 @@ declare const _default: {
|
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
export default _default;
|
|
14
|
-
export declare const Default: () => JSX.Element;
|
|
15
|
-
export declare const WithInitialChips: () => JSX.Element;
|
|
16
|
-
export declare const WithLongChips: () => JSX.Element;
|
|
17
|
-
export declare const Disabled: () => JSX.Element;
|
|
18
|
-
export declare const WithSearchAndSelect: () => JSX.Element;
|
|
19
|
-
export declare const WithCustomValuesAllowed: () => JSX.Element;
|
|
20
|
-
export declare const WithEmailValidation: () => JSX.Element;
|
|
21
|
-
export declare const WithInvalidChipsAllowed: () => JSX.Element;
|
|
22
|
-
export declare const PerformanceTest: () => JSX.Element;
|
|
23
|
-
export declare const WithHdmSerialNumberValidation: () => JSX.Element;
|
|
24
14
|
export declare const SimpleFormUsage: () => JSX.Element;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
var InputWrapper = function InputWrapper(_ref) {
|
|
4
|
-
var children = _ref.children,
|
|
5
|
-
_ref$className = _ref.className,
|
|
6
|
-
className = _ref$className === void 0 ? '' : _ref$className;
|
|
7
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
8
|
-
className: "bg-gray-50 border border-gray-300 rounded-lg p-3 min-h-12 ".concat(className)
|
|
9
|
-
}, children);
|
|
10
|
-
};
|
|
11
|
-
InputWrapper.displayName = 'InputWrapper';
|
|
12
|
-
|
|
13
|
-
export { InputWrapper };
|