@commercetools-uikit/creatable-select-field 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 +21 -0
- package/README.md +128 -0
- package/dist/commercetools-uikit-creatable-select-field.cjs.dev.js +476 -0
- package/dist/commercetools-uikit-creatable-select-field.cjs.js +7 -0
- package/dist/commercetools-uikit-creatable-select-field.cjs.prod.js +181 -0
- package/dist/commercetools-uikit-creatable-select-field.esm.js +449 -0
- package/package.json +53 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
6
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
10
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
12
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
13
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
14
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
|
+
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
16
|
+
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
17
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
18
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
19
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
20
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
21
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
22
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
23
|
+
var react = require('react');
|
|
24
|
+
var PropTypes = require('prop-types');
|
|
25
|
+
var requiredIf = require('react-required-if');
|
|
26
|
+
var utils = require('@commercetools-uikit/utils');
|
|
27
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
28
|
+
var Spacings = require('@commercetools-uikit/spacings');
|
|
29
|
+
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
30
|
+
var CreatableSelectInput = require('@commercetools-uikit/creatable-select-input');
|
|
31
|
+
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
32
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
33
|
+
|
|
34
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
35
|
+
|
|
36
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
37
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
38
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
39
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
40
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
41
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
43
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
44
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
45
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
46
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
47
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
48
|
+
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
49
|
+
var requiredIf__default = /*#__PURE__*/_interopDefault(requiredIf);
|
|
50
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
51
|
+
var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
52
|
+
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
53
|
+
var CreatableSelectInput__default = /*#__PURE__*/_interopDefault(CreatableSelectInput);
|
|
54
|
+
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
55
|
+
|
|
56
|
+
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; }
|
|
57
|
+
|
|
58
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context8; _forEachInstanceProperty__default['default'](_context8 = ownKeys(Object(source), true)).call(_context8, 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 _context9; _forEachInstanceProperty__default['default'](_context9 = ownKeys(Object(source))).call(_context9, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
|
|
59
|
+
|
|
60
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
61
|
+
|
|
62
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default['default'](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
63
|
+
var sequentialId = utils.createSequentialId('creatable-select-field-');
|
|
64
|
+
|
|
65
|
+
var hasErrors = function hasErrors(errors) {
|
|
66
|
+
var _context;
|
|
67
|
+
|
|
68
|
+
return errors && _someInstanceProperty__default['default'](_context = _Object$values__default['default'](errors)).call(_context, Boolean);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var CreatableSelectField = /*#__PURE__*/function (_Component) {
|
|
72
|
+
_inherits(CreatableSelectField, _Component);
|
|
73
|
+
|
|
74
|
+
var _super = _createSuper(CreatableSelectField);
|
|
75
|
+
|
|
76
|
+
function CreatableSelectField() {
|
|
77
|
+
var _context2;
|
|
78
|
+
|
|
79
|
+
var _this;
|
|
80
|
+
|
|
81
|
+
_classCallCheck(this, CreatableSelectField);
|
|
82
|
+
|
|
83
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
84
|
+
args[_key] = arguments[_key];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context2 = [this]).call(_context2, args));
|
|
88
|
+
_this.state = {
|
|
89
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
90
|
+
// label to the input component.
|
|
91
|
+
id: _this.props.id
|
|
92
|
+
};
|
|
93
|
+
return _this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
_createClass(CreatableSelectField, [{
|
|
97
|
+
key: "render",
|
|
98
|
+
value: function render() {
|
|
99
|
+
var hasError = CreatableSelectInput__default['default'].isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
100
|
+
return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
|
|
101
|
+
max: this.props.horizontalConstraint,
|
|
102
|
+
children: jsxRuntime.jsxs(Spacings__default['default'].Stack, {
|
|
103
|
+
scale: "xs",
|
|
104
|
+
children: [jsxRuntime.jsx(FieldLabel__default['default'], {
|
|
105
|
+
title: this.props.title,
|
|
106
|
+
hint: this.props.hint,
|
|
107
|
+
description: this.props.description,
|
|
108
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
109
|
+
hintIcon: this.props.hintIcon,
|
|
110
|
+
badge: this.props.badge,
|
|
111
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
112
|
+
htmlFor: this.state.id
|
|
113
|
+
}), jsxRuntime.jsx(CreatableSelectInput__default['default'], _objectSpread({
|
|
114
|
+
horizontalConstraint: "scale",
|
|
115
|
+
hasError: hasError,
|
|
116
|
+
"aria-label": this.props['aria-label'],
|
|
117
|
+
"aria-labelledby": this.props['aria-labelledby'],
|
|
118
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
119
|
+
backspaceRemovesValue: this.props.backspaceRemovesValue,
|
|
120
|
+
components: this.props.components,
|
|
121
|
+
filterOption: this.props.filterOption,
|
|
122
|
+
id: this.state.id,
|
|
123
|
+
containerId: this.props.containerId,
|
|
124
|
+
isClearable: this.props.isClearable,
|
|
125
|
+
isDisabled: this.props.isDisabled,
|
|
126
|
+
isOptionDisabled: this.props.isOptionDisabled,
|
|
127
|
+
isMulti: this.props.isMulti,
|
|
128
|
+
isSearchable: this.props.isSearchable,
|
|
129
|
+
hasWarning: this.props.hasWarning,
|
|
130
|
+
maxMenuHeight: this.props.maxMenuHeight,
|
|
131
|
+
menuPortalTarget: this.props.menuPortalTarget,
|
|
132
|
+
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
133
|
+
menuShouldBlockScroll: this.props.menuShouldBlockScroll,
|
|
134
|
+
name: this.props.name,
|
|
135
|
+
noOptionsMessage: this.props.noOptionsMessage,
|
|
136
|
+
onBlur: this.props.onBlur,
|
|
137
|
+
onChange: this.props.onChange,
|
|
138
|
+
onFocus: this.props.onFocus,
|
|
139
|
+
onInputChange: this.props.onInputChange,
|
|
140
|
+
options: this.props.options,
|
|
141
|
+
placeholder: this.props.placeholder,
|
|
142
|
+
tabIndex: this.props.tabIndex,
|
|
143
|
+
tabSelectsValue: this.props.tabSelectsValue,
|
|
144
|
+
value: this.props.value // Creatable props
|
|
145
|
+
,
|
|
146
|
+
allowCreateWhileLoading: this.props.allowCreateWhileLoading,
|
|
147
|
+
formatCreateLabel: this.props.formatCreateLabel,
|
|
148
|
+
isValidNewOption: this.props.isValidNewOption,
|
|
149
|
+
getNewOptionData: this.props.getNewOptionData,
|
|
150
|
+
onCreateOption: this.props.onCreateOption,
|
|
151
|
+
createOptionPosition: this.props.createOptionPosition,
|
|
152
|
+
showOptionGroupDivider: this.props.showOptionGroupDivider,
|
|
153
|
+
iconLeft: this.props.iconLeft
|
|
154
|
+
}, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default['default'], {
|
|
155
|
+
errors: this.props.errors,
|
|
156
|
+
isVisible: hasError,
|
|
157
|
+
renderError: this.props.renderError
|
|
158
|
+
})]
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}]);
|
|
163
|
+
|
|
164
|
+
return CreatableSelectField;
|
|
165
|
+
}(react.Component);
|
|
166
|
+
|
|
167
|
+
CreatableSelectField.displayName = 'CreatableSelectField';
|
|
168
|
+
CreatableSelectField.defaultProps = {
|
|
169
|
+
horizontalConstraint: 'scale'
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
CreatableSelectField.getDerivedStateFromProps = function (props, state) {
|
|
173
|
+
return {
|
|
174
|
+
id: utils.getFieldId(props, state, sequentialId)
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
CreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
178
|
+
// CreatableSelectField
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Used as HTML id property. An id is auto-generated when it is not specified.
|
|
182
|
+
*/
|
|
183
|
+
id: PropTypes__default['default'].string,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Horizontal size limit of the input fields.
|
|
187
|
+
*/
|
|
188
|
+
horizontalConstraint: PropTypes__default['default'].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A map of errors. Error messages for known errors are rendered automatically.
|
|
192
|
+
* <br />
|
|
193
|
+
* Unknown errors will be forwarded to `renderError`
|
|
194
|
+
*/
|
|
195
|
+
errors: PropTypes__default['default'].shape({
|
|
196
|
+
missing: PropTypes__default['default'].bool
|
|
197
|
+
}),
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
|
|
201
|
+
* <br />
|
|
202
|
+
* Signature: `(key, error) => React.node`
|
|
203
|
+
*/
|
|
204
|
+
renderError: PropTypes__default['default'].func,
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Indicates if the value is required. Shows an the "required asterisk" if so.
|
|
208
|
+
*/
|
|
209
|
+
isRequired: PropTypes__default['default'].bool,
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Indicates whether the field was touched. Errors will only be shown when the field was touched.
|
|
213
|
+
*/
|
|
214
|
+
touched: function touched(props) {
|
|
215
|
+
var _context3, _context4, _context5;
|
|
216
|
+
|
|
217
|
+
for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
218
|
+
rest[_key2 - 1] = arguments[_key2];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return props.isMulti ? PropTypes__default['default'].arrayOf.apply(PropTypes__default['default'], _concatInstanceProperty__default['default'](_context3 = [PropTypes__default['default'].bool]).call(_context3, rest)).apply(void 0, _concatInstanceProperty__default['default'](_context4 = [props]).call(_context4, rest)) : PropTypes__default['default'].bool.apply(PropTypes__default['default'], _concatInstanceProperty__default['default'](_context5 = [props]).call(_context5, rest));
|
|
222
|
+
},
|
|
223
|
+
// CreatableSelectInput
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Aria label (for assistive tech)
|
|
227
|
+
*/
|
|
228
|
+
'aria-label': PropTypes__default['default'].string,
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* HTML ID of an element that should be used as the label (for assistive tech)
|
|
232
|
+
*/
|
|
233
|
+
'aria-labelledby': PropTypes__default['default'].string,
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Focus the control when it is mounted
|
|
237
|
+
*/
|
|
238
|
+
isAutofocussed: PropTypes__default['default'].bool,
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Remove the currently focused option when the user presses backspace
|
|
242
|
+
*/
|
|
243
|
+
backspaceRemovesValue: PropTypes__default['default'].bool,
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Map of components to overwrite the default ones, see [what components you can override](https://react-select.com/components)
|
|
247
|
+
*/
|
|
248
|
+
components: PropTypes__default['default'].objectOf(PropTypes__default['default'].func),
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Custom method to filter whether an option should be displayed in the menu
|
|
252
|
+
*/
|
|
253
|
+
filterOption: PropTypes__default['default'].func,
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The id to set on the SelectContainer component
|
|
257
|
+
*/
|
|
258
|
+
containerId: PropTypes__default['default'].string,
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Is the select value clearable
|
|
262
|
+
*/
|
|
263
|
+
isClearable: PropTypes__default['default'].bool,
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Is the select disabled
|
|
267
|
+
*/
|
|
268
|
+
isDisabled: PropTypes__default['default'].bool,
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Is the select read-only
|
|
272
|
+
*/
|
|
273
|
+
// eslint-disable-next-line react/no-unused-prop-types
|
|
274
|
+
isReadOnly: PropTypes__default['default'].bool,
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Override the built-in logic to detect whether an option is disabled
|
|
278
|
+
*/
|
|
279
|
+
isOptionDisabled: PropTypes__default['default'].func,
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Support multiple selected options
|
|
283
|
+
*/
|
|
284
|
+
isMulti: PropTypes__default['default'].bool,
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Whether to enable search functionality
|
|
288
|
+
*/
|
|
289
|
+
isSearchable: PropTypes__default['default'].bool,
|
|
290
|
+
hasWarning: PropTypes__default['default'].bool,
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Maximum height of the menu before scrolling
|
|
294
|
+
*/
|
|
295
|
+
maxMenuHeight: PropTypes__default['default'].number,
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Dom element to portal the select menu to
|
|
299
|
+
*/
|
|
300
|
+
menuPortalTarget: PropTypes__default['default'].instanceOf(utils.SafeHTMLElement),
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* z-index value for the menu portal
|
|
304
|
+
*/
|
|
305
|
+
menuPortalZIndex: PropTypes__default['default'].number,
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* whether the menu should block scroll while open
|
|
309
|
+
*/
|
|
310
|
+
menuShouldBlockScroll: PropTypes__default['default'].bool,
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Name of the HTML Input (optional - without this, no input will be rendered)
|
|
314
|
+
*/
|
|
315
|
+
name: PropTypes__default['default'].string,
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* 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).
|
|
319
|
+
* <br/>
|
|
320
|
+
* Gets called with `{ inputValue: String }`. `inputValue` will be an empty string when no search text is present.
|
|
321
|
+
* <br />
|
|
322
|
+
* Signature: `({ inputValue }) => string`
|
|
323
|
+
*/
|
|
324
|
+
noOptionsMessage: PropTypes__default['default'].func,
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Handle blur events on the control
|
|
328
|
+
*/
|
|
329
|
+
onBlur: PropTypes__default['default'].func,
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Called with a fake event when value changes.
|
|
333
|
+
* <br />
|
|
334
|
+
* The event's `target.name` will be the name supplied in props. The event's `target.value` will hold the value. The value will be the selected option, or an array of options in case `isMulti` is `true`.
|
|
335
|
+
* <br />
|
|
336
|
+
* Signature: `(event) => void`
|
|
337
|
+
*/
|
|
338
|
+
onChange: PropTypes__default['default'].func,
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Handle focus events on the control
|
|
342
|
+
*/
|
|
343
|
+
onFocus: PropTypes__default['default'].func,
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Handle change events on the input
|
|
347
|
+
*/
|
|
348
|
+
onInputChange: PropTypes__default['default'].func,
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Array of options that populate the select menu
|
|
352
|
+
*/
|
|
353
|
+
options: PropTypes__default['default'].arrayOf(PropTypes__default['default'].oneOfType([PropTypes__default['default'].shape({
|
|
354
|
+
value: PropTypes__default['default'].string.isRequired
|
|
355
|
+
}), PropTypes__default['default'].shape({
|
|
356
|
+
options: PropTypes__default['default'].arrayOf(PropTypes__default['default'].shape({
|
|
357
|
+
value: PropTypes__default['default'].string.isRequired
|
|
358
|
+
}))
|
|
359
|
+
})])),
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Placeholder text for the select value
|
|
363
|
+
*/
|
|
364
|
+
placeholder: PropTypes__default['default'].string,
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Sets the tabIndex attribute on the input
|
|
368
|
+
*/
|
|
369
|
+
tabIndex: PropTypes__default['default'].string,
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Select the currently focused option when the user presses tab
|
|
373
|
+
*/
|
|
374
|
+
tabSelectsValue: PropTypes__default['default'].bool,
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* The value of the select; reflected by the selected option
|
|
378
|
+
*/
|
|
379
|
+
value: function value(props) {
|
|
380
|
+
var _context6, _context7;
|
|
381
|
+
|
|
382
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
383
|
+
rest[_key3 - 1] = arguments[_key3];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return props.isMulti ? PropTypes__default['default'].arrayOf(PropTypes__default['default'].shape({
|
|
387
|
+
value: PropTypes__default['default'].string.isRequired
|
|
388
|
+
})).apply(void 0, _concatInstanceProperty__default['default'](_context6 = [props]).call(_context6, rest)) : PropTypes__default['default'].shape({
|
|
389
|
+
value: PropTypes__default['default'].string.isRequired
|
|
390
|
+
}).apply(void 0, _concatInstanceProperty__default['default'](_context7 = [props]).call(_context7, rest));
|
|
391
|
+
},
|
|
392
|
+
showOptionGroupDivider: PropTypes__default['default'].bool,
|
|
393
|
+
// Creatable props
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Allow options to be created while the isLoading prop is true. Useful to prevent the "create new ..." option being displayed while async results are still being loaded.
|
|
397
|
+
*/
|
|
398
|
+
allowCreateWhileLoading: PropTypes__default['default'].bool,
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Gets the label for the "create new ..." option in the menu. Is given the current input value.
|
|
402
|
+
*/
|
|
403
|
+
formatCreateLabel: PropTypes__default['default'].func,
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Determines whether the "create new ..." option should be displayed based on the current input value, select value and options array.
|
|
407
|
+
*/
|
|
408
|
+
isValidNewOption: PropTypes__default['default'].func,
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Returns the data for the new option when it is created. Used to display the value, and is passed to onChange.
|
|
412
|
+
*/
|
|
413
|
+
getNewOptionData: PropTypes__default['default'].func,
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* If provided, this will be called with the input value when a new option is created, and onChange will not be called. Use this when you need more control over what happens when new options are created.
|
|
417
|
+
*/
|
|
418
|
+
onCreateOption: PropTypes__default['default'].func,
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Sets the position of the createOption element in your options list.
|
|
422
|
+
*/
|
|
423
|
+
createOptionPosition: PropTypes__default['default'].string,
|
|
424
|
+
// LabelField
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Title of the label
|
|
428
|
+
*/
|
|
429
|
+
title: PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]).isRequired,
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`.
|
|
433
|
+
*/
|
|
434
|
+
hint: requiredIf__default['default'](PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]), function (props) {
|
|
435
|
+
return props.hintIcon;
|
|
436
|
+
}),
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Provides a description for the title.
|
|
440
|
+
*/
|
|
441
|
+
description: PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]),
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Function called when info button is pressed.
|
|
445
|
+
* <br />
|
|
446
|
+
* Info button will only be visible when this prop is passed.
|
|
447
|
+
* <br />
|
|
448
|
+
* Signature: `(event) => void`
|
|
449
|
+
*/
|
|
450
|
+
onInfoButtonClick: PropTypes__default['default'].func,
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Icon to be displayed beside the hint text.
|
|
454
|
+
* <br />
|
|
455
|
+
* Will only get rendered when `hint` is passed as well.
|
|
456
|
+
*/
|
|
457
|
+
hintIcon: PropTypes__default['default'].node,
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Badge to be displayed beside the label.
|
|
461
|
+
* <br />
|
|
462
|
+
* Might be used to display additional information about the content of the field (E.g verified email)
|
|
463
|
+
*/
|
|
464
|
+
badge: PropTypes__default['default'].node,
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Icon to display on the left of the placeholder text and selected value. Has no effect when isMulti is enabled.
|
|
468
|
+
*/
|
|
469
|
+
iconLeft: PropTypes__default['default'].node
|
|
470
|
+
} : {};
|
|
471
|
+
|
|
472
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
473
|
+
var version = '0.0.0-canary-2021830134526';
|
|
474
|
+
|
|
475
|
+
exports['default'] = CreatableSelectField;
|
|
476
|
+
exports.version = version;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
6
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
10
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
12
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
13
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
14
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
|
+
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
16
|
+
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
17
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
18
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
19
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
20
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
21
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
22
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
23
|
+
var react = require('react');
|
|
24
|
+
require('prop-types');
|
|
25
|
+
require('react-required-if');
|
|
26
|
+
var utils = require('@commercetools-uikit/utils');
|
|
27
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
28
|
+
var Spacings = require('@commercetools-uikit/spacings');
|
|
29
|
+
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
30
|
+
var CreatableSelectInput = require('@commercetools-uikit/creatable-select-input');
|
|
31
|
+
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
32
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
33
|
+
|
|
34
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
35
|
+
|
|
36
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
37
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
38
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
39
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
40
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
41
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
43
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
44
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
45
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
46
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
47
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
48
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
49
|
+
var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
50
|
+
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
51
|
+
var CreatableSelectInput__default = /*#__PURE__*/_interopDefault(CreatableSelectInput);
|
|
52
|
+
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
53
|
+
|
|
54
|
+
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; }
|
|
55
|
+
|
|
56
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context8; _forEachInstanceProperty__default['default'](_context8 = ownKeys(Object(source), true)).call(_context8, 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 _context9; _forEachInstanceProperty__default['default'](_context9 = ownKeys(Object(source))).call(_context9, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
|
|
57
|
+
|
|
58
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
59
|
+
|
|
60
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default['default'](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
61
|
+
var sequentialId = utils.createSequentialId('creatable-select-field-');
|
|
62
|
+
|
|
63
|
+
var hasErrors = function hasErrors(errors) {
|
|
64
|
+
var _context;
|
|
65
|
+
|
|
66
|
+
return errors && _someInstanceProperty__default['default'](_context = _Object$values__default['default'](errors)).call(_context, Boolean);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
var CreatableSelectField = /*#__PURE__*/function (_Component) {
|
|
70
|
+
_inherits(CreatableSelectField, _Component);
|
|
71
|
+
|
|
72
|
+
var _super = _createSuper(CreatableSelectField);
|
|
73
|
+
|
|
74
|
+
function CreatableSelectField() {
|
|
75
|
+
var _context2;
|
|
76
|
+
|
|
77
|
+
var _this;
|
|
78
|
+
|
|
79
|
+
_classCallCheck(this, CreatableSelectField);
|
|
80
|
+
|
|
81
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
82
|
+
args[_key] = arguments[_key];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context2 = [this]).call(_context2, args));
|
|
86
|
+
_this.state = {
|
|
87
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
88
|
+
// label to the input component.
|
|
89
|
+
id: _this.props.id
|
|
90
|
+
};
|
|
91
|
+
return _this;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_createClass(CreatableSelectField, [{
|
|
95
|
+
key: "render",
|
|
96
|
+
value: function render() {
|
|
97
|
+
var hasError = CreatableSelectInput__default['default'].isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
98
|
+
return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
|
|
99
|
+
max: this.props.horizontalConstraint,
|
|
100
|
+
children: jsxRuntime.jsxs(Spacings__default['default'].Stack, {
|
|
101
|
+
scale: "xs",
|
|
102
|
+
children: [jsxRuntime.jsx(FieldLabel__default['default'], {
|
|
103
|
+
title: this.props.title,
|
|
104
|
+
hint: this.props.hint,
|
|
105
|
+
description: this.props.description,
|
|
106
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
107
|
+
hintIcon: this.props.hintIcon,
|
|
108
|
+
badge: this.props.badge,
|
|
109
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
110
|
+
htmlFor: this.state.id
|
|
111
|
+
}), jsxRuntime.jsx(CreatableSelectInput__default['default'], _objectSpread({
|
|
112
|
+
horizontalConstraint: "scale",
|
|
113
|
+
hasError: hasError,
|
|
114
|
+
"aria-label": this.props['aria-label'],
|
|
115
|
+
"aria-labelledby": this.props['aria-labelledby'],
|
|
116
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
117
|
+
backspaceRemovesValue: this.props.backspaceRemovesValue,
|
|
118
|
+
components: this.props.components,
|
|
119
|
+
filterOption: this.props.filterOption,
|
|
120
|
+
id: this.state.id,
|
|
121
|
+
containerId: this.props.containerId,
|
|
122
|
+
isClearable: this.props.isClearable,
|
|
123
|
+
isDisabled: this.props.isDisabled,
|
|
124
|
+
isOptionDisabled: this.props.isOptionDisabled,
|
|
125
|
+
isMulti: this.props.isMulti,
|
|
126
|
+
isSearchable: this.props.isSearchable,
|
|
127
|
+
hasWarning: this.props.hasWarning,
|
|
128
|
+
maxMenuHeight: this.props.maxMenuHeight,
|
|
129
|
+
menuPortalTarget: this.props.menuPortalTarget,
|
|
130
|
+
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
131
|
+
menuShouldBlockScroll: this.props.menuShouldBlockScroll,
|
|
132
|
+
name: this.props.name,
|
|
133
|
+
noOptionsMessage: this.props.noOptionsMessage,
|
|
134
|
+
onBlur: this.props.onBlur,
|
|
135
|
+
onChange: this.props.onChange,
|
|
136
|
+
onFocus: this.props.onFocus,
|
|
137
|
+
onInputChange: this.props.onInputChange,
|
|
138
|
+
options: this.props.options,
|
|
139
|
+
placeholder: this.props.placeholder,
|
|
140
|
+
tabIndex: this.props.tabIndex,
|
|
141
|
+
tabSelectsValue: this.props.tabSelectsValue,
|
|
142
|
+
value: this.props.value // Creatable props
|
|
143
|
+
,
|
|
144
|
+
allowCreateWhileLoading: this.props.allowCreateWhileLoading,
|
|
145
|
+
formatCreateLabel: this.props.formatCreateLabel,
|
|
146
|
+
isValidNewOption: this.props.isValidNewOption,
|
|
147
|
+
getNewOptionData: this.props.getNewOptionData,
|
|
148
|
+
onCreateOption: this.props.onCreateOption,
|
|
149
|
+
createOptionPosition: this.props.createOptionPosition,
|
|
150
|
+
showOptionGroupDivider: this.props.showOptionGroupDivider,
|
|
151
|
+
iconLeft: this.props.iconLeft
|
|
152
|
+
}, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default['default'], {
|
|
153
|
+
errors: this.props.errors,
|
|
154
|
+
isVisible: hasError,
|
|
155
|
+
renderError: this.props.renderError
|
|
156
|
+
})]
|
|
157
|
+
})
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}]);
|
|
161
|
+
|
|
162
|
+
return CreatableSelectField;
|
|
163
|
+
}(react.Component);
|
|
164
|
+
|
|
165
|
+
CreatableSelectField.displayName = 'CreatableSelectField';
|
|
166
|
+
CreatableSelectField.defaultProps = {
|
|
167
|
+
horizontalConstraint: 'scale'
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
CreatableSelectField.getDerivedStateFromProps = function (props, state) {
|
|
171
|
+
return {
|
|
172
|
+
id: utils.getFieldId(props, state, sequentialId)
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
CreatableSelectField.propTypes = {};
|
|
176
|
+
|
|
177
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
178
|
+
var version = '0.0.0-canary-2021830134526';
|
|
179
|
+
|
|
180
|
+
exports['default'] = CreatableSelectField;
|
|
181
|
+
exports.version = version;
|