@commercetools-uikit/select-input 0.0.0-canary-2021830134526

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ <!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
2
+ <!-- This file is created by the `yarn generate-readme` script. -->
3
+
4
+ # SelectInput
5
+
6
+ ## Description
7
+
8
+ An input component getting a selection from the user.
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ yarn add @commercetools-uikit/select-input
14
+ ```
15
+
16
+ ```
17
+ npm --save install @commercetools-uikit/select-input
18
+ ```
19
+
20
+ Additionally install the peer dependencies (if not present)
21
+
22
+ ```
23
+ yarn add react react-intl
24
+ ```
25
+
26
+ ```
27
+ npm --save install react react-intl
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```jsx
33
+ import PropTypes from 'prop-types';
34
+ import SelectInput from '@commercetools-uikit/select-input';
35
+
36
+ const Example = (props) => (
37
+ <SelectInput
38
+ name="form-field-name"
39
+ value={props.value}
40
+ onChange={
41
+ (/** event */) => {
42
+ // console.log(event.target.value)
43
+ }
44
+ }
45
+ options={[
46
+ { value: 'one', label: 'One' },
47
+ { value: 'two', label: 'Two' },
48
+ ]}
49
+ />
50
+ );
51
+
52
+ Example.propTypes = {
53
+ value: PropTypes.string,
54
+ };
55
+
56
+ export default Example;
57
+ ```
58
+
59
+ ## Properties
60
+
61
+ | Props | Type | Required | Default | Description |
62
+ | ---------------------------------- | -------------------------------------------------------------------------------------------------- | :------: | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
63
+ | `horizontalConstraint` | `enum`<br/>Possible values:<br/>`3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | | |
64
+ | `hasError` | `bool` | | | Indicates that input has errors |
65
+ | `isReadOnly` | `bool` | | | Is the select read-only |
66
+ | `hasWarning` | `bool` | | | Control to indicate on the input if there are selected values that are potentially invalid |
67
+ | `iconLeft` | `node` | | | Icon to display on the left of the placeholder text and selected value. Has no effect when isMulti is enabled. |
68
+ | `aria-label` | `string` | | | Aria label (for assistive tech) |
69
+ | `aria-labelledby` | `string` | | | HTML ID of an element that should be used as the label (for assistive tech) |
70
+ | `isAutofocussed` | `bool` | | | Focus the control when it is mounted |
71
+ | `backspaceRemovesValue` | `bool` | | | Remove the currently focused option when the user presses backspace |
72
+ | `components` | `objectOf(func)` | | | Map of components to overwrite the default ones, see what components you can override |
73
+ | `filterOption` | `func` | | | Custom method to filter whether an option should be displayed in the menu&#xA;<br />&#xA;Signature: `(option, rawInput) => boolean` |
74
+ | `id` | `string` | | | Used as HTML id property. An id is generated automatically when not provided.&#xA;This forwarded as react-select's "inputId" |
75
+ | `inputValue` | `string` | | | |
76
+ | `containerId` | `string` | | | The id to set on the SelectContainer component&#xA;This is forwarded as react-select's "id" |
77
+ | `isClearable` | `bool` | | | Is the select value clearable |
78
+ | `isDisabled` | `bool` | | | Is the select disabled |
79
+ | `isOptionDisabled` | `func` | | | Override the built-in logic to detect whether an option is disabled |
80
+ | `isMulti` | `bool` | | | Support multiple selected options |
81
+ | `isSearchable` | `bool` | | | Whether to enable search functionality |
82
+ | `maxMenuHeight` | `number` | | `220` | Maximum height of the menu before scrolling |
83
+ | `menuPortalTarget` | `SafeHTMLElement` | | | Dom element to portal the select menu to |
84
+ | `menuPortalZIndex` | `number` | | `1` | z-index value for the menu portal |
85
+ | `menuShouldBlockScroll` | `bool` | | | whether the menu should block scroll while open |
86
+ | `name` | `string` | | | Name of the HTML Input (optional - without this, no input will be rendered) |
87
+ | `noOptionsMessage` | `func` | | | Can be used to render a custom value when there are no options (either because of no search results, or all options have been used, or there were none in the first place). Gets called with { inputValue: String }.&#xA;<br />&#xA;`inputValue` will be an empty string when no search text is present.&#xA;<br />&#xA;Signature: `({ inputValue}) => string` |
88
+ | `onBlur` | `func` | | | Handle blur events on the control&#xA;<br />&#xA;Signature: `(event) => void` |
89
+ | `onChange` | `func` | | | 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.&#xA;<br />&#xA;Signature: `(event) => void` |
90
+ | `onFocus` | `func` | | | Handle focus events on the control&#xA;<br />&#xA;Signature: `(event) => void` |
91
+ | `onInputChange` | `func` | | | Handle change events on the input&#xA;<br />&#xA;Signature: `(newValue, actionMeta) => void` |
92
+ | `options` | `array` | | | Array of options that populate the select menu |
93
+ | `options[]<shape>` | `object` | | | |
94
+ | `options[]<shape>.value` | `string` | ✅ | | |
95
+ | `options[]<shape>.options` | `array` | | | |
96
+ | `options[]<shape>.options[].value` | `string` | ✅ | | |
97
+ | `showOptionGroupDivider` | `bool` | | | |
98
+ | `placeholder` | `string` | | | Placeholder text for the select value |
99
+ | `tabIndex` | `string` | | | Sets the tabIndex attribute on the input |
100
+ | `tabSelectsValue` | `bool` | | | Select the currently focused option when the user presses tab |
101
+ | `value` | `custom` | | | The value of the select; reflected by the selected option |
102
+
103
+ ## `react-select` under the hood
104
+
105
+ This input is built on top of [`react-select`](https://github.com/JedWatson/react-select) v2.
106
+ It supports mostly same properties as `react-select`. Behaviour for some props was changed, and support for others was dropped.
107
+
108
+ In case you need one of the currently excluded props, feel free to open a PR adding them.
109
+
110
+ ## `options`
111
+
112
+ The options support a `isDisabled` property which will render the option with a disabled style and will prevent users from selecting it.
113
+
114
+ ## Static Properties
115
+
116
+ ### `isTouched(touched)`
117
+
118
+ Expects to be called with an array or boolean.
119
+ Returns `true` when truthy.
120
+
121
+ ## Components
122
+
123
+ It is possible to customize `SelectInput` by passing the `components` property.
124
+ `SelectInput` exports the default underlying components as static exports.
125
+
126
+ Components available as static exports are:
127
+
128
+ - `ClearIndicator`
129
+ - `Control`
130
+ - `DropdownIndicator`
131
+ - `DownChevron`
132
+ - `CrossIcon`
133
+ - `Group`
134
+ - `GroupHeading`
135
+ - `IndicatorsContainer`
136
+ - `IndicatorSeparator`
137
+ - `Input`
138
+ - `LoadingIndicator`
139
+ - `Menu`
140
+ - `MenuList`
141
+ - `MenuPortal`
142
+ - `LoadingMessage`
143
+ - `NoOptionsMessage`
144
+ - `MultiValue`
145
+ - `MultiValueContainer`
146
+ - `MultiValueLabel`
147
+ - `MultiValueRemove`
148
+ - `Option`
149
+ - `Placeholder`
150
+ - `SelectContainer`
151
+ - `SingleValue`
152
+ - `ValueContainer`
153
+
154
+ See the [official documentation](https://react-select.com/components) for more information about the props they receive.
@@ -0,0 +1,447 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
6
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
7
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
8
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
9
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
10
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
11
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
12
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
13
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
14
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
15
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
16
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
17
+ var PropTypes = require('prop-types');
18
+ var reactIntl = require('react-intl');
19
+ var react = require('@emotion/react');
20
+ var has = require('lodash/has');
21
+ var flatMap = require('lodash/flatMap');
22
+ var Select = require('react-select');
23
+ var Constraints = require('@commercetools-uikit/constraints');
24
+ var selectUtils = require('@commercetools-uikit/select-utils');
25
+ var utils = require('@commercetools-uikit/utils');
26
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
27
+
28
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
29
+
30
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
31
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
32
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
33
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
34
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
35
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
36
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
37
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
38
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
39
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
40
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
41
+ var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
42
+ var has__default = /*#__PURE__*/_interopDefault(has);
43
+ var flatMap__default = /*#__PURE__*/_interopDefault(flatMap);
44
+ var Select__default = /*#__PURE__*/_interopDefault(Select);
45
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
46
+
47
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (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
+
49
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context5; _forEachInstanceProperty__default['default'](_context5 = ownKeys(Object(source), true)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context6; _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
+ var customizedComponents = {
51
+ DropdownIndicator: selectUtils.DropdownIndicator,
52
+ ClearIndicator: selectUtils.ClearIndicator,
53
+ MultiValueRemove: selectUtils.TagRemove
54
+ };
55
+
56
+ var SelectInput = function SelectInput(props) {
57
+ var _context, _context2;
58
+
59
+ var intl = reactIntl.useIntl();
60
+ var theme = react.useTheme();
61
+ var placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
62
+ // const colourOptions = [{ value: 'green', label: 'Green' }];
63
+ // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
64
+ // const groupedOptions = [
65
+ // { label: 'Colours', options: colourOptions },
66
+ // { label: 'Flavours', options: flavourOptions },
67
+ // ];
68
+ // So we "ungroup" the options by merging them all into one list first.
69
+
70
+ var optionsWithoutGroups = flatMap__default['default'](props.options, function (option) {
71
+ return has__default['default'](option, 'value') ? option : option.options;
72
+ });
73
+ 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
74
+ // sorting is not lost
75
+ ).call(_context2, function (value) {
76
+ return _findInstanceProperty__default['default'](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
77
+ return option.value === value;
78
+ });
79
+ })).call(_context, Boolean) : _findInstanceProperty__default['default'](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
80
+ return has__default['default'](option, 'value') && option.value === props.value;
81
+ }) || null;
82
+ return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
83
+ max: props.horizontalConstraint,
84
+ children: jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, utils.filterDataAttributes(props)), {}, {
85
+ children: jsxRuntime.jsx(Select__default['default'], {
86
+ "aria-label": props['aria-label'],
87
+ "aria-labelledby": props['aria-labelledby'],
88
+ autoFocus: props.isAutofocussed,
89
+ backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
90
+ components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? selectUtils.customComponentsWithIcons : {}), props.isReadOnly ? {
91
+ // eslint-disable-next-line react/display-name
92
+ Input: function Input(ownProps) {
93
+ return jsxRuntime.jsx(Select.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
94
+ readOnly: true
95
+ }));
96
+ }
97
+ } : {}), props.components),
98
+ menuIsOpen: props.isReadOnly ? false : undefined,
99
+ styles: selectUtils.createSelectStyles({
100
+ hasWarning: props.hasWarning,
101
+ hasError: props.hasError,
102
+ showOptionGroupDivider: props.showOptionGroupDivider,
103
+ menuPortalZIndex: props.menuPortalZIndex,
104
+ isDisabled: props.isDisabled,
105
+ isReadOnly: props.isReadOnly
106
+ }, theme),
107
+ filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
108
+ // but we use "id" (for the input) and "containerId" (for the container)
109
+ // instead.
110
+ // This makes it easier to less confusing to use with <label />s.
111
+ ,
112
+ id: props.containerId,
113
+ inputId: props.id,
114
+ inputValue: props.inputValue,
115
+ isClearable: props.isReadOnly ? false : props.isClearable,
116
+ isDisabled: props.isDisabled,
117
+ isReadOnly: props.isReadOnly,
118
+ isOptionDisabled: props.isOptionDisabled,
119
+ isMulti: props.isMulti,
120
+ isSearchable: props.isSearchable,
121
+ maxMenuHeight: props.maxMenuHeight,
122
+ menuPortalTarget: props.menuPortalTarget,
123
+ menuShouldBlockScroll: props.menuShouldBlockScroll,
124
+ name: props.name,
125
+ noOptionsMessage: props.noOptionsMessage || function (_ref) {
126
+ var inputValue = _ref.inputValue;
127
+ return inputValue === '' ? intl.formatMessage(selectUtils.messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(selectUtils.messages.noOptionsMessageWithInputValue, {
128
+ inputValue: inputValue
129
+ });
130
+ },
131
+ onBlur: typeof props.onBlur === 'function' ? function () {
132
+ var event = {
133
+ target: {
134
+ name: function () {
135
+ if (!props.isMulti) return props.name; // We append the ".0" to make Formik set the touched
136
+ // state as an array instead of a boolean only.
137
+ // Otherwise the shapes would clash on submission, as
138
+ // Formik will create an array on submission anyways.
139
+
140
+ return props.name ? "".concat(props.name, ".0") : undefined;
141
+ }()
142
+ },
143
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
144
+ persist: function persist() {}
145
+ };
146
+ props.onBlur(event);
147
+ } : undefined,
148
+ onChange: function onChange(nextSelectedOptions) {
149
+ // nextSelectedOptions is either an array, or a single option, or null
150
+ // depending on whether we're in multi-mode or not (isMulti)
151
+ var value = null;
152
+
153
+ if (props.isMulti) {
154
+ if (nextSelectedOptions) {
155
+ value = _mapInstanceProperty__default['default'](nextSelectedOptions).call(nextSelectedOptions, function (option) {
156
+ return option.value;
157
+ });
158
+ } else {
159
+ value = [];
160
+ }
161
+ } else if (nextSelectedOptions) {
162
+ value = nextSelectedOptions.value;
163
+ }
164
+
165
+ props.onChange({
166
+ target: {
167
+ name: props.name,
168
+ value: value
169
+ },
170
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
171
+ persist: function persist() {}
172
+ });
173
+ },
174
+ onFocus: props.onFocus,
175
+ onInputChange: props.onInputChange,
176
+ options: props.options,
177
+ placeholder: placeholder,
178
+ tabIndex: props.tabIndex,
179
+ tabSelectsValue: props.tabSelectsValue,
180
+ value: selectedOptions,
181
+ iconLeft: props.iconLeft
182
+ })
183
+ }))
184
+ });
185
+ };
186
+
187
+ SelectInput.displayName = 'SelectInput'; // Both "true" and an empty array [] represent a touched state. The Boolean
188
+ // conveniently handles both cases
189
+
190
+ SelectInput.isTouched = function (touched) {
191
+ return Boolean(touched);
192
+ };
193
+
194
+ SelectInput.defaultProps = {
195
+ maxMenuHeight: 220,
196
+ menuPortalZIndex: 1
197
+ };
198
+ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
199
+ horizontalConstraint: PropTypes__default['default'].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
200
+
201
+ /**
202
+ * Indicates that input has errors
203
+ */
204
+ hasError: PropTypes__default['default'].bool,
205
+
206
+ /**
207
+ * Is the select read-only
208
+ */
209
+ isReadOnly: PropTypes__default['default'].bool,
210
+
211
+ /**
212
+ * Control to indicate on the input if there are selected values that are potentially invalid
213
+ */
214
+ hasWarning: PropTypes__default['default'].bool,
215
+
216
+ /**
217
+ * Icon to display on the left of the placeholder text and selected value. Has no effect when isMulti is enabled.
218
+ */
219
+ iconLeft: PropTypes__default['default'].node,
220
+ // react-select base props
221
+ //
222
+ // Currently unsupported props are commented out. In case you need one of
223
+ // these props when using UI Kit, you can submit a PR and enable the
224
+ // prop. Don't forget to add it to the story, docs and other select input
225
+ // components as well!
226
+ //
227
+ // See https://react-select.com/props#select-props
228
+
229
+ /**
230
+ * Aria label (for assistive tech)
231
+ */
232
+ 'aria-label': PropTypes__default['default'].string,
233
+
234
+ /**
235
+ * HTML ID of an element that should be used as the label (for assistive tech)
236
+ */
237
+ 'aria-labelledby': PropTypes__default['default'].string,
238
+
239
+ /**
240
+ * Focus the control when it is mounted
241
+ */
242
+ isAutofocussed: PropTypes__default['default'].bool,
243
+
244
+ /**
245
+ * Remove the currently focused option when the user presses backspace
246
+ */
247
+ backspaceRemovesValue: PropTypes__default['default'].bool,
248
+ // blurInputOnSelect: PropTypes.bool,
249
+ // captureMenuScroll: PropTypes.bool,
250
+ // className: PropTypes.string,
251
+ // classNamePrefix: PropTypes.string,
252
+ // closeMenuOnSelect: PropTypes.bool,
253
+ // closeMenuOnScroll: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
254
+
255
+ /**
256
+ * Map of components to overwrite the default ones, see what components you can override
257
+ */
258
+ components: PropTypes__default['default'].objectOf(PropTypes__default['default'].func),
259
+ // controlShouldRenderValue: PropTypes.bool,
260
+ // delimiter: PropTypes.string,
261
+ // escapeClearsValue: PropTypes.bool,
262
+
263
+ /**
264
+ * Custom method to filter whether an option should be displayed in the menu
265
+ * <br />
266
+ * Signature: `(option, rawInput) => boolean`
267
+ */
268
+ filterOption: PropTypes__default['default'].func,
269
+ // formatGroupLabel: PropTypes.func,
270
+ // formatOptionLabel: PropTypes.func,
271
+ // getOptionLabel: PropTypes.func,
272
+ // getOptionValue: PropTypes.func,
273
+ // hideSelectedOptions: PropTypes.bool,
274
+
275
+ /**
276
+ * Used as HTML id property. An id is generated automatically when not provided.
277
+ *This forwarded as react-select's "inputId"
278
+ */
279
+ id: PropTypes__default['default'].string,
280
+ inputValue: PropTypes__default['default'].string,
281
+
282
+ /**
283
+ * The id to set on the SelectContainer component
284
+ * This is forwarded as react-select's "id"
285
+ */
286
+ containerId: PropTypes__default['default'].string,
287
+ // instanceId: PropTypes.string,
288
+
289
+ /**
290
+ * Is the select value clearable
291
+ */
292
+ isClearable: PropTypes__default['default'].bool,
293
+
294
+ /**
295
+ * Is the select disabled
296
+ */
297
+ isDisabled: PropTypes__default['default'].bool,
298
+ // isLoading: PropTypes.bool,
299
+
300
+ /**
301
+ * Override the built-in logic to detect whether an option is disabled
302
+ */
303
+ isOptionDisabled: PropTypes__default['default'].func,
304
+ // isOptionSelected: PropTypes.func,
305
+
306
+ /**
307
+ * Support multiple selected options
308
+ */
309
+ isMulti: PropTypes__default['default'].bool,
310
+ // isRtl: PropTypes.bool,
311
+
312
+ /**
313
+ * Whether to enable search functionality
314
+ */
315
+ isSearchable: PropTypes__default['default'].bool,
316
+ // loadingMessage: PropTypes.func,
317
+ // minMenuHeight: PropTypes.number,
318
+
319
+ /**
320
+ * Maximum height of the menu before scrolling
321
+ */
322
+ maxMenuHeight: PropTypes__default['default'].number,
323
+ // menuIsOpen: PropTypes.bool,
324
+ // menuPlacement: PropTypes.oneOf(['auto', 'bottom', 'top']),
325
+ // menuPosition: PropTypes.oneOf(['absolute', 'fixed']),
326
+
327
+ /**
328
+ * Dom element to portal the select menu to
329
+ */
330
+ menuPortalTarget: PropTypes__default['default'].instanceOf(utils.SafeHTMLElement),
331
+
332
+ /**
333
+ * z-index value for the menu portal
334
+ */
335
+ menuPortalZIndex: PropTypes__default['default'].number,
336
+
337
+ /**
338
+ * whether the menu should block scroll while open
339
+ */
340
+ menuShouldBlockScroll: PropTypes__default['default'].bool,
341
+ // menuShouldScrollIntoView: PropTypes.bool,
342
+
343
+ /**
344
+ * Name of the HTML Input (optional - without this, no input will be rendered)
345
+ */
346
+ name: PropTypes__default['default'].string,
347
+
348
+ /**
349
+ * Can be used to render a custom value when there are no options (either because of no search results, or all options have been used, or there were none in the first place). Gets called with { inputValue: String }.
350
+ * <br />
351
+ * `inputValue` will be an empty string when no search text is present.
352
+ * <br />
353
+ * Signature: `({ inputValue}) => string`
354
+ */
355
+ noOptionsMessage: PropTypes__default['default'].func,
356
+
357
+ /**
358
+ * Handle blur events on the control
359
+ * <br />
360
+ * Signature: `(event) => void`
361
+ */
362
+ onBlur: PropTypes__default['default'].func,
363
+
364
+ /**
365
+ * 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.
366
+ * <br/>
367
+ * The value will be the selected option, or an array of options in case isMulti is true.
368
+ * <br />
369
+ * Signature: `(event) => void`
370
+ */
371
+ onChange: PropTypes__default['default'].func,
372
+
373
+ /**
374
+ * Handle focus events on the control
375
+ * <br />
376
+ * Signature: `(event) => void`
377
+ */
378
+ onFocus: PropTypes__default['default'].func,
379
+
380
+ /**
381
+ * Handle change events on the input
382
+ * <br />
383
+ * Signature: `(newValue, actionMeta) => void`
384
+ */
385
+ onInputChange: PropTypes__default['default'].func,
386
+ // onKeyDown: PropTypes.func,
387
+ // onMenuOpen: PropTypes.func,
388
+ // onMenuClose: PropTypes.func,
389
+ // onMenuScrollToTop: PropTypes.func,
390
+ // onMenuScrollToBottom: PropTypes.func,
391
+ // openMenuOnFocus: PropTypes.bool,
392
+ // openMenuOnClick: PropTypes.bool,
393
+
394
+ /**
395
+ * Array of options that populate the select menu
396
+ */
397
+ options: PropTypes__default['default'].arrayOf(PropTypes__default['default'].oneOfType([PropTypes__default['default'].shape({
398
+ value: PropTypes__default['default'].string.isRequired
399
+ }), PropTypes__default['default'].shape({
400
+ options: PropTypes__default['default'].arrayOf(PropTypes__default['default'].shape({
401
+ value: PropTypes__default['default'].string.isRequired
402
+ }))
403
+ })])),
404
+ showOptionGroupDivider: PropTypes__default['default'].bool,
405
+ // pageSize: PropTypes.number,
406
+
407
+ /**
408
+ * Placeholder text for the select value
409
+ */
410
+ placeholder: PropTypes__default['default'].string,
411
+ // screenReaderStatus: PropTypes.func,
412
+ // styles: PropTypes.objectOf(PropTypes.func),
413
+ // theme: PropTypes.object,
414
+
415
+ /**
416
+ * Sets the tabIndex attribute on the input
417
+ */
418
+ tabIndex: PropTypes__default['default'].string,
419
+
420
+ /**
421
+ * Select the currently focused option when the user presses tab
422
+ */
423
+ tabSelectsValue: PropTypes__default['default'].bool,
424
+
425
+ /**
426
+ * The value of the select; reflected by the selected option
427
+ */
428
+ value: function value(props) {
429
+ var _PropTypes$arrayOf, _context3, _context4;
430
+
431
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
432
+ rest[_key - 1] = arguments[_key];
433
+ }
434
+
435
+ return props.isMulti ? (_PropTypes$arrayOf = PropTypes__default['default'].arrayOf(PropTypes__default['default'].string)).isRequired.apply(_PropTypes$arrayOf, _concatInstanceProperty__default['default'](_context3 = [props]).call(_context3, rest)) : PropTypes__default['default'].string.apply(PropTypes__default['default'], _concatInstanceProperty__default['default'](_context4 = [props]).call(_context4, rest));
436
+ }
437
+ } : {};
438
+ utils.addStaticFields(SelectInput, _objectSpread(_objectSpread(_objectSpread({}, Select.components), customizedComponents), {}, {
439
+ isTouched: SelectInput.isTouched
440
+ }));
441
+ var SelectInput$1 = SelectInput;
442
+
443
+ // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
444
+ var version = '0.0.0-canary-2021830134526';
445
+
446
+ exports['default'] = SelectInput$1;
447
+ exports.version = version;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-uikit-select-input.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-uikit-select-input.cjs.dev.js");
7
+ }
@@ -0,0 +1,206 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
6
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
7
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
8
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
9
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
10
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
11
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
12
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
13
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
14
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
15
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
16
+ require('@babel/runtime-corejs3/core-js-stable/instance/concat');
17
+ require('prop-types');
18
+ var reactIntl = require('react-intl');
19
+ var react = require('@emotion/react');
20
+ var has = require('lodash/has');
21
+ var flatMap = require('lodash/flatMap');
22
+ var Select = require('react-select');
23
+ var Constraints = require('@commercetools-uikit/constraints');
24
+ var selectUtils = require('@commercetools-uikit/select-utils');
25
+ var utils = require('@commercetools-uikit/utils');
26
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
27
+
28
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
29
+
30
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
31
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
32
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
33
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
34
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
35
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
36
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
37
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
38
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
39
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
40
+ var has__default = /*#__PURE__*/_interopDefault(has);
41
+ var flatMap__default = /*#__PURE__*/_interopDefault(flatMap);
42
+ var Select__default = /*#__PURE__*/_interopDefault(Select);
43
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
44
+
45
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (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; }
46
+
47
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context5; _forEachInstanceProperty__default['default'](_context5 = ownKeys(Object(source), true)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context6; _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; }
48
+ var customizedComponents = {
49
+ DropdownIndicator: selectUtils.DropdownIndicator,
50
+ ClearIndicator: selectUtils.ClearIndicator,
51
+ MultiValueRemove: selectUtils.TagRemove
52
+ };
53
+
54
+ var SelectInput = function SelectInput(props) {
55
+ var _context, _context2;
56
+
57
+ var intl = reactIntl.useIntl();
58
+ var theme = react.useTheme();
59
+ var placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder); // Options can be grouped as
60
+ // const colourOptions = [{ value: 'green', label: 'Green' }];
61
+ // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
62
+ // const groupedOptions = [
63
+ // { label: 'Colours', options: colourOptions },
64
+ // { label: 'Flavours', options: flavourOptions },
65
+ // ];
66
+ // So we "ungroup" the options by merging them all into one list first.
67
+
68
+ var optionsWithoutGroups = flatMap__default['default'](props.options, function (option) {
69
+ return has__default['default'](option, 'value') ? option : option.options;
70
+ });
71
+ 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
72
+ // sorting is not lost
73
+ ).call(_context2, function (value) {
74
+ return _findInstanceProperty__default['default'](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
75
+ return option.value === value;
76
+ });
77
+ })).call(_context, Boolean) : _findInstanceProperty__default['default'](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
78
+ return has__default['default'](option, 'value') && option.value === props.value;
79
+ }) || null;
80
+ return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
81
+ max: props.horizontalConstraint,
82
+ children: jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, utils.filterDataAttributes(props)), {}, {
83
+ children: jsxRuntime.jsx(Select__default['default'], {
84
+ "aria-label": props['aria-label'],
85
+ "aria-labelledby": props['aria-labelledby'],
86
+ autoFocus: props.isAutofocussed,
87
+ backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
88
+ components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? selectUtils.customComponentsWithIcons : {}), props.isReadOnly ? {
89
+ // eslint-disable-next-line react/display-name
90
+ Input: function Input(ownProps) {
91
+ return jsxRuntime.jsx(Select.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
92
+ readOnly: true
93
+ }));
94
+ }
95
+ } : {}), props.components),
96
+ menuIsOpen: props.isReadOnly ? false : undefined,
97
+ styles: selectUtils.createSelectStyles({
98
+ hasWarning: props.hasWarning,
99
+ hasError: props.hasError,
100
+ showOptionGroupDivider: props.showOptionGroupDivider,
101
+ menuPortalZIndex: props.menuPortalZIndex,
102
+ isDisabled: props.isDisabled,
103
+ isReadOnly: props.isReadOnly
104
+ }, theme),
105
+ filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
106
+ // but we use "id" (for the input) and "containerId" (for the container)
107
+ // instead.
108
+ // This makes it easier to less confusing to use with <label />s.
109
+ ,
110
+ id: props.containerId,
111
+ inputId: props.id,
112
+ inputValue: props.inputValue,
113
+ isClearable: props.isReadOnly ? false : props.isClearable,
114
+ isDisabled: props.isDisabled,
115
+ isReadOnly: props.isReadOnly,
116
+ isOptionDisabled: props.isOptionDisabled,
117
+ isMulti: props.isMulti,
118
+ isSearchable: props.isSearchable,
119
+ maxMenuHeight: props.maxMenuHeight,
120
+ menuPortalTarget: props.menuPortalTarget,
121
+ menuShouldBlockScroll: props.menuShouldBlockScroll,
122
+ name: props.name,
123
+ noOptionsMessage: props.noOptionsMessage || function (_ref) {
124
+ var inputValue = _ref.inputValue;
125
+ return inputValue === '' ? intl.formatMessage(selectUtils.messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(selectUtils.messages.noOptionsMessageWithInputValue, {
126
+ inputValue: inputValue
127
+ });
128
+ },
129
+ onBlur: typeof props.onBlur === 'function' ? function () {
130
+ var event = {
131
+ target: {
132
+ name: function () {
133
+ if (!props.isMulti) return props.name; // We append the ".0" to make Formik set the touched
134
+ // state as an array instead of a boolean only.
135
+ // Otherwise the shapes would clash on submission, as
136
+ // Formik will create an array on submission anyways.
137
+
138
+ return props.name ? "".concat(props.name, ".0") : undefined;
139
+ }()
140
+ },
141
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
142
+ persist: function persist() {}
143
+ };
144
+ props.onBlur(event);
145
+ } : undefined,
146
+ onChange: function onChange(nextSelectedOptions) {
147
+ // nextSelectedOptions is either an array, or a single option, or null
148
+ // depending on whether we're in multi-mode or not (isMulti)
149
+ var value = null;
150
+
151
+ if (props.isMulti) {
152
+ if (nextSelectedOptions) {
153
+ value = _mapInstanceProperty__default['default'](nextSelectedOptions).call(nextSelectedOptions, function (option) {
154
+ return option.value;
155
+ });
156
+ } else {
157
+ value = [];
158
+ }
159
+ } else if (nextSelectedOptions) {
160
+ value = nextSelectedOptions.value;
161
+ }
162
+
163
+ props.onChange({
164
+ target: {
165
+ name: props.name,
166
+ value: value
167
+ },
168
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
169
+ persist: function persist() {}
170
+ });
171
+ },
172
+ onFocus: props.onFocus,
173
+ onInputChange: props.onInputChange,
174
+ options: props.options,
175
+ placeholder: placeholder,
176
+ tabIndex: props.tabIndex,
177
+ tabSelectsValue: props.tabSelectsValue,
178
+ value: selectedOptions,
179
+ iconLeft: props.iconLeft
180
+ })
181
+ }))
182
+ });
183
+ };
184
+
185
+ SelectInput.displayName = 'SelectInput'; // Both "true" and an empty array [] represent a touched state. The Boolean
186
+ // conveniently handles both cases
187
+
188
+ SelectInput.isTouched = function (touched) {
189
+ return Boolean(touched);
190
+ };
191
+
192
+ SelectInput.defaultProps = {
193
+ maxMenuHeight: 220,
194
+ menuPortalZIndex: 1
195
+ };
196
+ SelectInput.propTypes = {};
197
+ utils.addStaticFields(SelectInput, _objectSpread(_objectSpread(_objectSpread({}, Select.components), customizedComponents), {}, {
198
+ isTouched: SelectInput.isTouched
199
+ }));
200
+ var SelectInput$1 = SelectInput;
201
+
202
+ // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
203
+ var version = '0.0.0-canary-2021830134526';
204
+
205
+ exports['default'] = SelectInput$1;
206
+ exports.version = version;
@@ -0,0 +1,423 @@
1
+ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
2
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
3
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
4
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
5
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
6
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
7
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
8
+ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
9
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
10
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
11
+ import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
12
+ import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
13
+ import PropTypes from 'prop-types';
14
+ import { useIntl } from 'react-intl';
15
+ import { useTheme } from '@emotion/react';
16
+ import has from 'lodash/has';
17
+ import flatMap from 'lodash/flatMap';
18
+ import Select, { components } from 'react-select';
19
+ import Constraints from '@commercetools-uikit/constraints';
20
+ import { messages, customComponentsWithIcons, createSelectStyles, DropdownIndicator, ClearIndicator, TagRemove } from '@commercetools-uikit/select-utils';
21
+ import { filterDataAttributes, SafeHTMLElement, addStaticFields } from '@commercetools-uikit/utils';
22
+ import { jsx } from '@emotion/react/jsx-runtime';
23
+
24
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
25
+
26
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context5; _forEachInstanceProperty(_context5 = ownKeys(Object(source), true)).call(_context5, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context6; _forEachInstanceProperty(_context6 = ownKeys(Object(source))).call(_context6, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
+ var customizedComponents = {
28
+ DropdownIndicator: DropdownIndicator,
29
+ ClearIndicator: ClearIndicator,
30
+ MultiValueRemove: TagRemove
31
+ };
32
+
33
+ var SelectInput = function SelectInput(props) {
34
+ var _context, _context2;
35
+
36
+ var intl = useIntl();
37
+ var theme = useTheme();
38
+ var placeholder = props.placeholder || intl.formatMessage(messages.placeholder); // Options can be grouped as
39
+ // const colourOptions = [{ value: 'green', label: 'Green' }];
40
+ // const flavourOptions = [{ value: 'vanilla', label: 'Vanilla' }];
41
+ // const groupedOptions = [
42
+ // { label: 'Colours', options: colourOptions },
43
+ // { label: 'Flavours', options: flavourOptions },
44
+ // ];
45
+ // So we "ungroup" the options by merging them all into one list first.
46
+
47
+ var optionsWithoutGroups = flatMap(props.options, function (option) {
48
+ return has(option, 'value') ? option : option.options;
49
+ });
50
+ var selectedOptions = props.isMulti ? _filterInstanceProperty(_context = _mapInstanceProperty(_context2 = props.value // Pass the options in the order selected by the use, so that the
51
+ // sorting is not lost
52
+ ).call(_context2, function (value) {
53
+ return _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
54
+ return option.value === value;
55
+ });
56
+ })).call(_context, Boolean) : _findInstanceProperty(optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
57
+ return has(option, 'value') && option.value === props.value;
58
+ }) || null;
59
+ return jsx(Constraints.Horizontal, {
60
+ max: props.horizontalConstraint,
61
+ children: jsx("div", _objectSpread(_objectSpread({}, filterDataAttributes(props)), {}, {
62
+ children: jsx(Select, {
63
+ "aria-label": props['aria-label'],
64
+ "aria-labelledby": props['aria-labelledby'],
65
+ autoFocus: props.isAutofocussed,
66
+ backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
67
+ components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? customComponentsWithIcons : {}), props.isReadOnly ? {
68
+ // eslint-disable-next-line react/display-name
69
+ Input: function Input(ownProps) {
70
+ return jsx(components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
71
+ readOnly: true
72
+ }));
73
+ }
74
+ } : {}), props.components),
75
+ menuIsOpen: props.isReadOnly ? false : undefined,
76
+ styles: createSelectStyles({
77
+ hasWarning: props.hasWarning,
78
+ hasError: props.hasError,
79
+ showOptionGroupDivider: props.showOptionGroupDivider,
80
+ menuPortalZIndex: props.menuPortalZIndex,
81
+ isDisabled: props.isDisabled,
82
+ isReadOnly: props.isReadOnly
83
+ }, theme),
84
+ filterOption: props.filterOption // react-select uses "id" (for the container) and "inputId" (for the input),
85
+ // but we use "id" (for the input) and "containerId" (for the container)
86
+ // instead.
87
+ // This makes it easier to less confusing to use with <label />s.
88
+ ,
89
+ id: props.containerId,
90
+ inputId: props.id,
91
+ inputValue: props.inputValue,
92
+ isClearable: props.isReadOnly ? false : props.isClearable,
93
+ isDisabled: props.isDisabled,
94
+ isReadOnly: props.isReadOnly,
95
+ isOptionDisabled: props.isOptionDisabled,
96
+ isMulti: props.isMulti,
97
+ isSearchable: props.isSearchable,
98
+ maxMenuHeight: props.maxMenuHeight,
99
+ menuPortalTarget: props.menuPortalTarget,
100
+ menuShouldBlockScroll: props.menuShouldBlockScroll,
101
+ name: props.name,
102
+ noOptionsMessage: props.noOptionsMessage || function (_ref) {
103
+ var inputValue = _ref.inputValue;
104
+ return inputValue === '' ? intl.formatMessage(messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(messages.noOptionsMessageWithInputValue, {
105
+ inputValue: inputValue
106
+ });
107
+ },
108
+ onBlur: typeof props.onBlur === 'function' ? function () {
109
+ var event = {
110
+ target: {
111
+ name: function () {
112
+ if (!props.isMulti) return props.name; // We append the ".0" to make Formik set the touched
113
+ // state as an array instead of a boolean only.
114
+ // Otherwise the shapes would clash on submission, as
115
+ // Formik will create an array on submission anyways.
116
+
117
+ return props.name ? "".concat(props.name, ".0") : undefined;
118
+ }()
119
+ },
120
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
121
+ persist: function persist() {}
122
+ };
123
+ props.onBlur(event);
124
+ } : undefined,
125
+ onChange: function onChange(nextSelectedOptions) {
126
+ // nextSelectedOptions is either an array, or a single option, or null
127
+ // depending on whether we're in multi-mode or not (isMulti)
128
+ var value = null;
129
+
130
+ if (props.isMulti) {
131
+ if (nextSelectedOptions) {
132
+ value = _mapInstanceProperty(nextSelectedOptions).call(nextSelectedOptions, function (option) {
133
+ return option.value;
134
+ });
135
+ } else {
136
+ value = [];
137
+ }
138
+ } else if (nextSelectedOptions) {
139
+ value = nextSelectedOptions.value;
140
+ }
141
+
142
+ props.onChange({
143
+ target: {
144
+ name: props.name,
145
+ value: value
146
+ },
147
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
148
+ persist: function persist() {}
149
+ });
150
+ },
151
+ onFocus: props.onFocus,
152
+ onInputChange: props.onInputChange,
153
+ options: props.options,
154
+ placeholder: placeholder,
155
+ tabIndex: props.tabIndex,
156
+ tabSelectsValue: props.tabSelectsValue,
157
+ value: selectedOptions,
158
+ iconLeft: props.iconLeft
159
+ })
160
+ }))
161
+ });
162
+ };
163
+
164
+ SelectInput.displayName = 'SelectInput'; // Both "true" and an empty array [] represent a touched state. The Boolean
165
+ // conveniently handles both cases
166
+
167
+ SelectInput.isTouched = function (touched) {
168
+ return Boolean(touched);
169
+ };
170
+
171
+ SelectInput.defaultProps = {
172
+ maxMenuHeight: 220,
173
+ menuPortalZIndex: 1
174
+ };
175
+ SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
176
+ horizontalConstraint: PropTypes.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
177
+
178
+ /**
179
+ * Indicates that input has errors
180
+ */
181
+ hasError: PropTypes.bool,
182
+
183
+ /**
184
+ * Is the select read-only
185
+ */
186
+ isReadOnly: PropTypes.bool,
187
+
188
+ /**
189
+ * Control to indicate on the input if there are selected values that are potentially invalid
190
+ */
191
+ hasWarning: PropTypes.bool,
192
+
193
+ /**
194
+ * Icon to display on the left of the placeholder text and selected value. Has no effect when isMulti is enabled.
195
+ */
196
+ iconLeft: PropTypes.node,
197
+ // react-select base props
198
+ //
199
+ // Currently unsupported props are commented out. In case you need one of
200
+ // these props when using UI Kit, you can submit a PR and enable the
201
+ // prop. Don't forget to add it to the story, docs and other select input
202
+ // components as well!
203
+ //
204
+ // See https://react-select.com/props#select-props
205
+
206
+ /**
207
+ * Aria label (for assistive tech)
208
+ */
209
+ 'aria-label': PropTypes.string,
210
+
211
+ /**
212
+ * HTML ID of an element that should be used as the label (for assistive tech)
213
+ */
214
+ 'aria-labelledby': PropTypes.string,
215
+
216
+ /**
217
+ * Focus the control when it is mounted
218
+ */
219
+ isAutofocussed: PropTypes.bool,
220
+
221
+ /**
222
+ * Remove the currently focused option when the user presses backspace
223
+ */
224
+ backspaceRemovesValue: PropTypes.bool,
225
+ // blurInputOnSelect: PropTypes.bool,
226
+ // captureMenuScroll: PropTypes.bool,
227
+ // className: PropTypes.string,
228
+ // classNamePrefix: PropTypes.string,
229
+ // closeMenuOnSelect: PropTypes.bool,
230
+ // closeMenuOnScroll: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
231
+
232
+ /**
233
+ * Map of components to overwrite the default ones, see what components you can override
234
+ */
235
+ components: PropTypes.objectOf(PropTypes.func),
236
+ // controlShouldRenderValue: PropTypes.bool,
237
+ // delimiter: PropTypes.string,
238
+ // escapeClearsValue: PropTypes.bool,
239
+
240
+ /**
241
+ * Custom method to filter whether an option should be displayed in the menu
242
+ * <br />
243
+ * Signature: `(option, rawInput) => boolean`
244
+ */
245
+ filterOption: PropTypes.func,
246
+ // formatGroupLabel: PropTypes.func,
247
+ // formatOptionLabel: PropTypes.func,
248
+ // getOptionLabel: PropTypes.func,
249
+ // getOptionValue: PropTypes.func,
250
+ // hideSelectedOptions: PropTypes.bool,
251
+
252
+ /**
253
+ * Used as HTML id property. An id is generated automatically when not provided.
254
+ *This forwarded as react-select's "inputId"
255
+ */
256
+ id: PropTypes.string,
257
+ inputValue: PropTypes.string,
258
+
259
+ /**
260
+ * The id to set on the SelectContainer component
261
+ * This is forwarded as react-select's "id"
262
+ */
263
+ containerId: PropTypes.string,
264
+ // instanceId: PropTypes.string,
265
+
266
+ /**
267
+ * Is the select value clearable
268
+ */
269
+ isClearable: PropTypes.bool,
270
+
271
+ /**
272
+ * Is the select disabled
273
+ */
274
+ isDisabled: PropTypes.bool,
275
+ // isLoading: PropTypes.bool,
276
+
277
+ /**
278
+ * Override the built-in logic to detect whether an option is disabled
279
+ */
280
+ isOptionDisabled: PropTypes.func,
281
+ // isOptionSelected: PropTypes.func,
282
+
283
+ /**
284
+ * Support multiple selected options
285
+ */
286
+ isMulti: PropTypes.bool,
287
+ // isRtl: PropTypes.bool,
288
+
289
+ /**
290
+ * Whether to enable search functionality
291
+ */
292
+ isSearchable: PropTypes.bool,
293
+ // loadingMessage: PropTypes.func,
294
+ // minMenuHeight: PropTypes.number,
295
+
296
+ /**
297
+ * Maximum height of the menu before scrolling
298
+ */
299
+ maxMenuHeight: PropTypes.number,
300
+ // menuIsOpen: PropTypes.bool,
301
+ // menuPlacement: PropTypes.oneOf(['auto', 'bottom', 'top']),
302
+ // menuPosition: PropTypes.oneOf(['absolute', 'fixed']),
303
+
304
+ /**
305
+ * Dom element to portal the select menu to
306
+ */
307
+ menuPortalTarget: PropTypes.instanceOf(SafeHTMLElement),
308
+
309
+ /**
310
+ * z-index value for the menu portal
311
+ */
312
+ menuPortalZIndex: PropTypes.number,
313
+
314
+ /**
315
+ * whether the menu should block scroll while open
316
+ */
317
+ menuShouldBlockScroll: PropTypes.bool,
318
+ // menuShouldScrollIntoView: PropTypes.bool,
319
+
320
+ /**
321
+ * Name of the HTML Input (optional - without this, no input will be rendered)
322
+ */
323
+ name: PropTypes.string,
324
+
325
+ /**
326
+ * Can be used to render a custom value when there are no options (either because of no search results, or all options have been used, or there were none in the first place). Gets called with { inputValue: String }.
327
+ * <br />
328
+ * `inputValue` will be an empty string when no search text is present.
329
+ * <br />
330
+ * Signature: `({ inputValue}) => string`
331
+ */
332
+ noOptionsMessage: PropTypes.func,
333
+
334
+ /**
335
+ * Handle blur events on the control
336
+ * <br />
337
+ * Signature: `(event) => void`
338
+ */
339
+ onBlur: PropTypes.func,
340
+
341
+ /**
342
+ * 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.
343
+ * <br/>
344
+ * The value will be the selected option, or an array of options in case isMulti is true.
345
+ * <br />
346
+ * Signature: `(event) => void`
347
+ */
348
+ onChange: PropTypes.func,
349
+
350
+ /**
351
+ * Handle focus events on the control
352
+ * <br />
353
+ * Signature: `(event) => void`
354
+ */
355
+ onFocus: PropTypes.func,
356
+
357
+ /**
358
+ * Handle change events on the input
359
+ * <br />
360
+ * Signature: `(newValue, actionMeta) => void`
361
+ */
362
+ onInputChange: PropTypes.func,
363
+ // onKeyDown: PropTypes.func,
364
+ // onMenuOpen: PropTypes.func,
365
+ // onMenuClose: PropTypes.func,
366
+ // onMenuScrollToTop: PropTypes.func,
367
+ // onMenuScrollToBottom: PropTypes.func,
368
+ // openMenuOnFocus: PropTypes.bool,
369
+ // openMenuOnClick: PropTypes.bool,
370
+
371
+ /**
372
+ * Array of options that populate the select menu
373
+ */
374
+ options: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape({
375
+ value: PropTypes.string.isRequired
376
+ }), PropTypes.shape({
377
+ options: PropTypes.arrayOf(PropTypes.shape({
378
+ value: PropTypes.string.isRequired
379
+ }))
380
+ })])),
381
+ showOptionGroupDivider: PropTypes.bool,
382
+ // pageSize: PropTypes.number,
383
+
384
+ /**
385
+ * Placeholder text for the select value
386
+ */
387
+ placeholder: PropTypes.string,
388
+ // screenReaderStatus: PropTypes.func,
389
+ // styles: PropTypes.objectOf(PropTypes.func),
390
+ // theme: PropTypes.object,
391
+
392
+ /**
393
+ * Sets the tabIndex attribute on the input
394
+ */
395
+ tabIndex: PropTypes.string,
396
+
397
+ /**
398
+ * Select the currently focused option when the user presses tab
399
+ */
400
+ tabSelectsValue: PropTypes.bool,
401
+
402
+ /**
403
+ * The value of the select; reflected by the selected option
404
+ */
405
+ value: function value(props) {
406
+ var _PropTypes$arrayOf, _context3, _context4;
407
+
408
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
409
+ rest[_key - 1] = arguments[_key];
410
+ }
411
+
412
+ return props.isMulti ? (_PropTypes$arrayOf = PropTypes.arrayOf(PropTypes.string)).isRequired.apply(_PropTypes$arrayOf, _concatInstanceProperty(_context3 = [props]).call(_context3, rest)) : PropTypes.string.apply(PropTypes, _concatInstanceProperty(_context4 = [props]).call(_context4, rest));
413
+ }
414
+ } : {};
415
+ addStaticFields(SelectInput, _objectSpread(_objectSpread(_objectSpread({}, components), customizedComponents), {}, {
416
+ isTouched: SelectInput.isTouched
417
+ }));
418
+ var SelectInput$1 = SelectInput;
419
+
420
+ // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
421
+ var version = '0.0.0-canary-2021830134526';
422
+
423
+ export { SelectInput$1 as default, version };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@commercetools-uikit/select-input",
3
+ "description": "An input component getting a selection from the user.",
4
+ "version": "0.0.0-canary-2021830134526",
5
+ "bugs": "https://github.com/commercetools/ui-kit/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/commercetools/ui-kit.git",
9
+ "directory": "packages/components/inputs/select-input"
10
+ },
11
+ "homepage": "https://uikit.commercetools.com",
12
+ "keywords": [
13
+ "javascript",
14
+ "design system",
15
+ "react",
16
+ "uikit"
17
+ ],
18
+ "license": "MIT",
19
+ "private": false,
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "sideEffects": false,
24
+ "main": "dist/commercetools-uikit-select-input.cjs.js",
25
+ "module": "dist/commercetools-uikit-select-input.esm.js",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "prepare": "../../../../scripts/version.js replace"
31
+ },
32
+ "dependencies": {
33
+ "@babel/runtime": "7.14.8",
34
+ "@babel/runtime-corejs3": "7.14.9",
35
+ "@commercetools-uikit/constraints": "0.0.0-canary-2021830134526",
36
+ "@commercetools-uikit/design-system": "0.0.0-canary-2021830134526",
37
+ "@commercetools-uikit/icons": "0.0.0-canary-2021830134526",
38
+ "@commercetools-uikit/select-utils": "0.0.0-canary-2021830134526",
39
+ "@commercetools-uikit/utils": "12.2.0",
40
+ "@emotion/is-prop-valid": "1.1.0",
41
+ "@emotion/react": "^11.4.0",
42
+ "@emotion/styled": "^11.3.0",
43
+ "lodash": "4.17.21",
44
+ "prop-types": "15.7.2",
45
+ "react-select": "4.3.1"
46
+ },
47
+ "devDependencies": {
48
+ "react": "17.0.2",
49
+ "react-intl": "5.20.7"
50
+ },
51
+ "peerDependencies": {
52
+ "react": "17.x",
53
+ "react-intl": "5.x"
54
+ }
55
+ }