@commercetools-uikit/select-input 15.14.2 → 15.15.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/README.md CHANGED
@@ -72,7 +72,7 @@ export default Example;
72
72
  | `isAutofocussed` | `boolean` | | | Focus the control when it is mounted |
73
73
  | `backspaceRemovesValue` | `ReactSelectProps['backspaceRemovesValue']` | | | Remove the currently focused option when the user presses backspace&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
74
74
  | `components` | `ReactSelectProps['components']` | | | Map of components to overwrite the default ones, see what components you can override&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
75
- | `controlShouldRenderValue` | `ReactSelectProps['controlShouldRenderValue']` | | | Control whether the selected values should be rendered in the control&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
75
+ | `controlShouldRenderValue` | `ReactSelectProps['controlShouldRenderValue']` | | `true` | Control whether the selected values should be rendered in the control&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
76
76
  | `filterOption` | `ReactSelectProps['filterOption']` | | | Custom method to filter whether an option should be displayed in the menu&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
77
77
  | `id` | `ReactSelectProps['inputId']` | | | Used as HTML id property. An id is generated automatically when not provided.&#xA;This forwarded as react-select's "inputId"&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
78
78
  | `inputValue` | `ReactSelectProps['inputValue']` | | | The value of the search input&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
@@ -84,7 +84,7 @@ export default Example;
84
84
  | `isSearchable` | `ReactSelectProps['isSearchable']` | | | Whether to enable search functionality&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
85
85
  | `maxMenuHeight` | `ReactSelectProps['maxMenuHeight']` | | `220` | Maximum height of the menu before scrolling&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
86
86
  | `menuPortalTarget` | `ReactSelectProps['menuPortalTarget']` | | | Dom element to portal the select menu to&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
87
- | `menuPortalZIndex` | `number` | | `1` | z-index value for the menu portal |
87
+ | `menuPortalZIndex` | `number` | | `1` | z-index value for the menu portal&#xA;<br>&#xA;Use in conjunction with `menuPortalTarget` |
88
88
  | `menuShouldBlockScroll` | `ReactSelectProps['menuShouldBlockScroll']` | | | whether the menu should block scroll while open&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
89
89
  | `closeMenuOnSelect` | `ReactSelectProps['closeMenuOnSelect']` | | | Whether the menu should close after a value is selected. Defaults to `true`.&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
90
90
  | `name` | `ReactSelectProps['name']` | | | Name of the HTML Input (optional - without this, no input will be rendered)&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
