@commercetools-uikit/select-input 15.14.3 → 15.15.1

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) |
@@ -1,2 +1,3 @@
1
1
  export * from "./declarations/src/index";
2
2
  export { default } from "./declarations/src/index";
3
+ //# sourceMappingURL=commercetools-uikit-select-input.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commercetools-uikit-select-input.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -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,32 +41,40 @@ 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; }
50
- var customizedComponents = {
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
+ const customizedComponents = {
51
51
  DropdownIndicator: selectUtils.DropdownIndicator,
52
52
  ClearIndicator: selectUtils.ClearIndicator,
53
53
  MultiValueRemove: selectUtils.TagRemove
54
54
  };
55
- var defaultProps = {
55
+ const defaultProps = {
56
56
  maxMenuHeight: 220,
57
- menuPortalZIndex: 1
57
+ menuPortalZIndex: 1,
58
+ controlShouldRenderValue: true,
59
+ options: []
58
60
  };
59
61
 
60
- var SelectInput = function SelectInput(props) {
61
- var _context, _context2;
62
+ const isOptionObject = option => option.options !== undefined;
62
63
 
63
- var intl = reactIntl.useIntl();
64
+ const SelectInput = props => {
65
+ var _context, _context2, _context3;
64
66
 
65
- var _useTheme = designSystem.useTheme(),
66
- isNewTheme = _useTheme.isNewTheme;
67
+ const intl = reactIntl.useIntl();
67
68
 
68
- var placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
69
+ const _useTheme = designSystem.useTheme(),
70
+ isNewTheme = _useTheme.isNewTheme;
71
+
72
+ selectUtils.warnIfMenuPortalPropsAreMissing({
73
+ menuPortalZIndex: props.menuPortalZIndex,
74
+ menuPortalTarget: props.menuPortalTarget,
75
+ componentName: 'SelectInput'
76
+ });
77
+ const placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
69
78
  // const colourOptions = [{ value: 'green', label: 'Green' }];
70
79
  // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
71
80
  // const groupedOptions = [
@@ -74,18 +83,17 @@ var SelectInput = function SelectInput(props) {
74
83
  // ];
75
84
  // So we "ungroup" the options by merging them all into one list first.
76
85
 
77
- var optionsWithoutGroups = flatMap__default["default"](props.options, function (option) {
78
- return has__default["default"](option, 'value') ? option : option.options;
86
+ const optionsWithoutGroups = _flatMapInstanceProperty__default["default"](_context = props.options).call(_context, option => {
87
+ if (isOptionObject(option)) {
88
+ return option.options;
89
+ }
90
+
91
+ return option;
79
92
  });
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
93
+
94
+ const 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
95
  // sorting is not lost
82
- ).call(_context2, function (value) {
83
- return _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
84
- return option.value === value;
85
- });
86
- })).call(_context, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
87
- return has__default["default"](option, 'value') && option.value === props.value;
88
- }) || null;
96
+ ).call(_context3, value => _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, option => option.value === value))).call(_context2, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, option => has__default["default"](option, 'value') && option.value === props.value) || null;
89
97
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
90
98
  max: props.horizontalConstraint,
91
99
  children: jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, utils.filterDataAttributes(props)), {}, {
@@ -97,11 +105,9 @@ var SelectInput = function SelectInput(props) {
97
105
  autoFocus: props.isAutofocussed,
98
106
  backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
99
107
  components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? selectUtils.customComponentsWithIcons : {}), props.isReadOnly ? {
100
- Input: function Input(ownProps) {
101
- return jsxRuntime.jsx(Select.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
102
- readOnly: true
103
- }));
104
- }
108
+ Input: ownProps => jsxRuntime.jsx(Select.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
109
+ readOnly: true
110
+ }))
105
111
  } : {}), props.components),
106
112
  menuIsOpen: props.isReadOnly ? false : undefined,
