@commercetools-uikit/async-creatable-select-input 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339
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 +21 -0
- package/README.md +162 -0
- package/dist/commercetools-uikit-async-creatable-select-input.cjs.d.ts +3 -0
- package/dist/commercetools-uikit-async-creatable-select-input.cjs.dev.js +265 -0
- package/dist/commercetools-uikit-async-creatable-select-input.cjs.js +7 -0
- package/dist/commercetools-uikit-async-creatable-select-input.cjs.prod.js +247 -0
- package/dist/commercetools-uikit-async-creatable-select-input.esm.js +243 -0
- package/dist/declarations/src/async-creatable-select-input.d.ts +333 -0
- package/dist/declarations/src/export-types.d.ts +1 -0
- package/dist/declarations/src/index.d.ts +3 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/package.json +57 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
6
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
7
|
+
require('prop-types');
|
|
8
|
+
require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
9
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
10
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
11
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
12
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
13
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
14
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
15
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
16
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
17
|
+
var reactIntl = require('react-intl');
|
|
18
|
+
var isEmpty = require('lodash/isEmpty');
|
|
19
|
+
var reactSelect = require('react-select');
|
|
20
|
+
var AsyncCreatableSelect = require('react-select/async-creatable');
|
|
21
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
22
|
+
var LoadingSpinner = require('@commercetools-uikit/loading-spinner');
|
|
23
|
+
var selectUtils = require('@commercetools-uikit/select-utils');
|
|
24
|
+
var utils = require('@commercetools-uikit/utils');
|
|
25
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
26
|
+
|
|
27
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
28
|
+
|
|
29
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
30
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
31
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
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 isEmpty__default = /*#__PURE__*/_interopDefault(isEmpty);
|
|
38
|
+
var AsyncCreatableSelect__default = /*#__PURE__*/_interopDefault(AsyncCreatableSelect);
|
|
39
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
40
|
+
var LoadingSpinner__default = /*#__PURE__*/_interopDefault(LoadingSpinner);
|
|
41
|
+
|
|
42
|
+
const _excluded = ["value", "isSearchable", "menuPortalZIndex"];
|
|
43
|
+
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
44
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
45
|
+
const LoadingIndicator = () => jsxRuntime.jsx(LoadingSpinner__default["default"], {
|
|
46
|
+
scale: "s"
|
|
47
|
+
});
|
|
48
|
+
LoadingIndicator.displayName = 'LoadingIndicator';
|
|
49
|
+
const customizedComponents = {
|
|
50
|
+
DropdownIndicator: selectUtils.DropdownIndicator,
|
|
51
|
+
ClearIndicator: selectUtils.ClearIndicator,
|
|
52
|
+
LoadingIndicator,
|
|
53
|
+
MultiValueRemove: selectUtils.TagRemove
|
|
54
|
+
};
|
|
55
|
+
const AsyncCreatableSelectInput = _ref => {
|
|
56
|
+
let _ref$value = _ref.value,
|
|
57
|
+
value = _ref$value === void 0 ? null : _ref$value,
|
|
58
|
+
_ref$isSearchable = _ref.isSearchable,
|
|
59
|
+
isSearchable = _ref$isSearchable === void 0 ? true : _ref$isSearchable,
|
|
60
|
+
_ref$menuPortalZIndex = _ref.menuPortalZIndex,
|
|
61
|
+
menuPortalZIndex = _ref$menuPortalZIndex === void 0 ? 1 : _ref$menuPortalZIndex,
|
|
62
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
63
|
+
const intl = reactIntl.useIntl();
|
|
64
|
+
const placeholder = props.placeholder || intl.formatMessage(selectUtils.messages.placeholder);
|
|
65
|
+
if (!props.isReadOnly) ;
|
|
66
|
+
if (props.isMulti) ;
|
|
67
|
+
selectUtils.warnIfMenuPortalPropsAreMissing({
|
|
68
|
+
menuPortalZIndex: menuPortalZIndex,
|
|
69
|
+
menuPortalTarget: props.menuPortalTarget,
|
|
70
|
+
componentName: 'AsyncCreatableSelectInput'
|
|
71
|
+
});
|
|
72
|
+
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
73
|
+
max: props.horizontalConstraint,
|
|
74
|
+
children: jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, utils.filterDataAttributes(_objectSpread({
|
|
75
|
+
value,
|
|
76
|
+
isSearchable,
|
|
77
|
+
menuPortalZIndex
|
|
78
|
+
}, props))), {}, {
|
|
79
|
+
children: jsxRuntime.jsx(AsyncCreatableSelect__default["default"], {
|
|
80
|
+
"aria-label": props['aria-label'],
|
|
81
|
+
"aria-labelledby": props['aria-labelledby'],
|
|
82
|
+
"aria-invalid": props['aria-invalid'],
|
|
83
|
+
"aria-errormessage": props['aria-errormessage'],
|
|
84
|
+
autoFocus: props.isAutofocussed,
|
|
85
|
+
backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
|
|
86
|
+
components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? selectUtils.customComponentsWithIcons : {}), props.isReadOnly ? {
|
|
87
|
+
Input: ownProps => jsxRuntime.jsx(reactSelect.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
|
|
88
|
+
readOnly: true
|
|
89
|
+
}))
|
|
90
|
+
} : {}), props.components),
|
|
91
|
+
menuIsOpen: props.isReadOnly ? false : undefined,
|
|
92
|
+
styles: selectUtils.createSelectStyles({
|
|
93
|
+
hasWarning: props.hasWarning,
|
|
94
|
+
hasError: props.hasError,
|
|
95
|
+
showOptionGroupDivider: props.showOptionGroupDivider,
|
|
96
|
+
menuPortalZIndex: menuPortalZIndex,
|
|
97
|
+
isCondensed: props.isCondensed,
|
|
98
|
+
isDisabled: props.isDisabled,
|
|
99
|
+
isReadOnly: props.isReadOnly,
|
|
100
|
+
iconLeft: props.iconLeft,
|
|
101
|
+
isMulti: props.isMulti,
|
|
102
|
+
hasValue: !isEmpty__default["default"](value),
|
|
103
|
+
horizontalConstraint: props.horizontalConstraint
|
|
104
|
+
}),
|
|
105
|
+
filterOption: props.filterOption
|
|
106
|
+
// react-select uses "id" (for the container) and "inputId" (for the input),
|
|
107
|
+
// but we use "id" (for the input) and "containerId" (for the container)
|
|
108
|
+
// instead.
|
|
109
|
+
// This makes it easier to less confusing to use with <label />s.
|
|
110
|
+
,
|
|
111
|
+
id: props.containerId,
|
|
112
|
+
inputId: props.id,
|
|
113
|
+
inputValue: props.inputValue,
|
|
114
|
+
isClearable: props.isReadOnly ? false : props.isClearable,
|
|
115
|
+
isDisabled: props.isDisabled,
|
|
116
|
+
isOptionDisabled: props.isOptionDisabled,
|
|
117
|
+
isMulti: props.isMulti,
|
|
118
|
+
isSearchable: isSearchable,
|
|
119
|
+
maxMenuHeight: props.maxMenuHeight,
|
|
120
|
+
menuPortalTarget: props.menuPortalTarget,
|
|
121
|
+
menuShouldBlockScroll: props.menuShouldBlockScroll,
|
|
122
|
+
closeMenuOnScroll: props.closeMenuOnSelect,
|
|
123
|
+
name: props.name,
|
|
124
|
+
noOptionsMessage: props.noOptionsMessage || (_ref2 => {
|
|
125
|
+
let inputValue = _ref2.inputValue;
|
|
126
|
+
return inputValue === '' ? intl.formatMessage(selectUtils.messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(selectUtils.messages.noOptionsMessageWithInputValue, {
|
|
127
|
+
inputValue
|
|
128
|
+
});
|
|
129
|
+
}),
|
|
130
|
+
onBlur: props.onBlur ? () => {
|
|
131
|
+
const event = {
|
|
132
|
+
target: {
|
|
133
|
+
id: props.id,
|
|
134
|
+
name: (() => {
|
|
135
|
+
if (!props.name) return undefined;
|
|
136
|
+
if (!props.isMulti) return props.name;
|
|
137
|
+
// We append the ".0" to make Formik set the touched
|
|
138
|
+
// state as an array instead of a boolean only.
|
|
139
|
+
// Otherwise the shapes would clash on submission, as
|
|
140
|
+
// Formik will create an array on submission anyways.
|
|
141
|
+
return `${props.name}.0`;
|
|
142
|
+
})()
|
|
143
|
+
},
|
|
144
|
+
persist: () => {}
|
|
145
|
+
};
|
|
146
|
+
props.onBlur && props.onBlur(event);
|
|
147
|
+
} : undefined,
|
|
148
|
+
onChange: (value, info) => {
|
|
149
|
+
// wrapping breaking changes made in react-select v3
|
|
150
|
+
let newValue = value;
|
|
151
|
+
if (props.isMulti && !newValue) {
|
|
152
|
+
newValue = [];
|
|
153
|
+
}
|
|
154
|
+
props.onChange?.({
|
|
155
|
+
target: {
|
|
156
|
+
id: props.id,
|
|
157
|
+
name: props.name,
|
|
158
|
+
value: newValue
|
|
159
|
+
},
|
|
160
|
+
persist: () => {}
|
|
161
|
+
}, info);
|
|
162
|
+
},
|
|
163
|
+
onFocus: props.onFocus,
|
|
164
|
+
onInputChange: props.onInputChange,
|
|
165
|
+
placeholder: placeholder,
|
|
166
|
+
tabIndex: props.tabIndex,
|
|
167
|
+
tabSelectsValue: props.tabSelectsValue,
|
|
168
|
+
value: value
|
|
169
|
+
// Async react-select props
|
|
170
|
+
,
|
|
171
|
+
defaultOptions: props.defaultOptions,
|
|
172
|
+
loadOptions: props.loadOptions,
|
|
173
|
+
cacheOptions: props.cacheOptions
|
|
174
|
+
// Creatable props
|
|
175
|
+
,
|
|
176
|
+
allowCreateWhileLoading: props.allowCreateWhileLoading,
|
|
177
|
+
formatCreateLabel: props.formatCreateLabel || (inputValue => intl.formatMessage(selectUtils.messages.createLabel, {
|
|
178
|
+
inputValue
|
|
179
|
+
})),
|
|
180
|
+
isValidNewOption: props.isValidNewOption,
|
|
181
|
+
getNewOptionData: props.getNewOptionData,
|
|
182
|
+
onCreateOption: props.onCreateOption,
|
|
183
|
+
createOptionPosition: props.createOptionPosition
|
|
184
|
+
// @ts-ignore
|
|
185
|
+
,
|
|
186
|
+
iconLeft: props.iconLeft,
|
|
187
|
+
isCondensed: props.isCondensed
|
|
188
|
+
})
|
|
189
|
+
}))
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
AsyncCreatableSelectInput.propTypes = {};
|
|
193
|
+
AsyncCreatableSelectInput.displayName = 'AsyncCreatableSelectInput';
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Expose static helper methods.
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
// Formik will set the field to an array on submission, so we always have to
|
|
200
|
+
// deal with an array. The touched state ends up being an empty array in case
|
|
201
|
+
// values were removed only. So we have to treat any array we receive as
|
|
202
|
+
// a signal of the field having been touched.
|
|
203
|
+
AsyncCreatableSelectInput.isTouched = touched => Boolean(touched);
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Expose react-select components for customization purposes.
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
// custom
|
|
210
|
+
AsyncCreatableSelectInput.ClearIndicator = customizedComponents.ClearIndicator;
|
|
211
|
+
AsyncCreatableSelectInput.Control = reactSelect.components.Control;
|
|
212
|
+
//https://github.com/commercetools/ui-kit/pull/3054/files#r1943026570
|
|
213
|
+
AsyncCreatableSelectInput.CrossIcon = reactSelect.components.CrossIcon;
|
|
214
|
+
//https://github.com/commercetools/ui-kit/pull/3054/files#r1943026570
|
|
215
|
+
AsyncCreatableSelectInput.DownChevron = reactSelect.components.DownChevron;
|
|
216
|
+
// custom
|
|
217
|
+
AsyncCreatableSelectInput.DropdownIndicator = customizedComponents.DropdownIndicator;
|
|
218
|
+
AsyncCreatableSelectInput.Group = reactSelect.components.Group;
|
|
219
|
+
AsyncCreatableSelectInput.GroupHeading = reactSelect.components.GroupHeading;
|
|
220
|
+
AsyncCreatableSelectInput.IndicatorSeparator = reactSelect.components.IndicatorSeparator;
|
|
221
|
+
AsyncCreatableSelectInput.IndicatorsContainer = reactSelect.components.IndicatorsContainer;
|
|
222
|
+
AsyncCreatableSelectInput.Input = reactSelect.components.Input;
|
|
223
|
+
// custom
|
|
224
|
+
AsyncCreatableSelectInput.LoadingIndicator = customizedComponents.LoadingIndicator;
|
|
225
|
+
AsyncCreatableSelectInput.LoadingMessage = reactSelect.components.LoadingMessage;
|
|
226
|
+
AsyncCreatableSelectInput.Menu = reactSelect.components.Menu;
|
|
227
|
+
AsyncCreatableSelectInput.MenuList = reactSelect.components.MenuList;
|
|
228
|
+
//https://github.com/commercetools/ui-kit/pull/3054/files#r1943026570
|
|
229
|
+
AsyncCreatableSelectInput.MenuPortal = reactSelect.components.MenuPortal;
|
|
230
|
+
AsyncCreatableSelectInput.MultiValue = reactSelect.components.MultiValue;
|
|
231
|
+
AsyncCreatableSelectInput.MultiValueContainer = reactSelect.components.MultiValueContainer;
|
|
232
|
+
AsyncCreatableSelectInput.MultiValueLabel = reactSelect.components.MultiValueLabel;
|
|
233
|
+
// custom
|
|
234
|
+
AsyncCreatableSelectInput.MultiValueRemove = customizedComponents.MultiValueRemove;
|
|
235
|
+
AsyncCreatableSelectInput.NoOptionsMessage = reactSelect.components.NoOptionsMessage;
|
|
236
|
+
AsyncCreatableSelectInput.Option = reactSelect.components.Option;
|
|
237
|
+
AsyncCreatableSelectInput.Placeholder = reactSelect.components.Placeholder;
|
|
238
|
+
AsyncCreatableSelectInput.SelectContainer = reactSelect.components.SelectContainer;
|
|
239
|
+
AsyncCreatableSelectInput.SingleValue = reactSelect.components.SingleValue;
|
|
240
|
+
AsyncCreatableSelectInput.ValueContainer = reactSelect.components.ValueContainer;
|
|
241
|
+
var AsyncCreatableSelectInput$1 = AsyncCreatableSelectInput;
|
|
242
|
+
|
|
243
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
244
|
+
var version = "19.25.1";
|
|
245
|
+
|
|
246
|
+
exports["default"] = AsyncCreatableSelectInput$1;
|
|
247
|
+
exports.version = version;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
2
|
+
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/esm/objectWithoutProperties';
|
|
3
|
+
import _pt from 'prop-types';
|
|
4
|
+
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
5
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
6
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
7
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
8
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
9
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
10
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
11
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
12
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
13
|
+
import { useIntl } from 'react-intl';
|
|
14
|
+
import isEmpty from 'lodash/isEmpty';
|
|
15
|
+
import { components } from 'react-select';
|
|
16
|
+
import AsyncCreatableSelect from 'react-select/async-creatable';
|
|
17
|
+
import Constraints from '@commercetools-uikit/constraints';
|
|
18
|
+
import LoadingSpinner from '@commercetools-uikit/loading-spinner';
|
|
19
|
+
import { messages, warnIfMenuPortalPropsAreMissing, customComponentsWithIcons, createSelectStyles, DropdownIndicator, ClearIndicator, TagRemove } from '@commercetools-uikit/select-utils';
|
|
20
|
+
import { warning, filterDataAttributes } from '@commercetools-uikit/utils';
|
|
21
|
+
import { jsx } from '@emotion/react/jsx-runtime';
|
|
22
|
+
|
|
23
|
+
const _excluded = ["value", "isSearchable", "menuPortalZIndex"];
|
|
24
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
+
const LoadingIndicator = () => jsx(LoadingSpinner, {
|
|
27
|
+
scale: "s"
|
|
28
|
+
});
|
|
29
|
+
LoadingIndicator.displayName = 'LoadingIndicator';
|
|
30
|
+
const customizedComponents = {
|
|
31
|
+
DropdownIndicator,
|
|
32
|
+
ClearIndicator,
|
|
33
|
+
LoadingIndicator,
|
|
34
|
+
MultiValueRemove: TagRemove
|
|
35
|
+
};
|
|
36
|
+
const AsyncCreatableSelectInput = _ref => {
|
|
37
|
+
let _ref$value = _ref.value,
|
|
38
|
+
value = _ref$value === void 0 ? null : _ref$value,
|
|
39
|
+
_ref$isSearchable = _ref.isSearchable,
|
|
40
|
+
isSearchable = _ref$isSearchable === void 0 ? true : _ref$isSearchable,
|
|
41
|
+
_ref$menuPortalZIndex = _ref.menuPortalZIndex,
|
|
42
|
+
menuPortalZIndex = _ref$menuPortalZIndex === void 0 ? 1 : _ref$menuPortalZIndex,
|
|
43
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
+
const intl = useIntl();
|
|
45
|
+
const placeholder = props.placeholder || intl.formatMessage(messages.placeholder);
|
|
46
|
+
if (!props.isReadOnly) {
|
|
47
|
+
process.env.NODE_ENV !== "production" ? warning(typeof props.onChange === 'function', 'AsyncCreatableSelectInput: `onChange` is required when input is not read only.') : void 0;
|
|
48
|
+
}
|
|
49
|
+
if (props.isMulti) {
|
|
50
|
+
process.env.NODE_ENV !== "production" ? warning(_Array$isArray(value), 'AsyncCreatableSelectInput: `value` is expected to be an array when isMulti is true') : void 0;
|
|
51
|
+
}
|
|
52
|
+
warnIfMenuPortalPropsAreMissing({
|
|
53
|
+
menuPortalZIndex: menuPortalZIndex,
|
|
54
|
+
menuPortalTarget: props.menuPortalTarget,
|
|
55
|
+
componentName: 'AsyncCreatableSelectInput'
|
|
56
|
+
});
|
|
57
|
+
return jsx(Constraints.Horizontal, {
|
|
58
|
+
max: props.horizontalConstraint,
|
|
59
|
+
children: jsx("div", _objectSpread(_objectSpread({}, filterDataAttributes(_objectSpread({
|
|
60
|
+
value,
|
|
61
|
+
isSearchable,
|
|
62
|
+
menuPortalZIndex
|
|
63
|
+
}, props))), {}, {
|
|
64
|
+
children: jsx(AsyncCreatableSelect, {
|
|
65
|
+
"aria-label": props['aria-label'],
|
|
66
|
+
"aria-labelledby": props['aria-labelledby'],
|
|
67
|
+
"aria-invalid": props['aria-invalid'],
|
|
68
|
+
"aria-errormessage": props['aria-errormessage'],
|
|
69
|
+
autoFocus: props.isAutofocussed,
|
|
70
|
+
backspaceRemovesValue: props.isReadOnly ? false : props.backspaceRemovesValue,
|
|
71
|
+
components: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, customizedComponents), props.iconLeft && !props.isMulti ? customComponentsWithIcons : {}), props.isReadOnly ? {
|
|
72
|
+
Input: ownProps => jsx(components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
|
|
73
|
+
readOnly: true
|
|
74
|
+
}))
|
|
75
|
+
} : {}), props.components),
|
|
76
|
+
menuIsOpen: props.isReadOnly ? false : undefined,
|
|
77
|
+
styles: createSelectStyles({
|
|
78
|
+
hasWarning: props.hasWarning,
|
|
79
|
+
hasError: props.hasError,
|
|
80
|
+
showOptionGroupDivider: props.showOptionGroupDivider,
|
|
81
|
+
menuPortalZIndex: menuPortalZIndex,
|
|
82
|
+
isCondensed: props.isCondensed,
|
|
83
|
+
isDisabled: props.isDisabled,
|
|
84
|
+
isReadOnly: props.isReadOnly,
|
|
85
|
+
iconLeft: props.iconLeft,
|
|
86
|
+
isMulti: props.isMulti,
|
|
87
|
+
hasValue: !isEmpty(value),
|
|
88
|
+
horizontalConstraint: props.horizontalConstraint
|
|
89
|
+
}),
|
|
90
|
+
filterOption: props.filterOption
|
|
91
|
+
// react-select uses "id" (for the container) and "inputId" (for the input),
|
|
92
|
+
// but we use "id" (for the input) and "containerId" (for the container)
|
|
93
|
+
// instead.
|
|
94
|
+
// This makes it easier to less confusing to use with <label />s.
|
|
95
|
+
,
|
|
96
|
+
id: props.containerId,
|
|
97
|
+
inputId: props.id,
|
|
98
|
+
inputValue: props.inputValue,
|
|
99
|
+
isClearable: props.isReadOnly ? false : props.isClearable,
|
|
100
|
+
isDisabled: props.isDisabled,
|
|
101
|
+
isOptionDisabled: props.isOptionDisabled,
|
|
102
|
+
isMulti: props.isMulti,
|
|
103
|
+
isSearchable: isSearchable,
|
|
104
|
+
maxMenuHeight: props.maxMenuHeight,
|
|
105
|
+
menuPortalTarget: props.menuPortalTarget,
|
|
106
|
+
menuShouldBlockScroll: props.menuShouldBlockScroll,
|
|
107
|
+
closeMenuOnScroll: props.closeMenuOnSelect,
|
|
108
|
+
name: props.name,
|
|
109
|
+
noOptionsMessage: props.noOptionsMessage || (_ref2 => {
|
|
110
|
+
let inputValue = _ref2.inputValue;
|
|
111
|
+
return inputValue === '' ? intl.formatMessage(messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(messages.noOptionsMessageWithInputValue, {
|
|
112
|
+
inputValue
|
|
113
|
+
});
|
|
114
|
+
}),
|
|
115
|
+
onBlur: props.onBlur ? () => {
|
|
116
|
+
const event = {
|
|
117
|
+
target: {
|
|
118
|
+
id: props.id,
|
|
119
|
+
name: (() => {
|
|
120
|
+
if (!props.name) return undefined;
|
|
121
|
+
if (!props.isMulti) return props.name;
|
|
122
|
+
// We append the ".0" to make Formik set the touched
|
|
123
|
+
// state as an array instead of a boolean only.
|
|
124
|
+
// Otherwise the shapes would clash on submission, as
|
|
125
|
+
// Formik will create an array on submission anyways.
|
|
126
|
+
return `${props.name}.0`;
|
|
127
|
+
})()
|
|
128
|
+
},
|
|
129
|
+
persist: () => {}
|
|
130
|
+
};
|
|
131
|
+
props.onBlur && props.onBlur(event);
|
|
132
|
+
} : undefined,
|
|
133
|
+
onChange: (value, info) => {
|
|
134
|
+
// wrapping breaking changes made in react-select v3
|
|
135
|
+
let newValue = value;
|
|
136
|
+
if (props.isMulti && !newValue) {
|
|
137
|
+
newValue = [];
|
|
138
|
+
}
|
|
139
|
+
props.onChange?.({
|
|
140
|
+
target: {
|
|
141
|
+
id: props.id,
|
|
142
|
+
name: props.name,
|
|
143
|
+
value: newValue
|
|
144
|
+
},
|
|
145
|
+
persist: () => {}
|
|
146
|
+
}, info);
|
|
147
|
+
},
|
|
148
|
+
onFocus: props.onFocus,
|
|
149
|
+
onInputChange: props.onInputChange,
|
|
150
|
+
placeholder: placeholder,
|
|
151
|
+
tabIndex: props.tabIndex,
|
|
152
|
+
tabSelectsValue: props.tabSelectsValue,
|
|
153
|
+
value: value
|
|
154
|
+
// Async react-select props
|
|
155
|
+
,
|
|
156
|
+
defaultOptions: props.defaultOptions,
|
|
157
|
+
loadOptions: props.loadOptions,
|
|
158
|
+
cacheOptions: props.cacheOptions
|
|
159
|
+
// Creatable props
|
|
160
|
+
,
|
|
161
|
+
allowCreateWhileLoading: props.allowCreateWhileLoading,
|
|
162
|
+
formatCreateLabel: props.formatCreateLabel || (inputValue => intl.formatMessage(messages.createLabel, {
|
|
163
|
+
inputValue
|
|
164
|
+
})),
|
|
165
|
+
isValidNewOption: props.isValidNewOption,
|
|
166
|
+
getNewOptionData: props.getNewOptionData,
|
|
167
|
+
onCreateOption: props.onCreateOption,
|
|
168
|
+
createOptionPosition: props.createOptionPosition
|
|
169
|
+
// @ts-ignore
|
|
170
|
+
,
|
|
171
|
+
iconLeft: props.iconLeft,
|
|
172
|
+
isCondensed: props.isCondensed
|
|
173
|
+
})
|
|
174
|
+
}))
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
AsyncCreatableSelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
178
|
+
horizontalConstraint: _pt.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
179
|
+
hasError: _pt.bool,
|
|
180
|
+
hasWarning: _pt.bool,
|
|
181
|
+
isReadOnly: _pt.bool,
|
|
182
|
+
iconLeft: _pt.node,
|
|
183
|
+
isAutofocussed: _pt.bool,
|
|
184
|
+
isCondensed: _pt.bool,
|
|
185
|
+
menuPortalZIndex: _pt.number,
|
|
186
|
+
onBlur: _pt.func,
|
|
187
|
+
onChange: _pt.func,
|
|
188
|
+
showOptionGroupDivider: _pt.bool
|
|
189
|
+
} : {};
|
|
190
|
+
AsyncCreatableSelectInput.displayName = 'AsyncCreatableSelectInput';
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Expose static helper methods.
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
// Formik will set the field to an array on submission, so we always have to
|
|
197
|
+
// deal with an array. The touched state ends up being an empty array in case
|
|
198
|
+
// values were removed only. So we have to treat any array we receive as
|
|
199
|
+
// a signal of the field having been touched.
|
|
200
|
+
AsyncCreatableSelectInput.isTouched = touched => Boolean(touched);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Expose react-select components for customization purposes.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
// custom
|
|
207
|
+
AsyncCreatableSelectInput.ClearIndicator = customizedComponents.ClearIndicator;
|
|
208
|
+
AsyncCreatableSelectInput.Control = components.Control;
|
|
209
|
+
//https://github.com/commercetools/ui-kit/pull/3054/files#r1943026570
|
|
210
|
+
AsyncCreatableSelectInput.CrossIcon = components.CrossIcon;
|
|
211
|
+
//https://github.com/commercetools/ui-kit/pull/3054/files#r1943026570
|
|
212
|
+
AsyncCreatableSelectInput.DownChevron = components.DownChevron;
|
|
213
|
+
// custom
|
|
214
|
+
AsyncCreatableSelectInput.DropdownIndicator = customizedComponents.DropdownIndicator;
|
|
215
|
+
AsyncCreatableSelectInput.Group = components.Group;
|
|
216
|
+
AsyncCreatableSelectInput.GroupHeading = components.GroupHeading;
|
|
217
|
+
AsyncCreatableSelectInput.IndicatorSeparator = components.IndicatorSeparator;
|
|
218
|
+
AsyncCreatableSelectInput.IndicatorsContainer = components.IndicatorsContainer;
|
|
219
|
+
AsyncCreatableSelectInput.Input = components.Input;
|
|
220
|
+
// custom
|
|
221
|
+
AsyncCreatableSelectInput.LoadingIndicator = customizedComponents.LoadingIndicator;
|
|
222
|
+
AsyncCreatableSelectInput.LoadingMessage = components.LoadingMessage;
|
|
223
|
+
AsyncCreatableSelectInput.Menu = components.Menu;
|
|
224
|
+
AsyncCreatableSelectInput.MenuList = components.MenuList;
|
|
225
|
+
//https://github.com/commercetools/ui-kit/pull/3054/files#r1943026570
|
|
226
|
+
AsyncCreatableSelectInput.MenuPortal = components.MenuPortal;
|
|
227
|
+
AsyncCreatableSelectInput.MultiValue = components.MultiValue;
|
|
228
|
+
AsyncCreatableSelectInput.MultiValueContainer = components.MultiValueContainer;
|
|
229
|
+
AsyncCreatableSelectInput.MultiValueLabel = components.MultiValueLabel;
|
|
230
|
+
// custom
|
|
231
|
+
AsyncCreatableSelectInput.MultiValueRemove = customizedComponents.MultiValueRemove;
|
|
232
|
+
AsyncCreatableSelectInput.NoOptionsMessage = components.NoOptionsMessage;
|
|
233
|
+
AsyncCreatableSelectInput.Option = components.Option;
|
|
234
|
+
AsyncCreatableSelectInput.Placeholder = components.Placeholder;
|
|
235
|
+
AsyncCreatableSelectInput.SelectContainer = components.SelectContainer;
|
|
236
|
+
AsyncCreatableSelectInput.SingleValue = components.SingleValue;
|
|
237
|
+
AsyncCreatableSelectInput.ValueContainer = components.ValueContainer;
|
|
238
|
+
var AsyncCreatableSelectInput$1 = AsyncCreatableSelectInput;
|
|
239
|
+
|
|
240
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
241
|
+
var version = "19.25.1";
|
|
242
|
+
|
|
243
|
+
export { AsyncCreatableSelectInput$1 as default, version };
|