@@ -93,7 +93,7 @@ export default Example;
93
93
  | `onChange` | `Function`<br/>[See signature.](#signature-onChange) | | | Called with a fake event when value changes. The event's target.name will be the name supplied in props. The event's target.value will hold the value.&#xA;<br/>&#xA;The value will be the selected option, or an array of options in case isMulti is true. |
94
94
  | `onFocus` | `ReactSelectProps['onFocus']` | | | Handle focus events on the control&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
95
95
  | `onInputChange` | `ReactSelectProps['onInputChange']` | | | Handle change events on the input&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
96
- | `options` | `union`<br/>Possible values:<br/>`TOption[] , TOptionObject[]` | | | Array of options that populate the select menu |
96
+ | `options` | `union`<br/>Possible values:<br/>`TOption[] , TOptionObject[]` | | `[]` | Array of options that populate the select menu |
97
97
  | `showOptionGroupDivider` | `boolean` | | | |
98
98
  | `placeholder` | `ReactSelectProps['placeholder']` | | | Placeholder text for the select value&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
99
99
  | `tabIndex` | `ReactSelectProps['tabIndex']` | | | Sets the tabIndex attribute on the input&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
6
6
  var _pt = require('prop-types');
7
+ var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
7
8
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
8
9
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
9
10
  var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
@@ -17,7 +18,6 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/obje
17
18
  var reactIntl = require('react-intl');
18
19
  var isEmpty = require('lodash/isEmpty');
19
20
  var has = require('lodash/has');
20
- var flatMap = require('lodash/flatMap');
21
21
  var Select = require('react-select');
22
22
  var Constraints = require('@commercetools-uikit/constraints');
23
23
  var selectUtils = require('@commercetools-uikit/select-utils');
@@ -28,6 +28,7 @@ var jsxRuntime = require('@emotion/react/jsx-runtime');
28
28
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
29
29
 
30
30
  var _pt__default = /*#__PURE__*/_interopDefault(_pt);
31
+ var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
31
32
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
32
33
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
33
34
  var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
@@ -40,13 +41,12 @@ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$def
40
41
  var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
41
42
  var isEmpty__default = /*#__PURE__*/_interopDefault(isEmpty);
42
43
  var has__default = /*#__PURE__*/_interopDefault(has);
43
- var flatMap__default = /*#__PURE__*/_interopDefault(flatMap);
44
44
  var Select__default = /*#__PURE__*/_interopDefault(Select);
45
45
  var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
46
46
 
47
47
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
48
48
 
49
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context4, _context5; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source), !0)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
49
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
50
50
  var customizedComponents = {
51
51
  DropdownIndicator: selectUtils.DropdownIndicator,
52
52
  ClearIndicator: selectUtils.ClearIndicator,
@@ -54,17 +54,28 @@ var customizedComponents = {
54
54
  };
55
55
  var defaultProps = {
56
56
  maxMenuHeight: 220,
57
- menuPortalZIndex: 1
57
+ menuPortalZIndex: 1,
58
+ controlShouldRenderValue: true,
59
+ options: []
60
+ };
61
+
62
+ var isOptionObject = function isOptionObject(option) {
63
+ return option.options !== undefined;
58
64
  };
59
65
 
60
66
  var SelectInput = function SelectInput(props) {
61
- var _context, _context2;
67
+ var _context, _context2, _context3;
62
68
 
63
69
  var intl = reactIntl.useIntl();
64
70
 
65
71
  var _useTheme = designSystem.useTheme(),
66
72
  isNewTheme = _useTheme.isNewTheme;
67
73
 
74
+ selectUtils.warnIfMenuPortalPropsAreMissing({
75
+ menuPortalZIndex: props.menuPortalZIndex,
76
+ menuPortalTarget: props.menuPortalTarget,
77
+ componentName: 'SelectInput'
78
+ });
68
79
  var placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
69
80
  // const colourOptions = [{ value: 'green', label: 'Green' }];
70
81
  // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
@@ -74,16 +85,21 @@ var SelectInput = function SelectInput(props) {
74
85
  // ];
75
86
  // So we "ungroup" the options by merging them all into one list first.
76
87
 
77
- var optionsWithoutGroups = flatMap__default["default"](props.options, function (option) {
78
- return has__default["default"](option, 'value') ? option : option.options;
88
+ var optionsWithoutGroups = _flatMapInstanceProperty__default["default"](_context = props.options).call(_context, function (option) {
89
+ if (isOptionObject(option)) {
90
+ return option.options;
91
+ }
92
+
93
+ return option;
79
94
  });
80
- var selectedOptions = props.isMulti ? _filterInstanceProperty__default["default"](_context = _mapInstanceProperty__default["default"](_context2 = props.value || [] // Pass the options in the order selected by the use, so that the
95
+
96
+ var selectedOptions = props.isMulti ? _filterInstanceProperty__default["default"](_context2 = _mapInstanceProperty__default["default"](_context3 = props.value || [] // Pass the options in the order selected by the use, so that the
81
97
  // sorting is not lost
82
- ).call(_context2, function (value) {
98
+ ).call(_context3, function (value) {
83
99
  return _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
84
100
  return option.value === value;
85
101
  });
86
- })).call(_context, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
102
+ })).call(_context2, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
87
103
  return has__default["default"](option, 'value') && option.value === props.value;
88
104
  }) || null;
89
105
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
@@ -114,6 +130,7 @@ var SelectInput = function SelectInput(props) {
114
130
  iconLeft: props.iconLeft,
115
131
  isMulti: props.isMulti,
116
132
  hasValue: !isEmpty__default["default"](selectedOptions),
133
+ controlShouldRenderValue: props.controlShouldRenderValue,
117
134
  isNewTheme: isNewTheme
118
135
  }),
119
136
  filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
@@ -166,9 +183,9 @@ var SelectInput = function SelectInput(props) {
166
183
 
167
184
  if (props.isMulti) {
168
185
  if (nextSelectedOptions) {
169
- var _context3;
186
+ var _context4;
170
187
 
171
- value = _mapInstanceProperty__default["default"](_context3 = nextSelectedOptions).call(_context3, function (option) {
188
+ value = _mapInstanceProperty__default["default"](_context4 = nextSelectedOptions).call(_context4, function (option) {
172
189
  return option.value;
173
190
  });
174
191
  } else {
@@ -219,7 +236,7 @@ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
219
236
  value: _pt__default["default"].string.isRequired,
220
237
  label: _pt__default["default"].node
221
238
  })).isRequired
222
- }))]),
239
+ }))]).isRequired,
223
240
  showOptionGroupDivider: _pt__default["default"].bool