107
113
  styles: selectUtils.createSelectStyles({
@@ -114,7 +120,8 @@ var SelectInput = function SelectInput(props) {
114
120
  iconLeft: props.iconLeft,
115
121
  isMulti: props.isMulti,
116
122
  hasValue: !isEmpty__default["default"](selectedOptions),
117
- isNewTheme: isNewTheme
123
+ controlShouldRenderValue: props.controlShouldRenderValue,
124
+ isNewTheme
118
125
  }),
119
126
  filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
120
127
  // but we use "id" (for the input) and "containerId" (for the container)
@@ -136,41 +143,39 @@ var SelectInput = function SelectInput(props) {
136
143
  menuShouldBlockScroll: props.menuShouldBlockScroll,
137
144
  closeMenuOnSelect: props.closeMenuOnSelect,
138
145
  name: props.name,
139
- noOptionsMessage: props.noOptionsMessage || function (_ref) {
140
- var inputValue = _ref.inputValue;
146
+ noOptionsMessage: props.noOptionsMessage || (_ref => {
147
+ let inputValue = _ref.inputValue;
141
148
  return !inputValue || inputValue === '' ? intl.formatMessage(selectUtils.messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(selectUtils.messages.noOptionsMessageWithInputValue, {
142
- inputValue: inputValue
149
+ inputValue
143
150
  });
144
- },
145
- onBlur: typeof props.onBlur === 'function' ? function () {
146
- var event = {
151
+ }),
152
+ onBlur: typeof props.onBlur === 'function' ? () => {
153
+ const event = {
147
154
  target: {
148
155
  id: props.id,
149
- name: function () {
156
+ name: (() => {
150
157
  if (!props.isMulti) return props.name; // We append the ".0" to make Formik set the touched
151
158
  // state as an array instead of a boolean only.
152
159
  // Otherwise the shapes would clash on submission, as
153
160
  // Formik will create an array on submission anyways.
154
161
 
155
162
  return props.name ? "".concat(props.name, ".0") : undefined;
156
- }()
163
+ })()
157
164
  },
158
- persist: function persist() {}
165
+ persist: () => {}
159
166
  };
160
167
  props.onBlur && props.onBlur(event);
161
168
  } : undefined,
162
- onChange: function onChange(nextSelectedOptions) {
169
+ onChange: nextSelectedOptions => {
163
170
  // nextSelectedOptions is either an array, or a single option, or null
164
171
  // depending on whether we're in multi-mode or not (isMulti)
165
- var value = null;
172
+ let value = null;
166
173
 
167
174
  if (props.isMulti) {
168
175
  if (nextSelectedOptions) {
169
- var _context3;
176
+ var _context4;
170
177
 
171
- value = _mapInstanceProperty__default["default"](_context3 = nextSelectedOptions).call(_context3, function (option) {
172
- return option.value;
173
- });
178
+ value = _mapInstanceProperty__default["default"](_context4 = nextSelectedOptions).call(_context4, option => option.value);
174
179
  } else {
175
180
  value = [];
176
181
  }
@@ -182,9 +187,9 @@ var SelectInput = function SelectInput(props) {
182
187
  target: {
183
188
  id: props.id,
184
189
  name: props.name,
185
- value: value
190
+ value
186
191
  },
187
- persist: function persist() {}
192
+ persist: () => {}
188
193
  });
189
194
  },
190
195
  onFocus: props.onFocus,
@@ -219,7 +224,7 @@ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
219
224
  value: _pt__default["default"].string.isRequired,
220
225
  label: _pt__default["default"].node
221
226
  })).isRequired
222
- }))]),
227
+ }))]).isRequired,
223
228
  showOptionGroupDivider: _pt__default["default"].bool
224
229
  } : {};
225
230
  SelectInput.displayName = 'SelectInput';
@@ -229,9 +234,7 @@ SelectInput.defaultProps = defaultProps;
229
234
  */
230
235
  // Both "true" and an empty array [] represent a touched state.
231
236
 
232
- SelectInput.isTouched = function (touched) {
233
- return Boolean(touched);
234
- };
237
+ SelectInput.isTouched = touched => Boolean(touched);
235
238
  /**
236
239
  * Expose react-select components for customization purposes.
237
240
  */
@@ -265,7 +268,7 @@ SelectInput.ValueContainer = Select.components.ValueContainer;
265
268
  var SelectInput$1 = SelectInput;
266
269
 
267
270
  // NOTE: This string will be replaced on build time with the package version.
268
- var version = "15.14.3";
271
+ var version = "15.15.1";
269
272
 
270
273
  exports["default"] = SelectInput$1;
271
274
  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,32 +40,40 @@ 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; }
