@commercetools-uikit/async-creatable-select-field 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 +183 -0
- package/dist/commercetools-uikit-async-creatable-select-field.cjs.d.ts +3 -0
- package/dist/commercetools-uikit-async-creatable-select-field.cjs.dev.js +228 -0
- package/dist/commercetools-uikit-async-creatable-select-field.cjs.js +7 -0
- package/dist/commercetools-uikit-async-creatable-select-field.cjs.prod.js +196 -0
- package/dist/commercetools-uikit-async-creatable-select-field.esm.js +201 -0
- package/dist/declarations/src/async-creatable-select-field.d.ts +340 -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 +51 -0
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,183 @@
|
|
|
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
|
+
# AsyncCreatableSelectField
|
|
5
|
+
|
|
6
|
+
## Description
|
|
7
|
+
|
|
8
|
+
An input component with validation states and a label getting a selection from an asynchronously loaded list from the user, and where options can be created by the user.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
yarn add @commercetools-uikit/async-creatable-select-field
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm --save install @commercetools-uikit/async-creatable-select-field
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Additionally install the peer dependencies (if not present)
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
yarn add react
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npm --save install react
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```jsx
|
|
33
|
+
import AsyncCreatableSelectField from '@commercetools-uikit/async-creatable-select-field';
|
|
34
|
+
|
|
35
|
+
const Example = () => (
|
|
36
|
+
<AsyncCreatableSelectField
|
|
37
|
+
title="State"
|
|
38
|
+
name="form-field-name"
|
|
39
|
+
value={{ value: 'one', label: 'One' }}
|
|
40
|
+
onChange={(event) => alert(event.target.value)}
|
|
41
|
+
loadOptions={() =>
|
|
42
|
+
Promise.resolve([
|
|
43
|
+
{ value: 'one', label: 'One' },
|
|
44
|
+
{ value: 'two', label: 'Two' },
|
|
45
|
+
])
|
|
46
|
+
}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export default Example;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Properties
|
|
54
|
+
|
|
55
|
+
| Props | Type | Required | Default | Description |
|
|
56
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------- | :------: | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
57
|
+
| `id` | `AsyncCreatableProps['inputId']` | | | Used as HTML id property. An id is auto-generated when it is not specified.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
58
|
+
| `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
|
|
59
|
+
| `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.
<br />
Unknown errors will be forwarded to `renderError` |
|
|
60
|
+
| `renderError` | `Function`<br/>[See signature.](#signature-rendererror) | | | 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. |
|
|
61
|
+
| `warnings` | `Record` | | | A map of warnings. Warning messages for known warnings are rendered automatically.
<br />
Unknown warnings will be forwarded to `renderWarning` |
|
|
62
|
+
| `renderWarning` | `Function`<br/>[See signature.](#signature-renderwarning) | | | Called with custom warnings. This function can return a message which will be wrapped in an WarningMessage. It can also return null to show no warning. |
|
|
63
|
+
| `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
64
|
+
| `touched` | `union`<br/>Possible values:<br/>`boolean[] , boolean` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
|
|
65
|
+
| `aria-label` | `AsyncCreatableProps['aria-label']` | | | Aria label (for assistive tech)
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
66
|
+
| `aria-labelledby` | `AsyncCreatableProps['aria-labelledby']` | | | HTML ID of an element that should be used as the label (for assistive tech)
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
67
|
+
| `isAutofocussed` | `boolean` | | | Focus the control when it is mounted |
|
|
68
|
+
| `backspaceRemovesValue` | `AsyncCreatableProps['backspaceRemovesValue']` | | | Remove the currently focused option when the user presses backspace
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
69
|
+
| `components` | `AsyncCreatableProps['components']` | | | Map of components to overwrite the default ones, see [what components you can override](https://react-select.com/components)
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
70
|
+
| `filterOption` | `AsyncCreatableProps['filterOption']` | | | Custom method to filter whether an option should be displayed in the menu
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
71
|
+
| `containerId` | `AsyncCreatableProps['id']` | | | The id to set on the SelectContainer component
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
72
|
+
| `isClearable` | `AsyncCreatableProps['isClearable']` | | | Is the select value clearable
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
73
|
+
| `isCondensed` | `boolean` | | | Use this property to reduce the paddings of the component for a ui compact variant |
|
|
74
|
+
| `isDisabled` | `AsyncCreatableProps['isDisabled']` | | | Is the select disabled
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
75
|
+
| `isReadOnly` | `boolean` | | | Is the select read-only |
|
|
76
|
+
| `isOptionDisabled` | `AsyncCreatableProps['isOptionDisabled']` | | | Override the built-in logic to detect whether an option is disabled
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
77
|
+
| `isMulti` | `AsyncCreatableProps['isMulti']` | | | Support multiple selected options
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
78
|
+
| `isSearchable` | `AsyncCreatableProps['isSearchable']` | | | Whether to enable search functionality
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
79
|
+
| `hasWarning` | `boolean` | | | Indicates the input field has a warning
@deprecated Please use the `warnings` prop instead so users know the reason why the field is in warning state. |
|
|
80
|
+
| `maxMenuHeight` | `AsyncCreatableProps['maxMenuHeight']` | | | Maximum height of the menu before scrolling
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
81
|
+
| `menuPortalTarget` | `AsyncCreatableProps['menuPortalTarget']` | | | Dom element to portal the select menu to
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
82
|
+
| `menuPortalZIndex` | `number` | | | z-index value for the menu portal
<br>
Use in conjunction with `menuPortalTarget` |
|
|
83
|
+
| `menuShouldBlockScroll` | `AsyncCreatableProps['menuShouldBlockScroll']` | | | whether the menu should block scroll while open
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
84
|
+
| `name` | `AsyncCreatableProps['name']` | | | Name of the HTML Input (optional - without this, no input will be rendered)
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
85
|
+
| `noOptionsMessage` | `AsyncCreatableProps['noOptionsMessage']` | | | 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).
<br/>
Gets called with `{ inputValue: String }`. `inputValue` will be an empty string when no search text is present.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
86
|
+
| `onBlur` | `Function`<br/>[See signature.](#signature-onblur) | | | Handle blur events on the control |
|
|
87
|
+
| `onChange` | `Function`<br/>[See signature.](#signature-onchange) | | | Called with a fake event when value changes.
<br />
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`.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
88
|
+
| `onFocus` | `AsyncCreatableProps['onFocus']` | | | Handle focus events on the control
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
89
|
+
| `onInputChange` | `AsyncCreatableProps['onInputChange']` | | | Handle change events on the input
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
90
|
+
| `placeholder` | `AsyncCreatableProps['placeholder']` | | | Placeholder text for the select value
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
91
|
+
| `tabIndex` | `AsyncCreatableProps['tabIndex']` | | | Sets the tabIndex attribute on the input
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
92
|
+
| `tabSelectsValue` | `AsyncCreatableProps['tabSelectsValue']` | | | Select the currently focused option when the user presses tab
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
93
|
+
| `value` | `AsyncCreatableProps['value']` | | | The value of the select; reflected by the selected option
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
94
|
+
| `showOptionGroupDivider` | `boolean` | | | Determines if option groups will be separated by a divider |
|
|
95
|
+
| `defaultOptions` | `AsyncCreatableProps['defaultOptions']` | | | The default set of options to show before the user starts searching.
<br/>
When set to `true`, the results for `loadOptions('')` will be autoloaded.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
96
|
+
| `loadOptions` | `AsyncCreatableProps['loadOptions']` | ✅ | | Function that returns a promise, which is the set of options to be used once the promise resolves.
<br />
[Props from React select was used](https://react-select.com/props) |
|
|
97
|
+
| `cacheOptions` | `AsyncCreatableProps['cacheOptions']` | | | If cacheOptions is truthy, then the loaded data will be cached. The cache will remain until cacheOptions changes value.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
98
|
+
| `allowCreateWhileLoading` | `AsyncCreatableProps['allowCreateWhileLoading']` | | | 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.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
99
|
+
| `formatCreateLabel` | `AsyncCreatableProps['formatCreateLabel']` | | | Gets the label for the "create new ..." option in the menu. Is given the current input value.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
100
|
+
| `isValidNewOption` | `AsyncCreatableProps['isValidNewOption']` | | | Determines whether the "create new ..." option should be displayed based on the current input value, select value and options array.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
101
|
+
| `getNewOptionData` | `AsyncCreatableProps['getNewOptionData']` | | | Returns the data for the new option when it is created. Used to display the value, and is passed to onChange.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
102
|
+
| `onCreateOption` | `AsyncCreatableProps['onCreateOption']` | | | 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.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
103
|
+
| `createOptionPosition` | `AsyncCreatableProps['createOptionPosition']` | | | Sets the position of the createOption element in your options list.
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
104
|
+
| `title` | `union`<br/>Possible values:<br/>`string , ReactNode` | ✅ | | Title of the label |
|
|
105
|
+
| `hint` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | 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`. |
|
|
106
|
+
| `description` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Provides a description for the title. |
|
|
107
|
+
| `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-oninfobuttonclick) | | | Function called when info button is pressed.
<br />
Info button will only be visible when this prop is passed. |
|
|
108
|
+
| `hintIcon` | `ReactElement` | | | Icon to be displayed beside the hint text.
<br />
Will only get rendered when `hint` is passed as well. |
|
|
109
|
+
| `badge` | `ReactNode` | | | Badge to be displayed beside the label.
<br />
Might be used to display additional information about the content of the field (E.g verified email) |
|
|
110
|
+
| `iconLeft` | `ReactNode` | | | Icon to display on the left of the placeholder text and selected value. Has no effect when isMulti is enabled. |
|
|
111
|
+
|
|
112
|
+
## Signatures
|
|
113
|
+
|
|
114
|
+
### Signature `renderError`
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
(key: string, error?: boolean) => ReactNode;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Signature `renderWarning`
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
(key: string, warning?: boolean) => ReactNode;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Signature `onBlur`
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
(event: TCustomEvent) => void
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Signature `onChange`
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
(event: TCustomEvent, info: ActionMeta<unknown>) => void
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Signature `onInfoButtonClick`
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
() => void
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## `data-*` props
|
|
145
|
+
|
|
146
|
+
The component further forwards all `data-` attributes to the underlying `AsyncCreatableSelectInput` component.
|
|
147
|
+
|
|
148
|
+
This input is built on top of [`react-select`](https://github.com/JedWatson/react-select) v2.
|
|
149
|
+
It supports mostly same properties as `react-select`. Behaviour for some props was changed, and support for others was dropped.
|
|
150
|
+
|
|
151
|
+
In case you need one of the currently excluded props, feel free to open a PR adding them.
|
|
152
|
+
|
|
153
|
+
## `errors`
|
|
154
|
+
|
|
155
|
+
This object is a key-value map. The `renderError` prop will be called for each entry with the key and the value. The return value will be rendered inside an `ErrorMessage` component underneath the input.
|
|
156
|
+
|
|
157
|
+
The `AsyncCreatableSelectField` supports some errors out of the box. Return `undefined` from `renderError` for these and the default errors will be shown instead. This prevents consumers from having to reimplement the same error messages for known errors while still keeping the flexibility of showing custom error messages for them.
|
|
158
|
+
|
|
159
|
+
When the `key` is known, and when the value is truthy, and when `renderError` returned `undefined` for that error entry, then the `AsyncCreatableSelectField` will render an appropriate error automatically.
|
|
160
|
+
|
|
161
|
+
Known error keys are:
|
|
162
|
+
|
|
163
|
+
- `missing`: tells the user that this field is required
|
|
164
|
+
|
|
165
|
+
## Static methods
|
|
166
|
+
|
|
167
|
+
### `AsyncCreatableSelectField.toFieldErrors`
|
|
168
|
+
|
|
169
|
+
Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
type FormValues = {
|
|
173
|
+
myField: string;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
<AsyncCreatableSelectField
|
|
177
|
+
// ...
|
|
178
|
+
name="my-field"
|
|
179
|
+
errors={
|
|
180
|
+
AsyncCreatableSelectField.toFieldErrors<FormValues>(formik.errors).myField
|
|
181
|
+
}
|
|
182
|
+
/>;
|
|
183
|
+
```
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from "./declarations/src/index.js";
|
|
2
|
+
export { default } from "./declarations/src/index.js";
|
|
3
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC1hc3luYy1jcmVhdGFibGUtc2VsZWN0LWZpZWxkLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|
|
@@ -0,0 +1,228 @@
|
|
|
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 _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
18
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
19
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
20
|
+
var _pt = require('prop-types');
|
|
21
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
22
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
23
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
24
|
+
var react = require('react');
|
|
25
|
+
var utils = require('@commercetools-uikit/utils');
|
|
26
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
27
|
+
var Spacings = require('@commercetools-uikit/spacings');
|
|
28
|
+
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
29
|
+
var AsyncCreatableSelectInput = require('@commercetools-uikit/async-creatable-select-input');
|
|
30
|
+
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
31
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
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 _pt__default = /*#__PURE__*/_interopDefault(_pt);
|
|
46
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
47
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
48
|
+
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
49
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
50
|
+
var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
51
|
+
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
52
|
+
var AsyncCreatableSelectInput__default = /*#__PURE__*/_interopDefault(AsyncCreatableSelectInput);
|
|
53
|
+
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
54
|
+
var FieldWarnings__default = /*#__PURE__*/_interopDefault(FieldWarnings);
|
|
55
|
+
|
|
56
|
+
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; }
|
|
57
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
58
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
59
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
60
|
+
const sequentialId = utils.createSequentialId('async-creatable-select-field-');
|
|
61
|
+
const hasErrors = errors => {
|
|
62
|
+
var _context;
|
|
63
|
+
return errors && _someInstanceProperty__default["default"](_context = _Object$values__default["default"](errors)).call(_context, Boolean);
|
|
64
|
+
};
|
|
65
|
+
const hasWarnings = warnings => {
|
|
66
|
+
var _context2;
|
|
67
|
+
return warnings && _someInstanceProperty__default["default"](_context2 = _Object$values__default["default"](warnings)).call(_context2, Boolean);
|
|
68
|
+
};
|
|
69
|
+
let AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
|
|
70
|
+
function AsyncCreatableSelectField() {
|
|
71
|
+
var _this;
|
|
72
|
+
_classCallCheck(this, AsyncCreatableSelectField);
|
|
73
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
74
|
+
args[_key] = arguments[_key];
|
|
75
|
+
}
|
|
76
|
+
_this = _callSuper(this, AsyncCreatableSelectField, [...args]);
|
|
77
|
+
_this.state = {
|
|
78
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
79
|
+
// label to the input component.
|
|
80
|
+
id: _this.props.id
|
|
81
|
+
};
|
|
82
|
+
return _this;
|
|
83
|
+
}
|
|
84
|
+
_inherits(AsyncCreatableSelectField, _Component);
|
|
85
|
+
return _createClass(AsyncCreatableSelectField, [{
|
|
86
|
+
key: "render",
|
|
87
|
+
value: function render() {
|
|
88
|
+
const hasError = AsyncCreatableSelectInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
89
|
+
const hasWarning = this.props.hasWarning || AsyncCreatableSelectInput__default["default"].isTouched(this.props.touched) && hasWarnings(this.props.warnings);
|
|
90
|
+
if (!this.props.isReadOnly) {
|
|
91
|
+
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'AsyncCreatableSelectField: `onChange` is required when field is not read only.') : void 0;
|
|
92
|
+
}
|
|
93
|
+
if (this.props.hintIcon) {
|
|
94
|
+
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.hint === 'string' || /*#__PURE__*/react.isValidElement(this.props.hint), 'AsyncCreatableSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
95
|
+
}
|
|
96
|
+
if (this.props.isMulti) {
|
|
97
|
+
process.env.NODE_ENV !== "production" ? utils.warning(_Array$isArray__default["default"](this.props.value), 'AsyncCreatableSelectField: `value` is expected to be an array of string when isMulti is true') : void 0;
|
|
98
|
+
process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.touched === 'undefined' || _Array$isArray__default["default"](this.props.touched), 'AsyncCreatableSelectField: `touched` is expected to be an array of boolean when isMulti is true') : void 0;
|
|
99
|
+
}
|
|
100
|
+
const errorsContainerId = `${this.state.id}-errors`;
|
|
101
|
+
const warningsContainerId = `${this.state.id}-warnings`;
|
|
102
|
+
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
103
|
+
max: this.props.horizontalConstraint,
|
|
104
|
+
children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
|
|
105
|
+
scale: "xs",
|
|
106
|
+
children: [jsxRuntime.jsx(FieldLabel__default["default"], {
|
|
107
|
+
title: this.props.title,
|
|
108
|
+
hint: this.props.hint,
|
|
109
|
+
description: this.props.description,
|
|
110
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
111
|
+
hintIcon: this.props.hintIcon,
|
|
112
|
+
badge: this.props.badge,
|
|
113
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
114
|
+
htmlFor: this.state.id
|
|
115
|
+
}), jsxRuntime.jsx(AsyncCreatableSelectInput__default["default"], _objectSpread({
|
|
116
|
+
horizontalConstraint: "scale",
|
|
117
|
+
hasError: hasError,
|
|
118
|
+
"aria-label": this.props['aria-label'],
|
|
119
|
+
"aria-labelledby": this.props['aria-labelledby'],
|
|
120
|
+
"aria-invalid": hasError,
|
|
121
|
+
"aria-errormessage": errorsContainerId,
|
|
122
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
123
|
+
backspaceRemovesValue: this.props.backspaceRemovesValue,
|
|
124
|
+
components: this.props.components,
|
|
125
|
+
filterOption: this.props.filterOption,
|
|
126
|
+
id: this.state.id,
|
|
127
|
+
containerId: this.props.containerId,
|
|
128
|
+
isClearable: this.props.isClearable,
|
|
129
|
+
isDisabled: this.props.isDisabled,
|
|
130
|
+
isReadOnly: this.props.isReadOnly,
|
|
131
|
+
isOptionDisabled: this.props.isOptionDisabled,
|
|
132
|
+
isMulti: this.props.isMulti,
|
|
133
|
+
isSearchable: this.props.isSearchable,
|
|
134
|
+
hasWarning: hasWarning,
|
|
135
|
+
maxMenuHeight: this.props.maxMenuHeight,
|
|
136
|
+
menuPortalTarget: this.props.menuPortalTarget,
|
|
137
|
+
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
138
|
+
menuShouldBlockScroll: this.props.menuShouldBlockScroll,
|
|
139
|
+
name: this.props.name,
|
|
140
|
+
noOptionsMessage: this.props.noOptionsMessage,
|
|
141
|
+
onBlur: this.props.onBlur,
|
|
142
|
+
onChange: this.props.onChange,
|
|
143
|
+
onFocus: this.props.onFocus,
|
|
144
|
+
onInputChange: this.props.onInputChange,
|
|
145
|
+
placeholder: this.props.placeholder,
|
|
146
|
+
tabIndex: this.props.tabIndex,
|
|
147
|
+
tabSelectsValue: this.props.tabSelectsValue,
|
|
148
|
+
value: this.props.value
|
|
149
|
+
// Async react-select props
|
|
150
|
+
,
|
|
151
|
+
defaultOptions: this.props.defaultOptions,
|
|
152
|
+
loadOptions: this.props.loadOptions,
|
|
153
|
+
cacheOptions: this.props.cacheOptions
|
|
154
|
+
// Creatable props
|
|
155
|
+
,
|
|
156
|
+
allowCreateWhileLoading: this.props.allowCreateWhileLoading,
|
|
157
|
+
formatCreateLabel: this.props.formatCreateLabel,
|
|
158
|
+
isValidNewOption: this.props.isValidNewOption,
|
|
159
|
+
getNewOptionData: this.props.getNewOptionData,
|
|
160
|
+
onCreateOption: this.props.onCreateOption,
|
|
161
|
+
createOptionPosition: this.props.createOptionPosition,
|
|
162
|
+
showOptionGroupDivider: this.props.showOptionGroupDivider,
|
|
163
|
+
iconLeft: this.props.iconLeft,
|
|
164
|
+
isCondensed: this.props.isCondensed
|
|
165
|
+
}, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default["default"], {
|
|
166
|
+
id: errorsContainerId,
|
|
167
|
+
errors: this.props.errors,
|
|
168
|
+
isVisible: hasError,
|
|
169
|
+
renderError: this.props.renderError
|
|
170
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
171
|
+
id: warningsContainerId,
|
|
172
|
+
warnings: this.props.warnings,
|
|
173
|
+
isVisible: hasWarning,
|
|
174
|
+
renderWarning: this.props.renderWarning
|
|
175
|
+
})]
|
|
176
|
+
})
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}], [{
|
|
180
|
+
key: "toFieldErrors",
|
|
181
|
+
value:
|
|
182
|
+
/**
|
|
183
|
+
* Use this function to convert the Formik `errors` object type to
|
|
184
|
+
* our custom field errors type.
|
|
185
|
+
* This is primarly useful when using TypeScript.
|
|
186
|
+
*/
|
|
187
|
+
function toFieldErrors(errors) {
|
|
188
|
+
return errors;
|
|
189
|
+
}
|
|
190
|
+
}]);
|
|
191
|
+
}(react.Component);
|
|
192
|
+
AsyncCreatableSelectField.displayName = 'AsyncCreatableSelectField';
|
|
193
|
+
AsyncCreatableSelectField.defaultProps = {
|
|
194
|
+
horizontalConstraint: 'scale'
|
|
195
|
+
};
|
|
196
|
+
AsyncCreatableSelectField.getDerivedStateFromProps = (props, state) => ({
|
|
197
|
+
id: utils.getFieldId(props, state, sequentialId)
|
|
198
|
+
});
|
|
199
|
+
AsyncCreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
200
|
+
horizontalConstraint: _pt__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
201
|
+
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
202
|
+
renderError: _pt__default["default"].func,
|
|
203
|
+
warnings: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
204
|
+
renderWarning: _pt__default["default"].func,
|
|
205
|
+
isRequired: _pt__default["default"].bool,
|
|
206
|
+
touched: _pt__default["default"].oneOfType([_pt__default["default"].arrayOf(_pt__default["default"].bool), _pt__default["default"].bool]),
|
|
207
|
+
isAutofocussed: _pt__default["default"].bool,
|
|
208
|
+
isCondensed: _pt__default["default"].bool,
|
|
209
|
+
isReadOnly: _pt__default["default"].bool,
|
|
210
|
+
hasWarning: _pt__default["default"].bool,
|
|
211
|
+
menuPortalZIndex: _pt__default["default"].number,
|
|
212
|
+
onBlur: _pt__default["default"].func,
|
|
213
|
+
onChange: _pt__default["default"].func,
|
|
214
|
+
showOptionGroupDivider: _pt__default["default"].bool,
|
|
215
|
+
title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
|
|
216
|
+
hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
217
|
+
description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
|
|
218
|
+
onInfoButtonClick: _pt__default["default"].func,
|
|
219
|
+
hintIcon: _pt__default["default"].element,
|
|
220
|
+
badge: _pt__default["default"].node,
|
|
221
|
+
iconLeft: _pt__default["default"].node
|
|
222
|
+
} : {};
|
|
223
|
+
|
|
224
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
225
|
+
var version = "19.25.1";
|
|
226
|
+
|
|
227
|
+
exports["default"] = AsyncCreatableSelectField;
|
|
228
|
+
exports.version = version;
|
|
@@ -0,0 +1,196 @@
|
|
|
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 _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
18
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
19
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
20
|
+
require('prop-types');
|
|
21
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
22
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
23
|
+
require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
24
|
+
var react = require('react');
|
|
25
|
+
var utils = require('@commercetools-uikit/utils');
|
|
26
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
27
|
+
var Spacings = require('@commercetools-uikit/spacings');
|
|
28
|
+
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
29
|
+
var AsyncCreatableSelectInput = require('@commercetools-uikit/async-creatable-select-input');
|
|
30
|
+
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
31
|
+
var FieldWarnings = require('@commercetools-uikit/field-warnings');
|
|
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 Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
48
|
+
var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
49
|
+
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
50
|
+
var AsyncCreatableSelectInput__default = /*#__PURE__*/_interopDefault(AsyncCreatableSelectInput);
|
|
51
|
+
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
52
|
+
var FieldWarnings__default = /*#__PURE__*/_interopDefault(FieldWarnings);
|
|
53
|
+
|
|
54
|
+
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; }
|
|
55
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
56
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
57
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
58
|
+
const sequentialId = utils.createSequentialId('async-creatable-select-field-');
|
|
59
|
+
const hasErrors = errors => {
|
|
60
|
+
var _context;
|
|
61
|
+
return errors && _someInstanceProperty__default["default"](_context = _Object$values__default["default"](errors)).call(_context, Boolean);
|
|
62
|
+
};
|
|
63
|
+
const hasWarnings = warnings => {
|
|
64
|
+
var _context2;
|
|
65
|
+
return warnings && _someInstanceProperty__default["default"](_context2 = _Object$values__default["default"](warnings)).call(_context2, Boolean);
|
|
66
|
+
};
|
|
67
|
+
let AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
|
|
68
|
+
function AsyncCreatableSelectField() {
|
|
69
|
+
var _this;
|
|
70
|
+
_classCallCheck(this, AsyncCreatableSelectField);
|
|
71
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
72
|
+
args[_key] = arguments[_key];
|
|
73
|
+
}
|
|
74
|
+
_this = _callSuper(this, AsyncCreatableSelectField, [...args]);
|
|
75
|
+
_this.state = {
|
|
76
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
77
|
+
// label to the input component.
|
|
78
|
+
id: _this.props.id
|
|
79
|
+
};
|
|
80
|
+
return _this;
|
|
81
|
+
}
|
|
82
|
+
_inherits(AsyncCreatableSelectField, _Component);
|
|
83
|
+
return _createClass(AsyncCreatableSelectField, [{
|
|
84
|
+
key: "render",
|
|
85
|
+
value: function render() {
|
|
86
|
+
const hasError = AsyncCreatableSelectInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
87
|
+
const hasWarning = this.props.hasWarning || AsyncCreatableSelectInput__default["default"].isTouched(this.props.touched) && hasWarnings(this.props.warnings);
|
|
88
|
+
if (!this.props.isReadOnly) ;
|
|
89
|
+
if (this.props.hintIcon) ;
|
|
90
|
+
if (this.props.isMulti) ;
|
|
91
|
+
const errorsContainerId = `${this.state.id}-errors`;
|
|
92
|
+
const warningsContainerId = `${this.state.id}-warnings`;
|
|
93
|
+
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
94
|
+
max: this.props.horizontalConstraint,
|
|
95
|
+
children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
|
|
96
|
+
scale: "xs",
|
|
97
|
+
children: [jsxRuntime.jsx(FieldLabel__default["default"], {
|
|
98
|
+
title: this.props.title,
|
|
99
|
+
hint: this.props.hint,
|
|
100
|
+
description: this.props.description,
|
|
101
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
102
|
+
hintIcon: this.props.hintIcon,
|
|
103
|
+
badge: this.props.badge,
|
|
104
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
105
|
+
htmlFor: this.state.id
|
|
106
|
+
}), jsxRuntime.jsx(AsyncCreatableSelectInput__default["default"], _objectSpread({
|
|
107
|
+
horizontalConstraint: "scale",
|
|
108
|
+
hasError: hasError,
|
|
109
|
+
"aria-label": this.props['aria-label'],
|
|
110
|
+
"aria-labelledby": this.props['aria-labelledby'],
|
|
111
|
+
"aria-invalid": hasError,
|
|
112
|
+
"aria-errormessage": errorsContainerId,
|
|
113
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
114
|
+
backspaceRemovesValue: this.props.backspaceRemovesValue,
|
|
115
|
+
components: this.props.components,
|
|
116
|
+
filterOption: this.props.filterOption,
|
|
117
|
+
id: this.state.id,
|
|
118
|
+
containerId: this.props.containerId,
|
|
119
|
+
isClearable: this.props.isClearable,
|
|
120
|
+
isDisabled: this.props.isDisabled,
|
|
121
|
+
isReadOnly: this.props.isReadOnly,
|
|
122
|
+
isOptionDisabled: this.props.isOptionDisabled,
|
|
123
|
+
isMulti: this.props.isMulti,
|
|
124
|
+
isSearchable: this.props.isSearchable,
|
|
125
|
+
hasWarning: hasWarning,
|
|
126
|
+
maxMenuHeight: this.props.maxMenuHeight,
|
|
127
|
+
menuPortalTarget: this.props.menuPortalTarget,
|
|
128
|
+
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
129
|
+
menuShouldBlockScroll: this.props.menuShouldBlockScroll,
|
|
130
|
+
name: this.props.name,
|
|
131
|
+
noOptionsMessage: this.props.noOptionsMessage,
|
|
132
|
+
onBlur: this.props.onBlur,
|
|
133
|
+
onChange: this.props.onChange,
|
|
134
|
+
onFocus: this.props.onFocus,
|
|
135
|
+
onInputChange: this.props.onInputChange,
|
|
136
|
+
placeholder: this.props.placeholder,
|
|
137
|
+
tabIndex: this.props.tabIndex,
|
|
138
|
+
tabSelectsValue: this.props.tabSelectsValue,
|
|
139
|
+
value: this.props.value
|
|
140
|
+
// Async react-select props
|
|
141
|
+
,
|
|
142
|
+
defaultOptions: this.props.defaultOptions,
|
|
143
|
+
loadOptions: this.props.loadOptions,
|
|
144
|
+
cacheOptions: this.props.cacheOptions
|
|
145
|
+
// Creatable props
|
|
146
|
+
,
|
|
147
|
+
allowCreateWhileLoading: this.props.allowCreateWhileLoading,
|
|
148
|
+
formatCreateLabel: this.props.formatCreateLabel,
|
|
149
|
+
isValidNewOption: this.props.isValidNewOption,
|
|
150
|
+
getNewOptionData: this.props.getNewOptionData,
|
|
151
|
+
onCreateOption: this.props.onCreateOption,
|
|
152
|
+
createOptionPosition: this.props.createOptionPosition,
|
|
153
|
+
showOptionGroupDivider: this.props.showOptionGroupDivider,
|
|
154
|
+
iconLeft: this.props.iconLeft,
|
|
155
|
+
isCondensed: this.props.isCondensed
|
|
156
|
+
}, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default["default"], {
|
|
157
|
+
id: errorsContainerId,
|
|
158
|
+
errors: this.props.errors,
|
|
159
|
+
isVisible: hasError,
|
|
160
|
+
renderError: this.props.renderError
|
|
161
|
+
}), jsxRuntime.jsx(FieldWarnings__default["default"], {
|
|
162
|
+
id: warningsContainerId,
|
|
163
|
+
warnings: this.props.warnings,
|
|
164
|
+
isVisible: hasWarning,
|
|
165
|
+
renderWarning: this.props.renderWarning
|
|
166
|
+
})]
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}], [{
|
|
171
|
+
key: "toFieldErrors",
|
|
172
|
+
value:
|
|
173
|
+
/**
|
|
174
|
+
* Use this function to convert the Formik `errors` object type to
|
|
175
|
+
* our custom field errors type.
|
|
176
|
+
* This is primarly useful when using TypeScript.
|
|
177
|
+
*/
|
|
178
|
+
function toFieldErrors(errors) {
|
|
179
|
+
return errors;
|
|
180
|
+
}
|
|
181
|
+
}]);
|
|
182
|
+
}(react.Component);
|
|
183
|
+
AsyncCreatableSelectField.displayName = 'AsyncCreatableSelectField';
|
|
184
|
+
AsyncCreatableSelectField.defaultProps = {
|
|
185
|
+
horizontalConstraint: 'scale'
|
|
186
|
+
};
|
|
187
|
+
AsyncCreatableSelectField.getDerivedStateFromProps = (props, state) => ({
|
|
188
|
+
id: utils.getFieldId(props, state, sequentialId)
|
|
189
|
+
});
|
|
190
|
+
AsyncCreatableSelectField.propTypes = {};
|
|
191
|
+
|
|
192
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
193
|
+
var version = "19.25.1";
|
|
194
|
+
|
|
195
|
+
exports["default"] = AsyncCreatableSelectField;
|
|
196
|
+
exports.version = version;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import _Reflect$construct from '@babel/runtime-corejs3/core-js-stable/reflect/construct';
|
|
2
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
3
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
4
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
5
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
6
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
7
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
8
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
9
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
10
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
11
|
+
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
12
|
+
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
13
|
+
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
14
|
+
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
15
|
+
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
16
|
+
import _pt from 'prop-types';
|
|
17
|
+
import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
|
|
18
|
+
import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
|
|
19
|
+
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
20
|
+
import { isValidElement, Component } from 'react';
|
|
21
|
+
import { createSequentialId, warning, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
|
|
22
|
+
import Constraints from '@commercetools-uikit/constraints';
|
|
23
|
+
import Spacings from '@commercetools-uikit/spacings';
|
|
24
|
+
import FieldLabel from '@commercetools-uikit/field-label';
|
|
25
|
+
import AsyncCreatableSelectInput from '@commercetools-uikit/async-creatable-select-input';
|
|
26
|
+
import FieldErrors from '@commercetools-uikit/field-errors';
|
|
27
|
+
import FieldWarnings from '@commercetools-uikit/field-warnings';
|
|
28
|
+
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
32
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
33
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
34
|
+
const sequentialId = createSequentialId('async-creatable-select-field-');
|
|
35
|
+
const hasErrors = errors => {
|
|
36
|
+
var _context;
|
|
37
|
+
return errors && _someInstanceProperty(_context = _Object$values(errors)).call(_context, Boolean);
|
|
38
|
+
};
|
|
39
|
+
const hasWarnings = warnings => {
|
|
40
|
+
var _context2;
|
|
41
|
+
return warnings && _someInstanceProperty(_context2 = _Object$values(warnings)).call(_context2, Boolean);
|
|
42
|
+
};
|
|
43
|
+
let AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
|
|
44
|
+
function AsyncCreatableSelectField() {
|
|
45
|
+
var _this;
|
|
46
|
+
_classCallCheck(this, AsyncCreatableSelectField);
|
|
47
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
48
|
+
args[_key] = arguments[_key];
|
|
49
|
+
}
|
|
50
|
+
_this = _callSuper(this, AsyncCreatableSelectField, [...args]);
|
|
51
|
+
_this.state = {
|
|
52
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
53
|
+
// label to the input component.
|
|
54
|
+
id: _this.props.id
|
|
55
|
+
};
|
|
56
|
+
return _this;
|
|
57
|
+
}
|
|
58
|
+
_inherits(AsyncCreatableSelectField, _Component);
|
|
59
|
+
return _createClass(AsyncCreatableSelectField, [{
|
|
60
|
+
key: "render",
|
|
61
|
+
value: function render() {
|
|
62
|
+
const hasError = AsyncCreatableSelectInput.isTouched(this.props.touched) && hasErrors(this.props.errors);
|
|
63
|
+
const hasWarning = this.props.hasWarning || AsyncCreatableSelectInput.isTouched(this.props.touched) && hasWarnings(this.props.warnings);
|
|
64
|
+
if (!this.props.isReadOnly) {
|
|
65
|
+
process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'AsyncCreatableSelectField: `onChange` is required when field is not read only.') : void 0;
|
|
66
|
+
}
|
|
67
|
+
if (this.props.hintIcon) {
|
|
68
|
+
process.env.NODE_ENV !== "production" ? warning(typeof this.props.hint === 'string' || /*#__PURE__*/isValidElement(this.props.hint), 'AsyncCreatableSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
69
|
+
}
|
|
70
|
+
if (this.props.isMulti) {
|
|
71
|
+
process.env.NODE_ENV !== "production" ? warning(_Array$isArray(this.props.value), 'AsyncCreatableSelectField: `value` is expected to be an array of string when isMulti is true') : void 0;
|
|
72
|
+
process.env.NODE_ENV !== "production" ? warning(typeof this.props.touched === 'undefined' || _Array$isArray(this.props.touched), 'AsyncCreatableSelectField: `touched` is expected to be an array of boolean when isMulti is true') : void 0;
|
|
73
|
+
}
|
|
74
|
+
const errorsContainerId = `${this.state.id}-errors`;
|
|
75
|
+
const warningsContainerId = `${this.state.id}-warnings`;
|
|
76
|
+
return jsx(Constraints.Horizontal, {
|
|
77
|
+
max: this.props.horizontalConstraint,
|
|
78
|
+
children: jsxs(Spacings.Stack, {
|
|
79
|
+
scale: "xs",
|
|
80
|
+
children: [jsx(FieldLabel, {
|
|
81
|
+
title: this.props.title,
|
|
82
|
+
hint: this.props.hint,
|
|
83
|
+
description: this.props.description,
|
|
84
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
85
|
+
hintIcon: this.props.hintIcon,
|
|
86
|
+
badge: this.props.badge,
|
|
87
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
88
|
+
htmlFor: this.state.id
|
|
89
|
+
}), jsx(AsyncCreatableSelectInput, _objectSpread({
|
|
90
|
+
horizontalConstraint: "scale",
|
|
91
|
+
hasError: hasError,
|
|
92
|
+
"aria-label": this.props['aria-label'],
|
|
93
|
+
"aria-labelledby": this.props['aria-labelledby'],
|
|
94
|
+
"aria-invalid": hasError,
|
|
95
|
+
"aria-errormessage": errorsContainerId,
|
|
96
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
97
|
+
backspaceRemovesValue: this.props.backspaceRemovesValue,
|
|
98
|
+
components: this.props.components,
|
|
99
|
+
filterOption: this.props.filterOption,
|
|
100
|
+
id: this.state.id,
|
|
101
|
+
containerId: this.props.containerId,
|
|
102
|
+
isClearable: this.props.isClearable,
|
|
103
|
+
isDisabled: this.props.isDisabled,
|
|
104
|
+
isReadOnly: this.props.isReadOnly,
|
|
105
|
+
isOptionDisabled: this.props.isOptionDisabled,
|
|
106
|
+
isMulti: this.props.isMulti,
|
|
107
|
+
isSearchable: this.props.isSearchable,
|
|
108
|
+
hasWarning: hasWarning,
|
|
109
|
+
maxMenuHeight: this.props.maxMenuHeight,
|
|
110
|
+
menuPortalTarget: this.props.menuPortalTarget,
|
|
111
|
+
menuPortalZIndex: this.props.menuPortalZIndex,
|
|
112
|
+
menuShouldBlockScroll: this.props.menuShouldBlockScroll,
|
|
113
|
+
name: this.props.name,
|
|
114
|
+
noOptionsMessage: this.props.noOptionsMessage,
|
|
115
|
+
onBlur: this.props.onBlur,
|
|
116
|
+
onChange: this.props.onChange,
|
|
117
|
+
onFocus: this.props.onFocus,
|
|
118
|
+
onInputChange: this.props.onInputChange,
|
|
119
|
+
placeholder: this.props.placeholder,
|
|
120
|
+
tabIndex: this.props.tabIndex,
|
|
121
|
+
tabSelectsValue: this.props.tabSelectsValue,
|
|
122
|
+
value: this.props.value
|
|
123
|
+
// Async react-select props
|
|
124
|
+
,
|
|
125
|
+
defaultOptions: this.props.defaultOptions,
|
|
126
|
+
loadOptions: this.props.loadOptions,
|
|
127
|
+
cacheOptions: this.props.cacheOptions
|
|
128
|
+
// Creatable props
|
|
129
|
+
,
|
|
130
|
+
allowCreateWhileLoading: this.props.allowCreateWhileLoading,
|
|
131
|
+
formatCreateLabel: this.props.formatCreateLabel,
|
|
132
|
+
isValidNewOption: this.props.isValidNewOption,
|
|
133
|
+
getNewOptionData: this.props.getNewOptionData,
|
|
134
|
+
onCreateOption: this.props.onCreateOption,
|
|
135
|
+
createOptionPosition: this.props.createOptionPosition,
|
|
136
|
+
showOptionGroupDivider: this.props.showOptionGroupDivider,
|
|
137
|
+
iconLeft: this.props.iconLeft,
|
|
138
|
+
isCondensed: this.props.isCondensed
|
|
139
|
+
}, filterDataAttributes(this.props))), jsx(FieldErrors, {
|
|
140
|
+
id: errorsContainerId,
|
|
141
|
+
errors: this.props.errors,
|
|
142
|
+
isVisible: hasError,
|
|
143
|
+
renderError: this.props.renderError
|
|
144
|
+
}), jsx(FieldWarnings, {
|
|
145
|
+
id: warningsContainerId,
|
|
146
|
+
warnings: this.props.warnings,
|
|
147
|
+
isVisible: hasWarning,
|
|
148
|
+
renderWarning: this.props.renderWarning
|
|
149
|
+
})]
|
|
150
|
+
})
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}], [{
|
|
154
|
+
key: "toFieldErrors",
|
|
155
|
+
value:
|
|
156
|
+
/**
|
|
157
|
+
* Use this function to convert the Formik `errors` object type to
|
|
158
|
+
* our custom field errors type.
|
|
159
|
+
* This is primarly useful when using TypeScript.
|
|
160
|
+
*/
|
|
161
|
+
function toFieldErrors(errors) {
|
|
162
|
+
return errors;
|
|
163
|
+
}
|
|
164
|
+
}]);
|
|
165
|
+
}(Component);
|
|
166
|
+
AsyncCreatableSelectField.displayName = 'AsyncCreatableSelectField';
|
|
167
|
+
AsyncCreatableSelectField.defaultProps = {
|
|
168
|
+
horizontalConstraint: 'scale'
|
|
169
|
+
};
|
|
170
|
+
AsyncCreatableSelectField.getDerivedStateFromProps = (props, state) => ({
|
|
171
|
+
id: getFieldId(props, state, sequentialId)
|
|
172
|
+
});
|
|
173
|
+
AsyncCreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
174
|
+
horizontalConstraint: _pt.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
175
|
+
errors: _pt.objectOf(_pt.bool),
|
|
176
|
+
renderError: _pt.func,
|
|
177
|
+
warnings: _pt.objectOf(_pt.bool),
|
|
178
|
+
renderWarning: _pt.func,
|
|
179
|
+
isRequired: _pt.bool,
|
|
180
|
+
touched: _pt.oneOfType([_pt.arrayOf(_pt.bool), _pt.bool]),
|
|
181
|
+
isAutofocussed: _pt.bool,
|
|
182
|
+
isCondensed: _pt.bool,
|
|
183
|
+
isReadOnly: _pt.bool,
|
|
184
|
+
hasWarning: _pt.bool,
|
|
185
|
+
menuPortalZIndex: _pt.number,
|
|
186
|
+
onBlur: _pt.func,
|
|
187
|
+
onChange: _pt.func,
|
|
188
|
+
showOptionGroupDivider: _pt.bool,
|
|
189
|
+
title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
|
|
190
|
+
hint: _pt.oneOfType([_pt.string, _pt.node]),
|
|
191
|
+
description: _pt.oneOfType([_pt.string, _pt.node]),
|
|
192
|
+
onInfoButtonClick: _pt.func,
|
|
193
|
+
hintIcon: _pt.element,
|
|
194
|
+
badge: _pt.node,
|
|
195
|
+
iconLeft: _pt.node
|
|
196
|
+
} : {};
|
|
197
|
+
|
|
198
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
199
|
+
var version = "19.25.1";
|
|
200
|
+
|
|
201
|
+
export { AsyncCreatableSelectField as default, version };
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { Component, type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import type { GroupBase, ActionMeta } from 'react-select';
|
|
3
|
+
import type { AsyncCreatableProps } from 'react-select/async-creatable';
|
|
4
|
+
type ReactSelectAsyncCreatableProps = AsyncCreatableProps<unknown, boolean, GroupBase<unknown>>;
|
|
5
|
+
type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
|
|
6
|
+
type TFieldErrors = Record<string, boolean>;
|
|
7
|
+
type TFieldWarnings = Record<string, boolean>;
|
|
8
|
+
type TCustomFormErrors<Values> = {
|
|
9
|
+
[K in keyof Values]?: TFieldErrors;
|
|
10
|
+
};
|
|
11
|
+
type TCustomEvent = {
|
|
12
|
+
target: {
|
|
13
|
+
id?: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
value?: unknown;
|
|
16
|
+
};
|
|
17
|
+
persist: () => void;
|
|
18
|
+
};
|
|
19
|
+
export type TAsyncCreatableSelectFieldProps = {
|
|
20
|
+
/**
|
|
21
|
+
* Used as HTML id property. An id is auto-generated when it is not specified.
|
|
22
|
+
* <br>
|
|
23
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
24
|
+
*/
|
|
25
|
+
id?: ReactSelectAsyncCreatableProps['inputId'];
|
|
26
|
+
/**
|
|
27
|
+
* Horizontal size limit of the input fields.
|
|
28
|
+
*/
|
|
29
|
+
horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
30
|
+
/**
|
|
31
|
+
* A map of errors. Error messages for known errors are rendered automatically.
|
|
32
|
+
* <br />
|
|
33
|
+
* Unknown errors will be forwarded to `renderError`
|
|
34
|
+
*/
|
|
35
|
+
errors?: TFieldErrors;
|
|
36
|
+
/**
|
|
37
|
+
* 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.
|
|
38
|
+
*/
|
|
39
|
+
renderError?: TErrorRenderer;
|
|
40
|
+
/**
|
|
41
|
+
* A map of warnings. Warning messages for known warnings are rendered automatically.
|
|
42
|
+
* <br />
|
|
43
|
+
* Unknown warnings will be forwarded to `renderWarning`
|
|
44
|
+
*/
|
|
45
|
+
warnings?: TFieldWarnings;
|
|
46
|
+
/**
|
|
47
|
+
* Called with custom warnings. This function can return a message which will be wrapped in an WarningMessage. It can also return null to show no warning.
|
|
48
|
+
*/
|
|
49
|
+
renderWarning?: (key: string, warning?: boolean) => ReactNode;
|
|
50
|
+
/**
|
|
51
|
+
* Indicates if the value is required. Shows an the "required asterisk" if so.
|
|
52
|
+
*/
|
|
53
|
+
isRequired?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Indicates whether the field was touched. Errors will only be shown when the field was touched.
|
|
56
|
+
*/
|
|
57
|
+
touched?: boolean[] | boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Aria label (for assistive tech)
|
|
60
|
+
* <br>
|
|
61
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
62
|
+
*/
|
|
63
|
+
'aria-label'?: ReactSelectAsyncCreatableProps['aria-label'];
|
|
64
|
+
/**
|
|
65
|
+
* HTML ID of an element that should be used as the label (for assistive tech)
|
|
66
|
+
* <br>
|
|
67
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
68
|
+
*/
|
|
69
|
+
'aria-labelledby'?: ReactSelectAsyncCreatableProps['aria-labelledby'];
|
|
70
|
+
/**
|
|
71
|
+
* Focus the control when it is mounted
|
|
72
|
+
*/
|
|
73
|
+
isAutofocussed?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Remove the currently focused option when the user presses backspace
|
|
76
|
+
* <br>
|
|
77
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
78
|
+
*/
|
|
79
|
+
backspaceRemovesValue?: ReactSelectAsyncCreatableProps['backspaceRemovesValue'];
|
|
80
|
+
/**
|
|
81
|
+
* Map of components to overwrite the default ones, see [what components you can override](https://react-select.com/components)
|
|
82
|
+
* <br>
|
|
83
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
84
|
+
*/
|
|
85
|
+
components?: ReactSelectAsyncCreatableProps['components'];
|
|
86
|
+
/**
|
|
87
|
+
* Custom method to filter whether an option should be displayed in the menu
|
|
88
|
+
* <br>
|
|
89
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
90
|
+
*/
|
|
91
|
+
filterOption?: ReactSelectAsyncCreatableProps['filterOption'];
|
|
92
|
+
/**
|
|
93
|
+
* The id to set on the SelectContainer component
|
|
94
|
+
* <br>
|
|
95
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
96
|
+
*/
|
|
97
|
+
containerId?: ReactSelectAsyncCreatableProps['id'];
|
|
98
|
+
/**
|
|
99
|
+
* Is the select value clearable
|
|
100
|
+
* <br>
|
|
101
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
102
|
+
*/
|
|
103
|
+
isClearable?: ReactSelectAsyncCreatableProps['isClearable'];
|
|
104
|
+
/**
|
|
105
|
+
* Use this property to reduce the paddings of the component for a ui compact variant
|
|
106
|
+
*/
|
|
107
|
+
isCondensed?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Is the select disabled
|
|
110
|
+
* <br>
|
|
111
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
112
|
+
*/
|
|
113
|
+
isDisabled?: ReactSelectAsyncCreatableProps['isDisabled'];
|
|
114
|
+
/**
|
|
115
|
+
* Is the select read-only
|
|
116
|
+
*/
|
|
117
|
+
isReadOnly?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Override the built-in logic to detect whether an option is disabled
|
|
120
|
+
* <br>
|
|
121
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
122
|
+
*/
|
|
123
|
+
isOptionDisabled?: ReactSelectAsyncCreatableProps['isOptionDisabled'];
|
|
124
|
+
/**
|
|
125
|
+
* Support multiple selected options
|
|
126
|
+
* <br>
|
|
127
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
128
|
+
*/
|
|
129
|
+
isMulti?: ReactSelectAsyncCreatableProps['isMulti'];
|
|
130
|
+
/**
|
|
131
|
+
* Whether to enable search functionality
|
|
132
|
+
* <br>
|
|
133
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
134
|
+
*/
|
|
135
|
+
isSearchable?: ReactSelectAsyncCreatableProps['isSearchable'];
|
|
136
|
+
/**
|
|
137
|
+
* Indicates the input field has a warning
|
|
138
|
+
* @deprecated Please use the `warnings` prop instead so users know the reason why the field is in warning state.
|
|
139
|
+
*/
|
|
140
|
+
hasWarning?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Maximum height of the menu before scrolling
|
|
143
|
+
* <br>
|
|
144
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
145
|
+
*/
|
|
146
|
+
maxMenuHeight?: ReactSelectAsyncCreatableProps['maxMenuHeight'];
|
|
147
|
+
/**
|
|
148
|
+
* Dom element to portal the select menu to
|
|
149
|
+
* <br>
|
|
150
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
151
|
+
*/
|
|
152
|
+
menuPortalTarget?: ReactSelectAsyncCreatableProps['menuPortalTarget'];
|
|
153
|
+
/**
|
|
154
|
+
* z-index value for the menu portal
|
|
155
|
+
* <br>
|
|
156
|
+
* Use in conjunction with `menuPortalTarget`
|
|
157
|
+
*/
|
|
158
|
+
menuPortalZIndex?: number;
|
|
159
|
+
/**
|
|
160
|
+
* whether the menu should block scroll while open
|
|
161
|
+
* <br>
|
|
162
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
163
|
+
*/
|
|
164
|
+
menuShouldBlockScroll?: ReactSelectAsyncCreatableProps['menuShouldBlockScroll'];
|
|
165
|
+
/**
|
|
166
|
+
* Name of the HTML Input (optional - without this, no input will be rendered)
|
|
167
|
+
* <br>
|
|
168
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
169
|
+
*/
|
|
170
|
+
name?: ReactSelectAsyncCreatableProps['name'];
|
|
171
|
+
/**
|
|
172
|
+
* 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).
|
|
173
|
+
* <br/>
|
|
174
|
+
* Gets called with `{ inputValue: String }`. `inputValue` will be an empty string when no search text is present.
|
|
175
|
+
* <br>
|
|
176
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
177
|
+
*/
|
|
178
|
+
noOptionsMessage?: ReactSelectAsyncCreatableProps['noOptionsMessage'];
|
|
179
|
+
/**
|
|
180
|
+
* Handle blur events on the control
|
|
181
|
+
*/
|
|
182
|
+
onBlur?: (event: TCustomEvent) => void;
|
|
183
|
+
/**
|
|
184
|
+
* Called with a fake event when value changes.
|
|
185
|
+
* <br />
|
|
186
|
+
* 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`.
|
|
187
|
+
* <br>
|
|
188
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
189
|
+
*/
|
|
190
|
+
onChange?: (event: TCustomEvent, info: ActionMeta<unknown>) => void;
|
|
191
|
+
/**
|
|
192
|
+
* Handle focus events on the control
|
|
193
|
+
* <br>
|
|
194
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
195
|
+
*/
|
|
196
|
+
onFocus?: ReactSelectAsyncCreatableProps['onFocus'];
|
|
197
|
+
/**
|
|
198
|
+
* Handle change events on the input
|
|
199
|
+
* <br>
|
|
200
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
201
|
+
*/
|
|
202
|
+
onInputChange?: ReactSelectAsyncCreatableProps['onInputChange'];
|
|
203
|
+
/**
|
|
204
|
+
* Placeholder text for the select value
|
|
205
|
+
* <br>
|
|
206
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
207
|
+
*/
|
|
208
|
+
placeholder?: ReactSelectAsyncCreatableProps['placeholder'];
|
|
209
|
+
/**
|
|
210
|
+
* Sets the tabIndex attribute on the input
|
|
211
|
+
* <br>
|
|
212
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
213
|
+
*/
|
|
214
|
+
tabIndex?: ReactSelectAsyncCreatableProps['tabIndex'];
|
|
215
|
+
/**
|
|
216
|
+
* Select the currently focused option when the user presses tab
|
|
217
|
+
* <br>
|
|
218
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
219
|
+
*/
|
|
220
|
+
tabSelectsValue?: ReactSelectAsyncCreatableProps['tabSelectsValue'];
|
|
221
|
+
/**
|
|
222
|
+
* The value of the select; reflected by the selected option
|
|
223
|
+
* <br>
|
|
224
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
225
|
+
*/
|
|
226
|
+
value?: ReactSelectAsyncCreatableProps['value'];
|
|
227
|
+
/**
|
|
228
|
+
* Determines if option groups will be separated by a divider
|
|
229
|
+
*/
|
|
230
|
+
showOptionGroupDivider?: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* The default set of options to show before the user starts searching.
|
|
233
|
+
* <br/>
|
|
234
|
+
* When set to `true`, the results for `loadOptions('')` will be autoloaded.
|
|
235
|
+
* <br>
|
|
236
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
237
|
+
*/
|
|
238
|
+
defaultOptions?: ReactSelectAsyncCreatableProps['defaultOptions'];
|
|
239
|
+
/**
|
|
240
|
+
* Function that returns a promise, which is the set of options to be used once the promise resolves.
|
|
241
|
+
* <br />
|
|
242
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
243
|
+
*/
|
|
244
|
+
loadOptions: ReactSelectAsyncCreatableProps['loadOptions'];
|
|
245
|
+
/**
|
|
246
|
+
* If cacheOptions is truthy, then the loaded data will be cached. The cache will remain until cacheOptions changes value.
|
|
247
|
+
* <br>
|
|
248
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
249
|
+
*/
|
|
250
|
+
cacheOptions?: ReactSelectAsyncCreatableProps['cacheOptions'];
|
|
251
|
+
/**
|
|
252
|
+
* 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.
|
|
253
|
+
* <br>
|
|
254
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
255
|
+
*/
|
|
256
|
+
allowCreateWhileLoading?: ReactSelectAsyncCreatableProps['allowCreateWhileLoading'];
|
|
257
|
+
/**
|
|
258
|
+
* Gets the label for the "create new ..." option in the menu. Is given the current input value.
|
|
259
|
+
* <br>
|
|
260
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
261
|
+
*/
|
|
262
|
+
formatCreateLabel?: ReactSelectAsyncCreatableProps['formatCreateLabel'];
|
|
263
|
+
/**
|
|
264
|
+
* Determines whether the "create new ..." option should be displayed based on the current input value, select value and options array.
|
|
265
|
+
* <br>
|
|
266
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
267
|
+
*/
|
|
268
|
+
isValidNewOption?: ReactSelectAsyncCreatableProps['isValidNewOption'];
|
|
269
|
+
/**
|
|
270
|
+
* Returns the data for the new option when it is created. Used to display the value, and is passed to onChange.
|
|
271
|
+
* <br>
|
|
272
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
273
|
+
*/
|
|
274
|
+
getNewOptionData?: ReactSelectAsyncCreatableProps['getNewOptionData'];
|
|
275
|
+
/**
|
|
276
|
+
* 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.
|
|
277
|
+
* <br>
|
|
278
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
279
|
+
*/
|
|
280
|
+
onCreateOption?: ReactSelectAsyncCreatableProps['onCreateOption'];
|
|
281
|
+
/**
|
|
282
|
+
* Sets the position of the createOption element in your options list.
|
|
283
|
+
* <br>
|
|
284
|
+
* [Props from React select was used](https://react-select.com/props)
|
|
285
|
+
*/
|
|
286
|
+
createOptionPosition?: ReactSelectAsyncCreatableProps['createOptionPosition'];
|
|
287
|
+
/**
|
|
288
|
+
* Title of the label
|
|
289
|
+
*/
|
|
290
|
+
title: string | ReactNode;
|
|
291
|
+
/**
|
|
292
|
+
* 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`.
|
|
293
|
+
*/
|
|
294
|
+
hint?: string | ReactNode;
|
|
295
|
+
/**
|
|
296
|
+
* Provides a description for the title.
|
|
297
|
+
*/
|
|
298
|
+
description?: string | ReactNode;
|
|
299
|
+
/**
|
|
300
|
+
* Function called when info button is pressed.
|
|
301
|
+
* <br />
|
|
302
|
+
* Info button will only be visible when this prop is passed.
|
|
303
|
+
*/
|
|
304
|
+
onInfoButtonClick?: () => void;
|
|
305
|
+
/**
|
|
306
|
+
* Icon to be displayed beside the hint text.
|
|
307
|
+
* <br />
|
|
308
|
+
* Will only get rendered when `hint` is passed as well.
|
|
309
|
+
*/
|
|
310
|
+
hintIcon?: ReactElement;
|
|
311
|
+
/**
|
|
312
|
+
* Badge to be displayed beside the label.
|
|
313
|
+
* <br />
|
|
314
|
+
* Might be used to display additional information about the content of the field (E.g verified email)
|
|
315
|
+
*/
|
|
316
|
+
badge?: ReactNode;
|
|
317
|
+
/**
|
|
318
|
+
* Icon to display on the left of the placeholder text and selected value. Has no effect when isMulti is enabled.
|
|
319
|
+
*/
|
|
320
|
+
iconLeft?: ReactNode;
|
|
321
|
+
};
|
|
322
|
+
type TAsyncCreatableSelectFieldState = Pick<TAsyncCreatableSelectFieldProps, 'id'>;
|
|
323
|
+
export default class AsyncCreatableSelectField extends Component<TAsyncCreatableSelectFieldProps, TAsyncCreatableSelectFieldState> {
|
|
324
|
+
static displayName: string;
|
|
325
|
+
static defaultProps: Pick<TAsyncCreatableSelectFieldProps, 'horizontalConstraint'>;
|
|
326
|
+
state: {
|
|
327
|
+
id: string | undefined;
|
|
328
|
+
};
|
|
329
|
+
static getDerivedStateFromProps: (props: TAsyncCreatableSelectFieldProps, state: TAsyncCreatableSelectFieldState) => {
|
|
330
|
+
id: string;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Use this function to convert the Formik `errors` object type to
|
|
334
|
+
* our custom field errors type.
|
|
335
|
+
* This is primarly useful when using TypeScript.
|
|
336
|
+
*/
|
|
337
|
+
static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
|
|
338
|
+
render(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
339
|
+
}
|
|
340
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { TAsyncCreatableSelectFieldProps } from "./async-creatable-select-field.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools-uikit/async-creatable-select-field",
|
|
3
|
+
"description": "An input component with validation states and a label getting a selection from an asynchronously loaded list from the user, and where options can be created by the user.",
|
|
4
|
+
"version": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
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/fields/async-creatable-select-field"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://uikit.commercetools.com",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"javascript",
|
|
14
|
+
"typescript",
|
|
15
|
+
"design-system",
|
|
16
|
+
"react",
|
|
17
|
+
"uikit"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "dist/commercetools-uikit-async-creatable-select-field.cjs.js",
|
|
25
|
+
"module": "dist/commercetools-uikit-async-creatable-select-field.esm.js",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@babel/runtime": "^7.20.13",
|
|
31
|
+
"@babel/runtime-corejs3": "^7.20.13",
|
|
32
|
+
"@commercetools-uikit/async-creatable-select-input": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
33
|
+
"@commercetools-uikit/constraints": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
34
|
+
"@commercetools-uikit/design-system": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
35
|
+
"@commercetools-uikit/field-errors": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
36
|
+
"@commercetools-uikit/field-label": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
37
|
+
"@commercetools-uikit/field-warnings": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
38
|
+
"@commercetools-uikit/spacings": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
39
|
+
"@commercetools-uikit/utils": "0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339",
|
|
40
|
+
"@emotion/react": "^11.10.5",
|
|
41
|
+
"@emotion/styled": "^11.10.5",
|
|
42
|
+
"prop-types": "15.8.1",
|
|
43
|
+
"react-intl": "^6.3.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"react": "17.0.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": "17.x"
|
|
50
|
+
}
|
|
51
|
+
}
|