224
241
  } : {};
225
242
  SelectInput.displayName = 'SelectInput';
@@ -265,7 +282,7 @@ SelectInput.ValueContainer = Select.components.ValueContainer;
265
282
  var SelectInput$1 = SelectInput;
266
283
 
267
284
  // NOTE: This string will be replaced on build time with the package version.
268
- var version = "15.14.2";
285
+ var version = "15.15.0";
269
286
 
270
287
  exports["default"] = SelectInput$1;
271
288
  exports.version = version;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
6
6
  require('prop-types');
7
+ var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
7
8
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
8
9
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
9
10
  var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
@@ -17,7 +18,6 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/obje
17
18
  var reactIntl = require('react-intl');
18
19
  var isEmpty = require('lodash/isEmpty');
19
20
  var has = require('lodash/has');
20
- var flatMap = require('lodash/flatMap');
21
21
  var Select = require('react-select');
22
22
  var Constraints = require('@commercetools-uikit/constraints');
23
23
  var selectUtils = require('@commercetools-uikit/select-utils');
@@ -27,6 +27,7 @@ var jsxRuntime = require('@emotion/react/jsx-runtime');
27
27
 
28
28
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
29
29
 
30
+ var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
30
31
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
31
32
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
32
33
  var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
@@ -39,13 +40,12 @@ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$def
39
40
  var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
40
41
  var isEmpty__default = /*#__PURE__*/_interopDefault(isEmpty);
41
42
  var has__default = /*#__PURE__*/_interopDefault(has);
42
- var flatMap__default = /*#__PURE__*/_interopDefault(flatMap);
43
43
  var Select__default = /*#__PURE__*/_interopDefault(Select);
44
44
  var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
45
45
 
46
46
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
47
47
 