49
- var customizedComponents = {
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
+ const customizedComponents = {
50
50
  DropdownIndicator: selectUtils.DropdownIndicator,
51
51
  ClearIndicator: selectUtils.ClearIndicator,
52
52
  MultiValueRemove: selectUtils.TagRemove
53
53
  };
54
- var defaultProps = {
54
+ const defaultProps = {
55
55
  maxMenuHeight: 220,
56
- menuPortalZIndex: 1
56
+ menuPortalZIndex: 1,
57
+ controlShouldRenderValue: true,
58
+ options: []
57
59
  };
58
60
 
59
- var SelectInput = function SelectInput(props) {
60
- var _context, _context2;
61
+ const isOptionObject = option => option.options !== undefined;
61
62
 
62
- var intl = reactIntl.useIntl();
63
+ const SelectInput = props => {
64
+ var _context, _context2, _context3;
63
65
 
64
- var _useTheme = designSystem.useTheme(),
65
- isNewTheme = _useTheme.isNewTheme;
66
+ const intl = reactIntl.useIntl();
66
67
 
67
- var placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
68
+ const _useTheme = designSystem.useTheme(),
69
+ isNewTheme = _useTheme.isNewTheme;
70
+
71
+ selectUtils.warnIfMenuPortalPropsAreMissing({
72
+ menuPortalZIndex: props.menuPortalZIndex,
73
+ menuPortalTarget: props.menuPortalTarget,
74
+ componentName: 'SelectInput'
75
+ });
76
+ const placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
68
77
  // const colourOptions = [{ value: 'green', label: 'Green' }];
69
78
  // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
70
79
  // const groupedOptions = [
@@ -73,18 +82,17 @@ var SelectInput = function SelectInput(props) {
73
82
  // ];
74
83
  // So we "ungroup" the options by merging them all into one list first.
75
84
 
76
- var optionsWithoutGroups = flatMap__default["default"](props.options, function (option) {
77
- return has__default["default"](option, 'value') ? option : option.options;
85
+ const optionsWithoutGroups = _flatMapInstanceProperty__default["default"](_context = props.options).call(_context, option => {
86
+ if (isOptionObject(option)) {
87
+ return option.options;
88
+ }
89
+
90
+ return option;
78
91
  });
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
92
+
93
+ const 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
94
  // sorting is not lost
81
- ).call(_context2, function (value) {
82
- return _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
83
- return option.value === value;
84
- });
85
- })).call(_context, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
86
- return has__default["default"](option, 'value') && option.value === props.value;
87
- }) || null;
95
+ ).call(_context3, value => _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, option => option.value === value))).call(_context2, Boolean) : _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, option => has__default["default"](option, 'value') && option.value === props.value) || null;
88
96
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
89
97
  max: props.horizontalConstraint,
90
98
  children: jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, utils.filterDataAttributes(props)), {}, {
@@ -96,11 +104,9 @@ var SelectInput = function SelectInput(props) {
96
104
  autoFocus: props.isAutofocussed,
97
105
  backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
98
106
  components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? selectUtils.customComponentsWithIcons : {}), props.isReadOnly ? {
99
- Input: function Input(ownProps) {
100
- return jsxRuntime.jsx(Select.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
101
- readOnly: true
102
- }));
103
- }
107
+ Input: ownProps => jsxRuntime.jsx(Select.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
108
+ readOnly: true
109
+ }))
104
110
  } : {}), props.components),
105
111
  menuIsOpen: props.isReadOnly ? false : undefined,
