@synerise/ds-collector 0.6.24 → 0.6.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.6.26](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@0.6.25...@synerise/ds-collector@0.6.26) (2023-10-17)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **collector:** added event capture for "add" ([6b3f129](https://github.com/Synerise/synerise-design/commit/6b3f12947eeeba555fb3cd2c4218f5335ddf6042))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.6.25](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@0.6.24...@synerise/ds-collector@0.6.25) (2023-10-11)
18
+
19
+ **Note:** Version bump only for package @synerise/ds-collector
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.6.24](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@0.6.23...@synerise/ds-collector@0.6.24) (2023-10-06)
7
26
 
8
27
  **Note:** Version bump only for package @synerise/ds-collector
package/README.md CHANGED
@@ -19,9 +19,12 @@ yarn add @synerise/ds-collector
19
19
  import Collector from '@synerise/ds-collector'
20
20
 
21
21
  <Collector
22
- selected={["Selected 1]}
23
- suggestions={["Suggestions 1]}
22
+ selected={["Selected 1"]}
23
+ suggestions={["Suggestions 1"]}
24
24
  onConfirm={console.log}
25
+ onItemAdd={value => ({
26
+ text: value,
27
+ })}
25
28
  texts={{ add: 'Add', cancel: 'Cancel', placeholder: "Please select values" }}
26
29
  />
27
30
  ```
@@ -56,6 +59,7 @@ import Collector from '@synerise/ds-collector'
56
59
  | onCancel | Callback executed when user clicks "cancel" button | () => void | --- |
57
60
  | onItemSelect | Callback executed when user selects an item | (value: CollectorValue) => void | --- |
58
61
  | onItemDeselect | Callback executed when user removes already selected item | (value: CollectorValue) => void | --- |
62
+ | onMultipleItemsSelect | Callback executed when user pastes multiple items | (values: CollectorValue[]) => void | --- |
59
63
  | onItemAdd | Callback executed when user adds a custom item to the list. | (itemName: React.ReactText) => CollectorValue | --- |
60
64
  | onSearchValueChange | Callback executed when user changes the value of the input | (value: string) => void | --- |
61
65
  | renderItem | Custom function for rendering a custom item inside dropdown | (value: CollectorValue) => JSX.Element | --- |
@@ -65,6 +69,9 @@ import Collector from '@synerise/ds-collector'
65
69
  | suggestions | Array of items which are displayed when showing suggestions dropdown | CollectorValue[] | [] |
66
70
  | texts | Texts object for the component | CollectorTexts | {} |
67
71
  | scrollbarProps | Object with scrollbar configturaion | ScrollbarAdditionalProps | - |
72
+ | allowPaste | Object with scrollbar configturaion | boolean | - |
73
+ | showCount | Display item counter above collector | boolean | - |
74
+ | valuesSeparator | Multi-value paste delimiter (separator) | CollectorValuesSeparator `;`, `/` or `,` | `;` |
68
75
 
69
76
  `CollectorValue = {[key:string]: any}`
70
77
 
@@ -1,3 +1,40 @@
1
+ import React from 'react';
1
2
  import { CollectorProps } from './Collector.types';
2
- declare const Collector: ({ allowCustomValue, allowMultipleValues, addButtonProps, cancelButtonProps, keepSearchQueryOnSelect, error, className, description, enableCustomFilteringSuggestions, selected, suggestions, showNavigationHints, onConfirm, onCancel, label, errorText, disabled, fixedHeight, texts, lookupConfig, onItemAdd, onItemDeselect, onItemSelect, dropdownContent, disableButtonPanel, disableSearch, dropdownItemHeight, searchValue, renderItem, onSearchValueChange, }: CollectorProps) => JSX.Element;
3
+ declare const Collector: {
4
+ ({ allowCustomValue, allowMultipleValues, addButtonProps, cancelButtonProps, keepSearchQueryOnSelect, error, className, description, enableCustomFilteringSuggestions, selected, suggestions, showNavigationHints, onConfirm, onCancel, label, errorText, disabled, fixedHeight, texts, lookupConfig, onItemAdd, onItemDeselect, onItemSelect, onMultipleItemsSelect, dropdownContent, disableButtonPanel, disableSearch, dropdownItemHeight, searchValue, renderItem, onSearchValueChange, allowPaste, showCount, valuesSeparator, }: CollectorProps): JSX.Element;
5
+ Container: import("styled-components").StyledComponent<"div", any, {}, never>;
6
+ ContentBelow: import("styled-components").StyledComponent<"div", any, {}, never>;
7
+ Description: import("styled-components").StyledComponent<"div", any, {}, never>;
8
+ ErrorText: import("styled-components").StyledComponent<"div", any, {}, never>;
9
+ CollectorInput: import("styled-components").StyledComponent<"div", any, import("@synerise/ds-input/dist/InputMultivalue/InputMultivalue.styles").InputWrapperProps & {
10
+ error?: boolean | undefined;
11
+ focus?: boolean | undefined;
12
+ disabled?: boolean | undefined;
13
+ }, never>;
14
+ RightSide: import("styled-components").StyledComponent<"div", any, {
15
+ gradientOverlap?: boolean | undefined;
16
+ focus?: boolean | undefined;
17
+ }, never>;
18
+ ContentAbove: import("styled-components").StyledComponent<"div", any, {}, never>;
19
+ MainContent: import("styled-components").StyledComponent<"div", any, {
20
+ fixedHeight?: boolean | undefined;
21
+ hasValues?: boolean | undefined;
22
+ gradientOverlap?: boolean | undefined;
23
+ focus?: boolean | undefined;
24
+ }, never>;
25
+ Input: import("styled-components").StyledComponent<"input", any, {
26
+ disabled?: boolean | undefined;
27
+ } & import("@synerise/ds-input/dist/Input.types").Props & import("antd/lib/input").InputProps & {
28
+ disabled?: boolean | undefined;
29
+ hasValues?: boolean | undefined;
30
+ transparent: boolean;
31
+ hidden: boolean;
32
+ }, never>;
33
+ Counter: import("styled-components").StyledComponent<"div", any, {}, never>;
34
+ Label: import("styled-components").StyledComponent<"label", any, {}, never>;
35
+ Values: React.FC<import("./Elements/Values/Values.types").ValuesProps>;
36
+ ButtonPanel: React.FC<import("./Elements/ButtonPanel/ButtonPanel.types").ButtonPanelProps>;
37
+ OptionsDropdown: React.FC<import("./Elements/OptionsDropdown/OptionsDropdown.types").OptionsDropdownProps>;
38
+ NavigationHint: React.FC<import("./Elements/NavigationHint/NavigationHint.types").NavigationHintProps>;
39
+ };
3
40
  export default Collector;
package/dist/Collector.js CHANGED
@@ -1,13 +1,23 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
1
7
  import React, { useEffect, useMemo, useCallback, useRef, useState } from 'react';
2
8
  import classNames from 'classnames';
9
+ import { compact } from 'lodash';
10
+ import { FormattedMessage } from 'react-intl';
3
11
  import { focusWithArrowKeys, useOnClickOutside } from '@synerise/ds-utils';
4
12
  import * as S from './Collector.styles';
5
13
  import ButtonPanel from './Elements/ButtonPanel/ButtonPanel';
6
14
  import OptionsDropdown from './Elements/OptionsDropdown/OptionsDropdown';
7
15
  import { filterValueSuggestions, isOverflown, scrollWithHorizontalArrow } from './utils';
8
16
  import Values from './Elements/Values/Values';
17
+ import NavigationHint from './Elements/NavigationHint/NavigationHint';
9
18
  var DROPDOWN_PADDING = 2 * 8;
10
19
  var COLLECTOR_CLASSNAME = 'ds-collector';
20
+ var DEFAULT_VALUES_SEPARATOR = ';';
11
21
 
12
22
  var Collector = function Collector(_ref) {
13
23
  var _classNames;
@@ -35,13 +45,18 @@ var Collector = function Collector(_ref) {
35
45
  onItemAdd = _ref.onItemAdd,
36
46
  onItemDeselect = _ref.onItemDeselect,
37
47
  onItemSelect = _ref.onItemSelect,
48
+ onMultipleItemsSelect = _ref.onMultipleItemsSelect,
38
49
  dropdownContent = _ref.dropdownContent,
39
50
  disableButtonPanel = _ref.disableButtonPanel,
40
51
  disableSearch = _ref.disableSearch,
41
52
  dropdownItemHeight = _ref.dropdownItemHeight,
42
53
  searchValue = _ref.searchValue,
43
54
  renderItem = _ref.renderItem,
44
- onSearchValueChange = _ref.onSearchValueChange;
55
+ onSearchValueChange = _ref.onSearchValueChange,
56
+ allowPaste = _ref.allowPaste,
57
+ showCount = _ref.showCount,
58
+ _ref$valuesSeparator = _ref.valuesSeparator,
59
+ valuesSeparator = _ref$valuesSeparator === void 0 ? DEFAULT_VALUES_SEPARATOR : _ref$valuesSeparator;
45
60
  var inputRef = useRef(null);
46
61
  var containerRef = useRef(null);
47
62
  var mainContentRef = useRef(null);
@@ -51,28 +66,28 @@ var Collector = function Collector(_ref) {
51
66
  setFocused = _useState[1];
52
67
 
53
68
  var _useState2 = useState(false),
54
- showGradient = _useState2[0],
55
- setShowGradient = _useState2[1];
69
+ isAddActive = _useState2[0],
70
+ setIsAddActive = _useState2[1];
56
71
 
57
- var _useState3 = useState(0),
58
- scrollLeft = _useState3[0],
59
- setScrollLeft = _useState3[1];
72
+ var _useState3 = useState(false),
73
+ showGradient = _useState3[0],
74
+ setShowGradient = _useState3[1];
60
75
 
61
- var _useState4 = useState(searchValue || ''),
62
- value = _useState4[0],
63
- setValue = _useState4[1];
76
+ var _useState4 = useState(0),
77
+ scrollLeft = _useState4[0],
78
+ setScrollLeft = _useState4[1];
64
79
 
65
- var _useState5 = useState(selected && allowMultipleValues ? selected : []),
66
- selectedValues = _useState5[0],
67
- setSelectedValues = _useState5[1];
80
+ var _useState5 = useState(searchValue || ''),
81
+ value = _useState5[0],
82
+ setValue = _useState5[1];
68
83
 
69
- useEffect(function () {
70
- setSelectedValues(selected);
71
- }, [selected]);
84
+ var _useState6 = useState(selected && allowMultipleValues ? selected : []),
85
+ selectedValues = _useState6[0],
86
+ setSelectedValues = _useState6[1];
72
87
 
73
- var _useState6 = useState(suggestions || []),
74
- filteredSuggestions = _useState6[0],
75
- setFilteredSuggestions = _useState6[1];
88
+ var _useState7 = useState(suggestions || []),
89
+ filteredSuggestions = _useState7[0],
90
+ setFilteredSuggestions = _useState7[1];
76
91
 
77
92
  var filterLookupKey = useMemo(function () {
78
93
  return (lookupConfig == null ? void 0 : lookupConfig.filter) || 'text';
@@ -80,11 +95,27 @@ var Collector = function Collector(_ref) {
80
95
  var displayLookupKey = useMemo(function () {
81
96
  return (lookupConfig == null ? void 0 : lookupConfig.display) || 'text';
82
97
  }, [lookupConfig]);
83
- var onFocusCallback = useCallback(function (e) {
84
- e.preventDefault();
98
+ var suggestionsIncludesItem = useCallback(function (item) {
99
+ return filteredSuggestions.some(function (suggestion) {
100
+ var _suggestion$filterLoo, _suggestion$filterLoo2;
101
+
102
+ return ((_suggestion$filterLoo = suggestion[filterLookupKey]) == null ? void 0 : (_suggestion$filterLoo2 = _suggestion$filterLoo.trim()) == null ? void 0 : _suggestion$filterLoo2.toLowerCase()) === item.trim().toLowerCase();
103
+ });
104
+ }, [filterLookupKey, filteredSuggestions]);
105
+ var createItem = useCallback(function (text) {
106
+ var suggestionsIncludesCurrentValue = suggestionsIncludesItem(text);
107
+
108
+ if (allowCustomValue || suggestionsIncludesCurrentValue) {
109
+ return onItemAdd && onItemAdd(text);
110
+ }
111
+
112
+ return null;
113
+ }, [allowCustomValue, onItemAdd, suggestionsIncludesItem]);
114
+ var onFocusCallback = useCallback(function (event) {
115
+ event.preventDefault();
85
116
 
86
- if (!e.target.classList.contains(COLLECTOR_CLASSNAME)) {
87
- if (!!inputRef && !!(inputRef != null && inputRef.current)) {
117
+ if (!event.target.classList.contains(COLLECTOR_CLASSNAME)) {
118
+ if (!!inputRef && !!inputRef.current) {
88
119
  inputRef.current.focus({
89
120
  preventScroll: true
90
121
  });
@@ -97,11 +128,28 @@ var Collector = function Collector(_ref) {
97
128
  var filtered = filterValueSuggestions(suggestions, selectedValues, val, filterLookupKey);
98
129
  setFilteredSuggestions(filtered);
99
130
  }, [suggestions, selectedValues, filterLookupKey]);
131
+ var canCreateItemFromValue = useCallback(function () {
132
+ if (!value) {
133
+ return false;
134
+ }
135
+
136
+ var item = createItem(value);
137
+
138
+ if (item) {
139
+ return true;
140
+ }
141
+
142
+ return false;
143
+ }, [createItem, value]);
100
144
  useEffect(function () {
101
145
  setSelectedValues(selected && allowMultipleValues ? selected : []);
102
- setFilteredSuggestions([]);
146
+
147
+ if (!enableCustomFilteringSuggestions) {
148
+ setFilteredSuggestions([]);
149
+ }
150
+
103
151
  !searchValue && allowMultipleValues && setValue(''); // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, [allowMultipleValues, allowCustomValue, selected]);
152
+ }, [allowMultipleValues, allowCustomValue, selected, enableCustomFilteringSuggestions]);
105
153
  useEffect(function () {
106
154
  if (searchValue !== undefined && searchValue !== null) {
107
155
  setValue(searchValue);
@@ -117,39 +165,49 @@ var Collector = function Collector(_ref) {
117
165
  useEffect(function () {
118
166
  if (!enableCustomFilteringSuggestions) filterSuggestions(value);
119
167
  }, [value, selectedValues, filterSuggestions, enableCustomFilteringSuggestions]);
168
+ useEffect(function () {
169
+ setIsAddActive(Boolean(selected.length) || canCreateItemFromValue());
170
+ }, [canCreateItemFromValue, selected]);
120
171
  var clear = useCallback(function () {
121
172
  setSelectedValues([]);
122
173
  setValue('');
123
174
  setFocused(false);
124
- (inputRef == null ? void 0 : inputRef.current) && inputRef.current.blur();
175
+ inputRef.current && inputRef.current.blur();
125
176
  }, []);
126
177
 
127
- var handleKeyDown = function handleKeyDown(e) {
128
- if (!enableCustomFilteringSuggestions && e.key === 'Enter') {
129
- var suggestionsIncludesCurrentValue = filteredSuggestions.some(function (suggestion) {
130
- return suggestion[filterLookupKey].trim().toLowerCase() === value.trim().toLowerCase();
131
- });
178
+ var handlePaste = function handlePaste(event) {
179
+ if (allowMultipleValues && onItemAdd) {
180
+ var pastedText = event.clipboardData.getData('text');
181
+ var pastedItems = allowMultipleValues ? pastedText.split(valuesSeparator) : [pastedText];
182
+ var newValues = compact(pastedItems.map(createItem));
132
183
 
133
- if (allowMultipleValues && (allowCustomValue || suggestionsIncludesCurrentValue)) {
134
- var newValue = onItemAdd && onItemAdd(value);
135
- newValue && onItemSelect(newValue);
136
- return;
184
+ if (newValues.length) {
185
+ onMultipleItemsSelect && onMultipleItemsSelect(newValues);
137
186
  }
187
+ }
188
+ };
138
189
 
139
- if (!allowMultipleValues) {
140
- if (allowCustomValue || suggestionsIncludesCurrentValue) {
141
- var _newValue = onItemAdd && onItemAdd(value);
190
+ var addItem = function addItem() {
191
+ if (!value.trim()) {
192
+ return;
193
+ }
142
194
 
143
- if (_newValue) {
144
- onConfirm && onConfirm([_newValue]);
145
- }
195
+ var newValue = createItem(value);
146
196
 
147
- !keepSearchQueryOnSelect && clear();
148
- }
149
- }
197
+ if (!newValue) {
198
+ return;
199
+ }
200
+
201
+ if (allowMultipleValues) {
202
+ onItemSelect(newValue);
203
+ } else {
204
+ onConfirm && onConfirm([newValue]);
205
+ !keepSearchQueryOnSelect && clear();
150
206
  }
207
+ };
151
208
 
152
- if (allowMultipleValues && e.key === 'Backspace' && !value && !!(selectedValues != null && selectedValues.length)) {
209
+ var handleKeyDown = function handleKeyDown(event) {
210
+ if (allowMultipleValues && event.key === 'Backspace' && !value && !!(selectedValues != null && selectedValues.length)) {
153
211
  var lastElement = selected.pop();
154
212
 
155
213
  if (lastElement && onItemDeselect) {
@@ -158,21 +216,34 @@ var Collector = function Collector(_ref) {
158
216
  }
159
217
  };
160
218
 
219
+ var handleKeyPress = function handleKeyPress(event) {
220
+ if (event.key === 'Enter') {
221
+ addItem();
222
+ }
223
+
224
+ if (allowPaste && event.key === valuesSeparator) {
225
+ value.trim() ? addItem() : event.preventDefault();
226
+ }
227
+ };
228
+
161
229
  var onCancelCallback = useCallback(function () {
162
230
  clear();
163
231
  onCancel && onCancel();
164
232
  }, [onCancel, clear]);
165
233
  var onConfirmCallback = useCallback(function () {
166
234
  if (allowMultipleValues) {
167
- onConfirm && onConfirm(selectedValues);
235
+ var createdItem = value && createItem(value);
236
+ var finalItems = createdItem ? [].concat(selectedValues, [createdItem]) : selectedValues;
237
+ onConfirm && onConfirm(finalItems);
168
238
  clear();
169
239
  return;
170
240
  }
171
241
 
172
- var suggestionsIncludesCurrentValue = filteredSuggestions.some(function (suggestion) {
173
- var _suggestion$filterLoo, _suggestion$filterLoo2;
242
+ var suggestionsIncludesCurrentValue = suggestionsIncludesItem(value);
243
+ filteredSuggestions.some(function (suggestion) {
244
+ var _suggestion$filterLoo3, _suggestion$filterLoo4;
174
245
 
175
- return ((_suggestion$filterLoo = suggestion[filterLookupKey]) == null ? void 0 : (_suggestion$filterLoo2 = _suggestion$filterLoo.trim()) == null ? void 0 : _suggestion$filterLoo2.toLowerCase()) === value.trim().toLowerCase();
246
+ return ((_suggestion$filterLoo3 = suggestion[filterLookupKey]) == null ? void 0 : (_suggestion$filterLoo4 = _suggestion$filterLoo3.trim()) == null ? void 0 : _suggestion$filterLoo4.toLowerCase()) === value.trim().toLowerCase();
176
247
  });
177
248
 
178
249
  if (allowCustomValue || suggestionsIncludesCurrentValue) {
@@ -180,42 +251,49 @@ var Collector = function Collector(_ref) {
180
251
  newValue && onConfirm && onConfirm([newValue]);
181
252
  clear();
182
253
  }
183
- }, [selectedValues, clear, onConfirm, value, filteredSuggestions, allowMultipleValues, allowCustomValue, onItemAdd, filterLookupKey]);
254
+ }, [allowMultipleValues, suggestionsIncludesItem, value, filteredSuggestions, allowCustomValue, createItem, selectedValues, onConfirm, clear, filterLookupKey, onItemAdd]);
184
255
  var getContainerWidth = useCallback(function () {
185
256
  var _containerRef$current;
186
257
 
187
258
  return Number((_containerRef$current = containerRef.current) == null ? void 0 : _containerRef$current.offsetWidth) - DROPDOWN_PADDING;
188
259
  }, [containerRef]);
189
- var handleDropdownClick = useCallback(function () {
260
+
261
+ var focusInput = function focusInput() {
190
262
  if (inputRef != null && inputRef.current) {
191
263
  inputRef.current.focus({
192
264
  preventScroll: true
193
265
  });
194
266
  }
195
- }, [inputRef]);
267
+ };
268
+
269
+ var handleDropdownClick = function handleDropdownClick() {
270
+ focusInput();
271
+ };
272
+
273
+ var handleChange = disableSearch ? undefined : function (event) {
274
+ onSearchValueChange && onSearchValueChange(event.target.value);
275
+ setValue(event.target.value);
276
+ if (!enableCustomFilteringSuggestions) filterSuggestions(event.target.value);
277
+ };
196
278
  useOnClickOutside(containerRef, function () {
197
279
  setFocused(false);
198
280
  });
199
281
  var showError = error || !!errorText;
200
- return /*#__PURE__*/React.createElement(S.Container, {
201
- ref: containerRef,
202
- onKeyDown: function onKeyDown(e) {
203
- focusWithArrowKeys(e, 'ds-search-item', function () {
204
- (inputRef == null ? void 0 : inputRef.current) && inputRef.current.focus({
205
- preventScroll: true
206
- });
207
- });
208
- !value && scrollWithHorizontalArrow(mainContentRef, e);
209
- }
210
- }, label && /*#__PURE__*/React.createElement(S.ContentAbove, null, /*#__PURE__*/React.createElement(S.Label, null, label)), /*#__PURE__*/React.createElement(S.CollectorInput, {
211
- className: classNames(COLLECTOR_CLASSNAME, (_classNames = {}, _classNames[className] = !!className, _classNames)),
212
- tabIndex: 0,
213
- focus: isFocused,
214
- onFocus: onFocusCallback,
215
- error: showError,
216
- disabled: disabled
217
- }, /*#__PURE__*/React.createElement(S.MainContent, {
218
- wrap: !fixedHeight,
282
+
283
+ var renderCountLabel = function renderCountLabel() {
284
+ var total = selectedValues.length;
285
+ var counterLabel = total === 1 ? /*#__PURE__*/React.createElement(FormattedMessage, {
286
+ id: "DS.COLLECTOR.ITEM",
287
+ defaultMessage: "Item"
288
+ }) : /*#__PURE__*/React.createElement(FormattedMessage, {
289
+ id: "DS.COLLECTOR.ITEMS",
290
+ defaultMessage: "Items"
291
+ });
292
+ return /*#__PURE__*/React.createElement(S.Counter, null, total, " ", counterLabel);
293
+ };
294
+
295
+ var valuesContainer = /*#__PURE__*/React.createElement(S.MainContent, {
296
+ fixedHeight: fixedHeight,
219
297
  onScroll: function onScroll(_ref2) {
220
298
  var currentTarget = _ref2.currentTarget;
221
299
 
@@ -234,40 +312,73 @@ var Collector = function Collector(_ref) {
234
312
  disabled: !!disabled,
235
313
  displayLookupKey: displayLookupKey
236
314
  }), /*#__PURE__*/React.createElement(S.Input, {
315
+ onPaste: handlePaste,
316
+ onKeyPress: handleKeyPress,
237
317
  onKeyDown: handleKeyDown,
238
318
  ref: inputRef,
239
319
  value: value,
240
- onChange: !disableSearch ? function (e) {
241
- onSearchValueChange && onSearchValueChange(e.target.value);
242
- setValue(e.target.value);
243
- if (!enableCustomFilteringSuggestions) filterSuggestions(e.target.value);
244
- } : undefined,
320
+ onChange: handleChange,
245
321
  disabled: disabled,
246
322
  transparent: !!disableSearch,
247
323
  hidden: !!disableSearch && !!selectedValues.length,
248
324
  placeholder: selectedValues && selectedValues.length ? undefined : texts == null ? void 0 : texts.placeholder,
249
325
  hasValues: !!(selectedValues != null && selectedValues.length)
250
- })), !disableButtonPanel && /*#__PURE__*/React.createElement(S.RightSide, {
326
+ }));
327
+ var innerContent = fixedHeight ? valuesContainer : /*#__PURE__*/React.createElement(S.Scrollbar, {
328
+ absolute: true,
329
+ maxHeight: 160
330
+ }, valuesContainer);
331
+ return /*#__PURE__*/React.createElement(S.Container, {
332
+ ref: containerRef,
333
+ onKeyDown: function onKeyDown(event) {
334
+ focusWithArrowKeys(event, 'ds-search-item', function () {
335
+ (inputRef == null ? void 0 : inputRef.current) && inputRef.current.focus({
336
+ preventScroll: true
337
+ });
338
+ });
339
+ !value && scrollWithHorizontalArrow(mainContentRef, event);
340
+ }
341
+ }, (label || showCount) && /*#__PURE__*/React.createElement(S.ContentAbove, null, label && /*#__PURE__*/React.createElement(S.Label, null, label), showCount && renderCountLabel()), /*#__PURE__*/React.createElement(S.CollectorInput, {
342
+ className: classNames(COLLECTOR_CLASSNAME, (_classNames = {}, _classNames[className] = !!className, _classNames)),
343
+ tabIndex: 0,
344
+ focus: isFocused,
345
+ onFocus: onFocusCallback,
346
+ onClick: onFocusCallback,
347
+ error: showError,
348
+ disabled: disabled
349
+ }, innerContent, !disableButtonPanel && /*#__PURE__*/React.createElement(S.RightSide, {
251
350
  gradientOverlap: showGradient && !value,
252
- focus: isFocused
351
+ focus: isFocused,
352
+ onClick: function onClick(event) {
353
+ return event.stopPropagation();
354
+ }
253
355
  }, /*#__PURE__*/React.createElement(ButtonPanel, {
254
356
  onCancel: onCancelCallback,
255
357
  onConfirm: onConfirmCallback,
256
358
  disabled: !!disabled,
257
359
  showCancel: !!value || !!(selectedValues != null && selectedValues.length),
258
360
  texts: texts,
259
- addButtonProps: addButtonProps,
361
+ addButtonProps: _objectSpread({}, addButtonProps, {
362
+ disabled: !isAddActive
363
+ }),
260
364
  cancelButtonProps: cancelButtonProps
261
365
  }))), /*#__PURE__*/React.createElement(OptionsDropdown, {
262
366
  options: filteredSuggestions,
263
- onItemAdd: onItemAdd,
367
+ onItemAdd: addItem,
264
368
  lookupKey: displayLookupKey,
265
369
  dropdownItemHeight: dropdownItemHeight,
266
370
  value: value,
267
371
  visible: isFocused && !disabled && (filteredSuggestions.length > 0 || !!value && allowMultipleValues && allowCustomValue),
268
372
  onSelect: function onSelect(item) {
269
373
  onItemSelect && onItemSelect(item);
270
- !keepSearchQueryOnSelect && item[filterLookupKey] && setValue(item[filterLookupKey]);
374
+
375
+ if (!keepSearchQueryOnSelect && item[filterLookupKey]) {
376
+ setValue(item[filterLookupKey]);
377
+ } else {
378
+ clear();
379
+ }
380
+
381
+ focusInput();
271
382
  },
272
383
  onClick: handleDropdownClick,
273
384
  renderItem: renderItem,
@@ -279,4 +390,19 @@ var Collector = function Collector(_ref) {
279
390
  }), (showError || description) && /*#__PURE__*/React.createElement(S.ContentBelow, null, showError && /*#__PURE__*/React.createElement(S.ErrorText, null, errorText), description && /*#__PURE__*/React.createElement(S.Description, null, description)));
280
391
  };
281
392
 
393
+ Collector.Container = S.Container;
394
+ Collector.ContentBelow = S.ContentBelow;
395
+ Collector.Description = S.Description;
396
+ Collector.ErrorText = S.ErrorText;
397
+ Collector.CollectorInput = S.CollectorInput;
398
+ Collector.RightSide = S.RightSide;
399
+ Collector.ContentAbove = S.ContentAbove;
400
+ Collector.MainContent = S.MainContent;
401
+ Collector.Input = S.Input;
402
+ Collector.Counter = S.Counter;
403
+ Collector.Label = S.Label;
404
+ Collector.Values = Values;
405
+ Collector.ButtonPanel = ButtonPanel;
406
+ Collector.OptionsDropdown = OptionsDropdown;
407
+ Collector.NavigationHint = NavigationHint;
282
408
  export default Collector;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { ContentAbove, Label, ContentBelow, Description, ErrorText, ValueText } from '@synerise/ds-input/dist/InputMultivalue/InputMultivalue.styles';
2
3
  import { Props as DSInputProps } from '@synerise/ds-input/dist/Input.types';
3
4
  import { InputProps } from 'antd/lib/input';
@@ -9,8 +10,11 @@ export declare const CollectorInput: import("styled-components").StyledComponent
9
10
  focus?: boolean | undefined;
10
11
  disabled?: boolean | undefined;
11
12
  }, never>;
13
+ export declare const Scrollbar: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("@synerise/ds-scrollbar").ScrollbarAdditionalProps & {
14
+ children: import("react").ReactNode;
15
+ } & import("react").RefAttributes<HTMLElement>>, any, {}, never>;
12
16
  export declare const MainContent: import("styled-components").StyledComponent<"div", any, {
13
- wrap: boolean;
17
+ fixedHeight?: boolean | undefined;
14
18
  hasValues?: boolean | undefined;
15
19
  gradientOverlap?: boolean | undefined;
16
20
  focus?: boolean | undefined;
@@ -43,3 +47,4 @@ export declare const DropdownAddButton: import("styled-components").StyledCompon
43
47
  export declare const DropdownTop: import("styled-components").StyledComponent<"div", any, {}, never>;
44
48
  export declare const DividerContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
45
49
  export declare const NavigationWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
50
+ export declare const Counter: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -1,4 +1,5 @@
1
1
  import { InputWrapper, BorderLessInput, ContentAbove, Label, ContentBelow, Description, ErrorText, ValueText } from '@synerise/ds-input/dist/InputMultivalue/InputMultivalue.styles';
2
+ import DSScrollbar from '@synerise/ds-scrollbar';
2
3
  import styled, { css } from 'styled-components';
3
4
  import Value from '@synerise/ds-input/dist/InputMultivalue/Elements/Value';
4
5
  import Button from '@synerise/ds-button';
@@ -14,14 +15,24 @@ var gradientOverlayStyles = function gradientOverlayStyles() {
14
15
  export var CollectorInput = styled(InputWrapper).withConfig({
15
16
  displayName: "Collectorstyles__CollectorInput",
16
17
  componentId: "sc-14aly5p-1"
17
- })(["width:100%;min-height:48px;padding:8px 4px;border-radius:5px;"]);
18
+ })(["width:100%;min-height:48px;padding:8px 4px;border-radius:5px;flex-wrap:nowrap;justify-content:space-between;"]);
19
+ export var Scrollbar = styled(DSScrollbar).withConfig({
20
+ displayName: "Collectorstyles__Scrollbar",
21
+ componentId: "sc-14aly5p-2"
22
+ })([""]);
18
23
  export var MainContent = styled.div.withConfig({
19
24
  displayName: "Collectorstyles__MainContent",
20
- componentId: "sc-14aly5p-2"
21
- })(["display:flex;position:relative;padding:", ";flex:1;align-items:flex-start;flex-wrap:", ";overflow-x:scroll;overflow-y:hidden;padding-right:4px;::-webkit-scrollbar{display:none;}-ms-overflow-style:none;scrollbar-width:none;.ds-input-value-wrapper{min-width:fit-content;margin:4px 0 4px 8px;right:0;background:", ";}&::before{content:'';opacity:", ";position:fixed;", " background-image:", ";}"], function (props) {
25
+ componentId: "sc-14aly5p-3"
26
+ })(["display:flex;position:relative;padding:", ";flex:1;align-items:flex-start;flex-wrap:", ";overflow-x:", ";overflow-y:", ";padding-right:", ";::-webkit-scrollbar{display:none;}-ms-overflow-style:none;scrollbar-width:none;.ds-input-value-wrapper{min-width:fit-content;margin:4px 0 4px 8px;right:0;background:", ";}&::before{content:'';opacity:", ";position:fixed;", " background-image:", ";}"], function (props) {
22
27
  return props.hasValues ? '0' : '2px 0';
23
28
  }, function (props) {
24
- return props.wrap ? 'wrap' : 'nowrap';
29
+ return props.fixedHeight ? 'nowrap' : 'wrap';
30
+ }, function (props) {
31
+ return props.fixedHeight ? 'scroll' : 'hidden';
32
+ }, function (props) {
33
+ return props.fixedHeight ? 'hidden' : 'scroll';
34
+ }, function (props) {
35
+ return props.fixedHeight ? '4px' : '12px';
25
36
  }, function (props) {
26
37
  return props.theme.palette['grey-200'];
27
38
  }, function (props) {
@@ -31,7 +42,7 @@ export var MainContent = styled.div.withConfig({
31
42
  });
32
43
  export var RightSide = styled.div.withConfig({
33
44
  displayName: "Collectorstyles__RightSide",
34
- componentId: "sc-14aly5p-3"
45
+ componentId: "sc-14aly5p-4"
35
46
  })(["display:flex;margin:0 4px;position:relative;.ds-button:not(:last-child){margin-right:8px;}&::before{content:", ";", " background-image:", ";position:absolute;left:-102px;}"], function (props) {
36
47
  return props.gradientOverlap ? "''" : 'none';
37
48
  }, gradientOverlayStyles(), function (props) {
@@ -39,7 +50,7 @@ export var RightSide = styled.div.withConfig({
39
50
  });
40
51
  export var Input = styled(BorderLessInput).withConfig({
41
52
  displayName: "Collectorstyles__Input",
42
- componentId: "sc-14aly5p-4"
53
+ componentId: "sc-14aly5p-5"
43
54
  })(["margin:", ";padding:1px 0;min-width:unset;line-height:18px;", " ", ""], function (props) {
44
55
  return props.hasValues ? '6px 0 6px 12px' : '4px 0 4px 12px';
45
56
  }, function (props) {
@@ -56,33 +67,33 @@ export { ErrorText };
56
67
  export { ValueText };
57
68
  export var DropdownWrapper = styled.div.withConfig({
58
69
  displayName: "Collectorstyles__DropdownWrapper",
59
- componentId: "sc-14aly5p-5"
70
+ componentId: "sc-14aly5p-6"
60
71
  })(["position:relative;user-select:none;"]);
61
72
  export var CustomContentWrapper = styled.div.withConfig({
62
73
  displayName: "Collectorstyles__CustomContentWrapper",
63
- componentId: "sc-14aly5p-6"
74
+ componentId: "sc-14aly5p-7"
64
75
  })(["position:absolute;z-index:99;"]);
65
76
  export var DropdownContent = styled.div.withConfig({
66
77
  displayName: "Collectorstyles__DropdownContent",
67
- componentId: "sc-14aly5p-7"
78
+ componentId: "sc-14aly5p-8"
68
79
  })(["background:", ";border-radius:3px;padding:8px 0 8px 8px;position:absolute;width:100%;top:4px;left:0;box-shadow:0 16px 32px 0 rgba(35,41,54,0.12);z-index:99;"], function (props) {
69
80
  return props.theme.palette.white;
70
81
  });
71
82
  export var DropdownAddButton = styled(Button).withConfig({
72
83
  displayName: "Collectorstyles__DropdownAddButton",
73
- componentId: "sc-14aly5p-8"
84
+ componentId: "sc-14aly5p-9"
74
85
  })(["white-space:nowrap;overflow:hidden;width:100%;text-overflow:ellipsis;&&{display:flex;justify-content:flex-start;align-items:center;font-weight:400;text-align:left;}.ds-icon{margin-left:16px;margin-right:8px;}strong{font-weight:500;margin:0 0 0 3px;display:block;overflow:hidden;text-overflow:ellipsis;}"]);
75
86
  export var DropdownTop = styled.div.withConfig({
76
87
  displayName: "Collectorstyles__DropdownTop",
77
- componentId: "sc-14aly5p-9"
88
+ componentId: "sc-14aly5p-10"
78
89
  })(["padding-right:8px;"]);
79
90
  export var DividerContainer = styled.div.withConfig({
80
91
  displayName: "Collectorstyles__DividerContainer",
81
- componentId: "sc-14aly5p-10"
92
+ componentId: "sc-14aly5p-11"
82
93
  })(["padding:8px 12px;"]);
83
94
  export var NavigationWrapper = styled.div.withConfig({
84
95
  displayName: "Collectorstyles__NavigationWrapper",
85
- componentId: "sc-14aly5p-11"
96
+ componentId: "sc-14aly5p-12"
86
97
  })(["margin-top:8px;border-top:1px solid ", ";background:", ";padding:12px 16px;margin-left:-8px;margin-bottom:-8px;color:", ";display:flex;align-items:center;.ds-icon > svg{fill:", ";}span{margin-left:2px;margin-right:8px;font-weight:500;}"], function (props) {
87
98
  return props.theme.palette['grey-100'];
88
99
  }, function (props) {
@@ -91,4 +102,8 @@ export var NavigationWrapper = styled.div.withConfig({
91
102
  return props.theme.palette['grey-400'];
92
103
  }, function (props) {
93
104
  return props.theme.palette['grey-400'];
94
- });
105
+ });
106
+ export var Counter = styled.div.withConfig({
107
+ displayName: "Collectorstyles__Counter",
108
+ componentId: "sc-14aly5p-13"
109
+ })(["display:flex;height:26px;align-items:center;column-gap:4px;"]);
@@ -24,6 +24,7 @@ export type CollectorProps = {
24
24
  onItemDeselect?: (item: CollectorValue) => void;
25
25
  onItemAdd?: (itemName: React.ReactText) => CollectorValue;
26
26
  onItemSelect: (item: CollectorValue) => void;
27
+ onMultipleItemsSelect?: (items: CollectorValue[]) => void;
27
28
  renderItem?: (value: CollectorValue) => JSX.Element;
28
29
  showNavigationHints?: boolean;
29
30
  searchValue?: string;
@@ -33,7 +34,11 @@ export type CollectorProps = {
33
34
  dropdownItemHeight?: 'large';
34
35
  enableCustomFilteringSuggestions?: boolean;
35
36
  scrollbarProps?: ScrollbarAdditionalProps;
37
+ allowPaste?: boolean;
38
+ showCount?: boolean;
39
+ valuesSeparator?: CollectorValuesSeparator;
36
40
  };
41
+ export type CollectorValuesSeparator = ';' | ',' | '|';
37
42
  export type CollectorTexts = {
38
43
  add: string | React.ReactNode;
39
44
  cancel: string | React.ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-collector",
3
- "version": "0.6.24",
3
+ "version": "0.6.26",
4
4
  "description": "Collector UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -21,6 +21,7 @@
21
21
  "build:js": "babel --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
22
22
  "build:watch": "npm run build:js -- --watch",
23
23
  "defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
24
+ "pack:ci": "npm pack --pack-destination ../../portal/storybook-static/static",
24
25
  "prepublish": "npm run build",
25
26
  "test": "jest",
26
27
  "test:watch": "npm run test -- --watchAll",
@@ -32,15 +33,16 @@
32
33
  ],
33
34
  "types": "dist/index.d.ts",
34
35
  "dependencies": {
35
- "@synerise/ds-button": "^0.18.3",
36
- "@synerise/ds-divider": "^0.6.0",
37
- "@synerise/ds-icon": "^0.58.3",
38
- "@synerise/ds-input": "^0.19.3",
39
- "@synerise/ds-menu": "^0.18.0",
40
- "@synerise/ds-scrollbar": "^0.6.8",
41
- "@synerise/ds-search": "^0.8.67",
42
- "@synerise/ds-utils": "^0.24.17",
43
- "classnames": "2.3.2"
36
+ "@synerise/ds-button": "^0.18.4",
37
+ "@synerise/ds-divider": "^0.6.1",
38
+ "@synerise/ds-icon": "^0.58.4",
39
+ "@synerise/ds-input": "^0.19.4",
40
+ "@synerise/ds-menu": "^0.18.1",
41
+ "@synerise/ds-scrollbar": "^0.6.9",
42
+ "@synerise/ds-search": "^0.8.68",
43
+ "@synerise/ds-utils": "^0.24.18",
44
+ "classnames": "2.3.2",
45
+ "lodash": "^4.17.19"
44
46
  },
45
47
  "peerDependencies": {
46
48
  "@synerise/ds-core": "*",
@@ -50,7 +52,7 @@
50
52
  },
51
53
  "devDependencies": {
52
54
  "@testing-library/jest-dom": "5.1.1",
53
- "@testing-library/react": "10.0.1"
55
+ "@testing-library/react": "^11"
54
56
  },
55
- "gitHead": "d944339a738211d8f74b27360481aafd7ef51ddd"
57
+ "gitHead": "02f0a1dad6df5acf89b3d3defa6993716ba992fb"
56
58
  }