48
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context4, _context5; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source), !0)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
48
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
49
49
  var customizedComponents = {
50
50
  DropdownIndicator: selectUtils.DropdownIndicator,
51
51
  ClearIndicator: selectUtils.ClearIndicator,
@@ -53,17 +53,28 @@ var customizedComponents = {
53
53
  };
54
54
  var defaultProps = {
55
55
  maxMenuHeight: 220,
56
- menuPortalZIndex: 1
56
+ menuPortalZIndex: 1,
57
+ controlShouldRenderValue: true,
58
+ options: []
59
+ };
60
+
61
+ var isOptionObject = function isOptionObject(option) {
62
+ return option.options !== undefined;
57
63
  };
58
64
 
59
65
  var SelectInput = function SelectInput(props) {
60
- var _context, _context2;
66
+ var _context, _context2, _context3;
61
67
 
62
68
  var intl = reactIntl.useIntl();
63
69
 
64
70
  var _useTheme = designSystem.useTheme(),
65
71
  isNewTheme = _useTheme.isNewTheme;
66
72
 
73
+ selectUtils.warnIfMenuPortalPropsAreMissing({
74
+ menuPortalZIndex: props.menuPortalZIndex,
75
+ menuPortalTarget: props.menuPortalTarget,
76
+ componentName: 'SelectInput'
77
+ });
67
78
  var placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
68
79
  // const colourOptions = [{ value: 'green', label: 'Green' }];
69
80
  // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
@@ -73,16 +84,21 @@ var SelectInput = function SelectInput(props) {
73
84
  // ];
74
85
  // So we "ungroup" the options by merging them all into one list first.
75
86
 
76
- var optionsWithoutGroups = flatMap__default["default"](props.options, function (option) {
77
- return has__default["default"](option, 'value') ? option : option.options;
87
+ var optionsWithoutGroups = _flatMapInstanceProperty__default["default"](_context = props.options).call(_context, function (option) {
88
+ if (isOptionObject(option)) {
89
+ return option.options;
90
+ }
91
+
92
+ return option;
78
93
  });
79
- var selectedOptions = props.isMulti ? _filterInstanceProperty__default["default"](_context = _mapInstanceProperty__default["default"](_context2 = props.value || [] // Pass the options in the order selected by the use, so that the
94
+
95
+ var selectedOptions = props.isMulti ? _filterInstanceProperty__default["default"](_context2 = _mapInstanceProperty__default["default"](_context3 = props.value || [] // Pass the options in the order selected by the use, so that the
80
96
  // sorting is not lost
81
- ).call(_context2, function (value) {
97
+ ).call(_context3, function (value) {
82
98
  return _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
83
99
  return option.value === value;
84
100
  });
85
- })).call(_context, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
101
+ })).call(_context2, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
86
102
  return has__default["default"](option, 'value') && option.value === props.value;
87
103
  }) || null;
88
104
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
@@ -113,6 +129,7 @@ var SelectInput = function SelectInput(props) {
113
129
  iconLeft: props.iconLeft,
114
130
  isMulti: props.isMulti,
115
131
  hasValue: !isEmpty__default["default"](selectedOptions),
132
+ controlShouldRenderValue: props.controlShouldRenderValue,
116
133
  isNewTheme: isNewTheme
117
134
  }),
118
135
  filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
@@ -165,9 +182,9 @@ var SelectInput = function SelectInput(props) {
165
182
 
166
183
  if (props.isMulti) {
167
184
  if (nextSelectedOptions) {
168
- var _context3;
185
+ var _context4;
169
186
 
170
- value = _mapInstanceProperty__default["default"](_context3 = nextSelectedOptions).call(_context3, function (option) {
187
+ value = _mapInstanceProperty__default["default"](_context4 = nextSelectedOptions).call(_context4, function (option) {
171
188
  return option.value;
172
189
  });
173
190
  } else {
@@ -244,7 +261,7 @@ SelectInput.ValueContainer = Select.components.ValueContainer;
244
261
  var SelectInput$1 = SelectInput;
245
262
 
246
263
  // NOTE: This string will be replaced on build time with the package version.
247
- var version = "15.14.2";
264
+ var version = "15.15.0";
248
265
 
249
266
  exports["default"] = SelectInput$1;
250
267
  exports.version = version;
@@ -1,5 +1,6 @@
1
1
  import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
2
2
  import _pt from 'prop-types';
3
+ import _flatMapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/flat-map';
3
4
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
4
5
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
5
6
  import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
@@ -13,17 +14,16 @@ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object
13
14
  import { useIntl } from 'react-intl';
14
15
  import isEmpty from 'lodash/isEmpty';
15
16
  import has from 'lodash/has';
16
- import flatMap from 'lodash/flatMap';
17
17
  import Select, { components } from 'react-select';
18
18
  import Constraints from '@commercetools-uikit/constraints';
19
- import { messages, customComponentsWithIcons, createSelectStyles, DropdownIndicator, ClearIndicator, TagRemove } from '@commercetools-uikit/select-utils';
19
+ import { warnIfMenuPortalPropsAreMissing, messages, customComponentsWithIcons, createSelectStyles, DropdownIndicator, ClearIndicator, TagRemove } from '@commercetools-uikit/select-utils';
20
20
  import { filterDataAttributes } from '@commercetools-uikit/utils';
21
21
  import { useTheme } from '@commercetools-uikit/design-system';
22
22
  import { jsx } from '@emotion/react/jsx-runtime';
23
23
 
24
24
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
25
 
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context4, _context5; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context4 = ownKeys(Object(source), !0)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
26
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context5, _context6; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
27
27
  var customizedComponents = {
28
28
  DropdownIndicator: DropdownIndicator,
29
29
  ClearIndicator: ClearIndicator,
@@ -31,17 +31,28 @@ var customizedComponents = {
31
31
  };
32
32
  var defaultProps = {
33
33
  maxMenuHeight: 220,
34
- menuPortalZIndex: 1
34
+ menuPortalZIndex: 1,
35
+ controlShouldRenderValue: true,
36
+ options: []
37
+ };
38
+
39
+ var isOptionObject = function isOptionObject(option) {
40
+ return option.options !== undefined;
35
41
  };
36
42
 
37
43
  var SelectInput = function SelectInput(props) {
38
- var _context, _context2;
44
+ var _context, _context2, _context3;
39
45
 
40
46
  var intl = useIntl();
41
47
 
42
48
  var _useTheme = useTheme(),
43
49
  isNewTheme = _useTheme.isNewTheme;
44
50
 
51
+ warnIfMenuPortalPropsAreMissing({
52
+ menuPortalZIndex: props.menuPortalZIndex,
53
+ menuPortalTarget: props.menuPortalTarget,
54
+ componentName: 'SelectInput'
55
+ });
45
56
  var placeholder = props.placeholder || intl.formatMessage(messages.placeholder); // Options can be grouped as
46
57
  // const colourOptions = [{ value: 'green', label: 'Green' }];
47
58
  // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
@@ -51,16 +62,21 @@ var SelectInput = function SelectInput(props) {
51
62
  // ];
52
63
  // So we "ungroup" the options by merging them all into one list first.
53
64
 
54
- var optionsWithoutGroups = flatMap(props.options, function (option) {
55
- return has(option, 'value') ? option : option.options;
65
+ var optionsWithoutGroups = _flatMapInstanceProperty(_context = props.options).call(_context, function (option) {
66
+ if (isOptionObject(option)) {
67
+ return option.options;
68
+ }
69
+
70
+ return option;
56
71
  });
57
- var selectedOptions = props.isMulti ? _filterInstanceProperty(_context = _mapInstanceProperty(_context2 = props.value || [] // Pass the options in the order selected by the use, so that the
72
+
73
+ var selectedOptions = props.isMulti ? _filterInstanceProperty(_context2 = _mapInstanceProperty(_context3 = props.value || [] // Pass the options in the order selected by the use, so that the
58
74
  // sorting is not lost
59
- ).call(_context2, function (value) {
75
+ ).call(_context3, function (value) {
60
76
  return _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
61
77
  return option.value === value;
62
78
  });
63
- })).call(_context, Boolean) : _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
79
+ })).call(_context2, Boolean) : _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
64
80
  return has(option, 'value') && option.value === props.value;
65
81
  }) || null;
66
82
  return jsx(Constraints.Horizontal, {
@@ -91,6 +107,7 @@ var SelectInput = function SelectInput(props) {
91
107
  iconLeft: props.iconLeft,
92
108
  isMulti: props.isMulti,
93
109
  hasValue: !isEmpty(selectedOptions),
110
+ controlShouldRenderValue: props.controlShouldRenderValue,
94
111
  isNewTheme: isNewTheme
95
112
  }),
96
113
  filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
@@ -143,9 +160,9 @@ var SelectInput = function SelectInput(props) {
143
160
 
144
161
  if (props.isMulti) {
145
162
  if (nextSelectedOptions) {
146
- var _context3;
163
+ var _context4;
147
164
 
148
- value = _mapInstanceProperty(_context3 = nextSelectedOptions).call(_context3, function (option) {
165
+ value = _mapInstanceProperty(_context4 = nextSelectedOptions).call(_context4, function (option) {
149
166
  return option.value;
150
167
  });
151
168
  } else {
@@ -196,7 +213,7 @@ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
196
213
  value: _pt.string.isRequired,
197
214
  label: _pt.node
198
215
  })).isRequired
199
- }))]),
216
+ }))]).isRequired,
200
217
  showOptionGroupDivider: _pt.bool
201
218
  } : {};