106
112
  styles: selectUtils.createSelectStyles({
@@ -113,7 +119,8 @@ var SelectInput = function SelectInput(props) {
113
119
  iconLeft: props.iconLeft,
114
120
  isMulti: props.isMulti,
115
121
  hasValue: !isEmpty__default["default"](selectedOptions),
116
- isNewTheme: isNewTheme
122
+ controlShouldRenderValue: props.controlShouldRenderValue,
123
+ isNewTheme
117
124
  }),
118
125
  filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
119
126
  // but we use "id" (for the input) and "containerId" (for the container)
@@ -135,41 +142,39 @@ var SelectInput = function SelectInput(props) {
135
142
  menuShouldBlockScroll: props.menuShouldBlockScroll,
136
143
  closeMenuOnSelect: props.closeMenuOnSelect,
137
144
  name: props.name,
138
- noOptionsMessage: props.noOptionsMessage || function (_ref) {
139
- var inputValue = _ref.inputValue;
145
+ noOptionsMessage: props.noOptionsMessage || (_ref => {
146
+ let inputValue = _ref.inputValue;
140
147
  return !inputValue || inputValue === '' ? intl.formatMessage(selectUtils.messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(selectUtils.messages.noOptionsMessageWithInputValue, {
141
- inputValue: inputValue
148
+ inputValue
142
149
  });
143
- },
144
- onBlur: typeof props.onBlur === 'function' ? function () {
145
- var event = {
150
+ }),
151
+ onBlur: typeof props.onBlur === 'function' ? () => {
152
+ const event = {
146
153
  target: {
147
154
  id: props.id,
148
- name: function () {
155
+ name: (() => {
149
156
  if (!props.isMulti) return props.name; // We append the ".0" to make Formik set the touched
150
157
  // state as an array instead of a boolean only.
151
158
  // Otherwise the shapes would clash on submission, as
152
159
  // Formik will create an array on submission anyways.
153
160
 
154
161
  return props.name ? "".concat(props.name, ".0") : undefined;
155
- }()
162
+ })()
156
163
  },
157
- persist: function persist() {}
164
+ persist: () => {}
158
165
  };
159
166
  props.onBlur && props.onBlur(event);
160
167
  } : undefined,
161
- onChange: function onChange(nextSelectedOptions) {
168
+ onChange: nextSelectedOptions => {
162
169
  // nextSelectedOptions is either an array, or a single option, or null
163
170
  // depending on whether we're in multi-mode or not (isMulti)
164
- var value = null;
171
+ let value = null;
165
172
 
166
173
  if (props.isMulti) {
167
174
  if (nextSelectedOptions) {
168
- var _context3;
175
+ var _context4;
169
176
 
170
- value = _mapInstanceProperty__default["default"](_context3 = nextSelectedOptions).call(_context3, function (option) {
171
- return option.value;
172
- });
177
+ value = _mapInstanceProperty__default["default"](_context4 = nextSelectedOptions).call(_context4, option => option.value);
173
178
  } else {
174
179
  value = [];
175
180
  }
@@ -181,9 +186,9 @@ var SelectInput = function SelectInput(props) {
181
186
  target: {
182
187
  id: props.id,
183
188
  name: props.name,
184
- value: value
189
+ value
185
190
  },
186
- persist: function persist() {}
191
+ persist: () => {}
187
192
  });
188
193
  },
189
194
  onFocus: props.onFocus,
@@ -208,9 +213,7 @@ SelectInput.defaultProps = defaultProps;
208
213
  */
209
214
  // Both "true" and an empty array [] represent a touched state.
210
215
 
211
- SelectInput.isTouched = function (touched) {
212
- return Boolean(touched);
213
- };
216
+ SelectInput.isTouched = touched => Boolean(touched);
214
217
  /**
215
218
  * Expose react-select components for customization purposes.
216
219
  */
@@ -244,7 +247,7 @@ SelectInput.ValueContainer = Select.components.ValueContainer;
244
247
  var SelectInput$1 = SelectInput;
245
248
 
246
249
  // NOTE: This string will be replaced on build time with the package version.
247
- var version = "15.14.3";
250
+ var version = "15.15.1";
248
251
 
249
252
  exports["default"] = SelectInput$1;
250
253
  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,36 +14,44 @@ 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; }
27
- var customizedComponents = {
28
- DropdownIndicator: DropdownIndicator,
29
- ClearIndicator: ClearIndicator,
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
+ const customizedComponents = {
28
+ DropdownIndicator,
29
+ ClearIndicator,
30
30
  MultiValueRemove: TagRemove
31
31
  };
32
- var defaultProps = {
32
+ const defaultProps = {
33
33
  maxMenuHeight: 220,
34
- menuPortalZIndex: 1
34
+ menuPortalZIndex: 1,
35
+ controlShouldRenderValue: true,
36
+ options: []
35
37
  };
36
38
 
37
- var SelectInput = function SelectInput(props) {
38
- var _context, _context2;
39
+ const isOptionObject = option => option.options !== undefined;
39
40
 
40
- var intl = useIntl();
41
+ const SelectInput = props => {
42
+ var _context, _context2, _context3;
41
43
 
42
- var _useTheme = useTheme(),
43
- isNewTheme = _useTheme.isNewTheme;
44
+ const intl = useIntl();
44
45
 
45
- var placeholder = props.placeholder || intl.formatMessage(messages.placeholder); // Options can be grouped as
46
+ const _useTheme = useTheme(),
47
+ isNewTheme = _useTheme.isNewTheme;
48
+
49
+ warnIfMenuPortalPropsAreMissing({
50
+ menuPortalZIndex: props.menuPortalZIndex,
51
+ menuPortalTarget: props.menuPortalTarget,
52
+ componentName: 'SelectInput'
53
+ });
54
+ const placeholder = props.placeholder || intl.formatMessage(messages.placeholder); // Options can be grouped as
46
55
  // const colourOptions = [{ value: 'green', label: 'Green' }];
47
56
  // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
48
57
  // const groupedOptions = [
@@ -51,18 +60,17 @@ var SelectInput = function SelectInput(props) {
51
60
  // ];
52
61
  // So we "ungroup" the options by merging them all into one list first.
53
62
 
54
- var optionsWithoutGroups = flatMap(props.options, function (option) {
55
- return has(option, 'value') ? option : option.options;
63
+ const optionsWithoutGroups = _flatMapInstanceProperty(_context = props.options).call(_context, option => {
64
+ if (isOptionObject(option)) {
65
+ return option.options;
66
+ }
67
+
68
+ return option;
56
69
  });
57
- var selectedOptions = props.isMulti ? _filterInstanceProperty(_context = _mapInstanceProperty(_context2 = props.value || [] // Pass the options in the order selected by the use, so that the
70
+
71
+ const selectedOptions = props.isMulti ? _filterInstanceProperty(_context2 = _mapInstanceProperty(_context3 = props.value || [] // Pass the options in the order selected by the use, so that the
58
72
  // sorting is not lost
59
- ).call(_context2, function (value) {
60
- return _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
61
- return option.value === value;
62
- });
63
- })).call(_context, Boolean) : _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
64
- return has(option, 'value') && option.value === props.value;
65
- }) || null;
73
+ ).call(_context3, value => _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, option => option.value === value))).call(_context2, Boolean) : _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, option => has(option, 'value') && option.value === props.value) || null;
66
74
  return jsx(Constraints.Horizontal, {
67
75
  max: props.horizontalConstraint,
68
76
  children: jsx("div", _objectSpread(_objectSpread({}, filterDataAttributes(props)), {}, {
@@ -74,11 +82,9 @@ var SelectInput = function SelectInput(props) {
74
82
  autoFocus: props.isAutofocussed,
75
83
  backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
76
84
  components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? customComponentsWithIcons : {}), props.isReadOnly ? {
77
- Input: function Input(ownProps) {
78
- return jsx(components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
79
- readOnly: true
80
- }));
81
- }
85
+ Input: ownProps => jsx(components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
86
+ readOnly: true
87
+ }))
82
88
  } : {}), props.components),
83
89
  menuIsOpen: props.isReadOnly ? false : undefined,
84
90
  styles: createSelectStyles({
@@ -91,7 +97,8 @@ var SelectInput = function SelectInput(props) {
91
97
  iconLeft: props.iconLeft,
92
98
  isMulti: props.isMulti,
93
99
  hasValue: !isEmpty(selectedOptions),
94
- isNewTheme: isNewTheme
100
+ controlShouldRenderValue: props.controlShouldRenderValue,
101
+ isNewTheme
95
102
  }),
96
103
  filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
97
104
  // but we use "id" (for the input) and "containerId" (for the container)
@@ -113,41 +120,39 @@ var SelectInput = function SelectInput(props) {
113
120
  menuShouldBlockScroll: props.menuShouldBlockScroll,
114
121
  closeMenuOnSelect: props.closeMenuOnSelect,
115
122
  name: props.name,
116
- noOptionsMessage: props.noOptionsMessage || function (_ref) {
117
- var inputValue = _ref.inputValue;
123
+ noOptionsMessage: props.noOptionsMessage || (_ref => {
124
+ let inputValue = _ref.inputValue;
118
125
  return !inputValue || inputValue === '' ? intl.formatMessage(messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(messages.noOptionsMessageWithInputValue, {
119
- inputValue: inputValue
126
+ inputValue
120
127
  });
121
- },
122
- onBlur: typeof props.onBlur === 'function' ? function () {
123
- var event = {
128
+ }),
129
+ onBlur: typeof props.onBlur === 'function' ? () => {
130
+ const event = {
124
131
  target: {
125
132
  id: props.id,
126
- name: function () {
133
+ name: (() => {
127
134
  if (!props.isMulti) return props.name; // We append the ".0" to make Formik set the touched
128
135
  // state as an array instead of a boolean only.
129
136
  // Otherwise the shapes would clash on submission, as
130
137
  // Formik will create an array on submission anyways.
131
138
 
132
139
  return props.name ? "".concat(props.name, ".0") : undefined;
133
- }()
140
+ })()
134
141
  },
135
- persist: function persist() {}
142
+ persist: () => {}
136
143
  };
137
144
  props.onBlur && props.onBlur(event);
138
145
  } : undefined,
139
- onChange: function onChange(nextSelectedOptions) {
146
+ onChange: nextSelectedOptions => {
140
147
  // nextSelectedOptions is either an array, or a single option, or null
141
148
  // depending on whether we're in multi-mode or not (isMulti)
142
- var value = null;
149
+ let value = null;
143
150
 
144
151
  if (props.isMulti) {
145
152
  if (nextSelectedOptions) {
146
- var _context3;
153
+ var _context4;
147
154
 
148
- value = _mapInstanceProperty(_context3 = nextSelectedOptions).call(_context3, function (option) {
149
- return option.value;
150
- });
155
+ value = _mapInstanceProperty(_context4 = nextSelectedOptions).call(_context4, option => option.value);
151
156
  } else {
152
157
  value = [];
153
158
  }
@@ -159,9 +164,9 @@ var SelectInput = function SelectInput(props) {
159
164
  target: {
160
165
  id: props.id,
161
166
  name: props.name,
162
- value: value
167
+ value
163
168
  },
164
- persist: function persist() {}
169
+ persist: () => {}
165
170
  });
166
171
  },
167
172
  onFocus: props.onFocus,
@@ -196,7 +201,7 @@ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
196
201
  value: _pt.string.isRequired,
197
202
  label: _pt.node
198
203
  })).isRequired
199
- }))]),
204
+ }))]).isRequired,
200
205
  showOptionGroupDivider: _pt.bool