202
219
  SelectInput.displayName = 'SelectInput';
@@ -242,6 +259,6 @@ SelectInput.ValueContainer = components.ValueContainer;
242
259
  var SelectInput$1 = SelectInput;
243
260
 
244
261
  // NOTE: This string will be replaced on build time with the package version.
245
- var version = "15.14.2";
262
+ var version = "15.15.0";
246
263
 
247
264
  export { SelectInput$1 as default, version };
@@ -1 +1 @@
1
- export type { TSelectInputProps, TOption } from './select-input';
1
+ export type { TSelectInputProps, TOption, TOptionObject, TOptions, TCustomEvent, } from './select-input';
@@ -4,11 +4,11 @@ export type TOption = {
4
4
  value: string;
5
5
  label?: ReactNode;
6
6
  };
7
- type TOptionObject = {
7
+ export type TOptionObject = {
8
8
  options: TOption[];
9
9
  };
10
- type TOptions = TOption[] | TOptionObject[];
11
- type TCustomEvent = {
10
+ export type TOptions = TOption[] | TOptionObject[];
11
+ export type TCustomEvent = {
12
12
  target: {
13
13
  id?: ReactSelectProps['inputId'];
14
14
  name?: ReactSelectProps['name'];
@@ -50,7 +50,7 @@ export type TSelectInputProps = {
50
50
  onChange?: (event: TCustomEvent) => void;
51
51
  onFocus?: ReactSelectProps['onFocus'];
52
52
  onInputChange?: ReactSelectProps['onInputChange'];
53
- options?: TOptions;
53
+ options: TOptions;
54
54
  showOptionGroupDivider?: boolean;
55
55
  placeholder?: ReactSelectProps['placeholder'];
56
56
  tabIndex?: ReactSelectProps['tabIndex'];
@@ -60,10 +60,10 @@ export type TSelectInputProps = {
60
60
  declare const SelectInput: {
61
61
  (props: TSelectInputProps): import("@emotion/react/jsx-runtime").JSX.Element;
62
62
  displayName: string;
63
- defaultProps: Pick<TSelectInputProps, "maxMenuHeight" | "menuPortalZIndex">;
63
+ defaultProps: Pick<TSelectInputProps, "controlShouldRenderValue" | "maxMenuHeight" | "options" | "menuPortalZIndex">;
64
64
  isTouched(touched: boolean | unknown[]): boolean;
65
65
  ClearIndicator: {
66
- (props: import("@commercetools-uikit/select-utils/src/clear-indicator/clear-indicator").TClearIndicator): import("@emotion/react/jsx-runtime").JSX.Element;
66
+ (props: import("@commercetools-uikit/select-utils").TClearIndicatorProps): import("@emotion/react/jsx-runtime").JSX.Element;
67
67
  displayName: string;
68
68
  };
69
69
  Control: <Option_1, IsMulti_1 extends boolean, Group_1 extends import("react-select").GroupBase<Option_1>>(props: import("react-select").ControlProps<Option_1, IsMulti_1, Group_1>) => import("@emotion/react").jsx.JSX.Element;
@@ -97,7 +97,7 @@ declare const SelectInput: {
97
97
  MultiValueContainer: <Option_15, IsMulti_15 extends boolean, Group_15 extends import("react-select").GroupBase<Option_15>>({ children, innerProps, }: import("react-select").MultiValueGenericProps<Option_15, IsMulti_15, Group_15>) => import("@emotion/react").jsx.JSX.Element;
98
98
  MultiValueLabel: <Option_15_1, IsMulti_15_1 extends boolean, Group_15_1 extends import("react-select").GroupBase<Option_15_1>>({ children, innerProps, }: import("react-select").MultiValueGenericProps<Option_15_1, IsMulti_15_1, Group_15_1>) => import("@emotion/react").jsx.JSX.Element;
99
99
  MultiValueRemove: {
100
- (props: import("@commercetools-uikit/select-utils/src/tag-remove/tag-remove").TTagRemoveProps): import("@emotion/react/jsx-runtime").JSX.Element;
100
+ (props: import("@commercetools-uikit/select-utils").TTagRemoveProps): import("@emotion/react/jsx-runtime").JSX.Element;
101
101
  displayName: string;
102
102
  };
103
103
  NoOptionsMessage: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/select-input",
3
3
  "description": "An input component getting a selection from the user.",
4
- "version": "15.14.2",
4
+ "version": "15.15.0",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,11 +21,11 @@
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.20.13",
23
23
  "@babel/runtime-corejs3": "^7.20.13",
24
- "@commercetools-uikit/constraints": "15.14.2",
25
- "@commercetools-uikit/design-system": "15.14.2",
26
- "@commercetools-uikit/icons": "15.14.2",
27
- "@commercetools-uikit/select-utils": "15.14.2",
28
- "@commercetools-uikit/utils": "15.14.2",
24
+ "@commercetools-uikit/constraints": "15.15.0",
25
+ "@commercetools-uikit/design-system": "15.15.0",
26
+ "@commercetools-uikit/icons": "15.15.0",
27
+ "@commercetools-uikit/select-utils": "15.15.0",
28
+ "@commercetools-uikit/utils": "15.15.0",
29
29
  "@emotion/is-prop-valid": "1.2.0",
30
30
  "@emotion/react": "^11.10.5",
31
31
  "@emotion/styled": "^11.10.5",