201
206
  } : {};
202
207
  SelectInput.displayName = 'SelectInput';
@@ -206,9 +211,7 @@ SelectInput.defaultProps = defaultProps;
206
211
  */
207
212
  // Both "true" and an empty array [] represent a touched state.
208
213
 
209
- SelectInput.isTouched = function (touched) {
210
- return Boolean(touched);
211
- };
214
+ SelectInput.isTouched = touched => Boolean(touched);
212
215
  /**
213
216
  * Expose react-select components for customization purposes.
214
217
  */
@@ -242,6 +245,6 @@ SelectInput.ValueContainer = components.ValueContainer;
242
245
  var SelectInput$1 = SelectInput;
243
246
 
244
247
  // NOTE: This string will be replaced on build time with the package version.
245
- var version = "15.14.3";
248
+ var version = "15.15.1";
246
249
 
247
250
  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,7 +60,7 @@ 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
66
  (props: import("@commercetools-uikit/select-utils").TClearIndicatorProps): import("@emotion/react/jsx-runtime").JSX.Element;
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.3",
4
+ "version": "15.15.1",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,17 +21,17 @@
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.20.13",
23
23
  "@babel/runtime-corejs3": "^7.20.13",
24
- "@commercetools-uikit/constraints": "15.14.3",
25
- "@commercetools-uikit/design-system": "15.14.3",
26
- "@commercetools-uikit/icons": "15.14.3",
27
- "@commercetools-uikit/select-utils": "15.14.3",
28
- "@commercetools-uikit/utils": "15.14.3",
24
+ "@commercetools-uikit/constraints": "15.15.1",
25
+ "@commercetools-uikit/design-system": "15.15.1",
26
+ "@commercetools-uikit/icons": "15.15.1",
27
+ "@commercetools-uikit/select-utils": "15.15.1",
28
+ "@commercetools-uikit/utils": "15.15.1",
29
29
  "@emotion/is-prop-valid": "1.2.0",
30
30
  "@emotion/react": "^11.10.5",
31
31
  "@emotion/styled": "^11.10.5",
32
32
  "lodash": "4.17.21",
33
33
  "prop-types": "15.8.1",
34
- "react-select": "5.7.1"
34
+ "react-select": "5.7.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "react": "17.0.2",