@commercetools-uikit/search-select-field 13.0.4 → 14.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/dist/commercetools-uikit-search-select-field.cjs.dev.js +18 -3
- package/dist/commercetools-uikit-search-select-field.cjs.prod.js +15 -2
- package/dist/commercetools-uikit-search-select-field.esm.js +18 -3
- package/dist/declarations/src/search-select-field.d.ts +10 -5
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ export default Example;
|
|
|
111
111
|
| `menuShouldBlockScroll` | `boolean` | | | whether the menu should block scroll while open |
|
|
112
112
|
| `showOptionGroupDivider` | `boolean` | | | Determines if option groups will be separated by a divider |
|
|
113
113
|
| `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Handle blur events on the control |
|
|
114
|
-
| `onChange` | `Function`<br/>[See signature.](#signature-onChange) |
|
|
114
|
+
| `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`. |
|
|
115
115
|
| `onFocus` | `AsyncProps['onFocus']` | | | Handle focus events on the control
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
116
116
|
| `onInputChange` | `AsyncProps['onInputChange']` | | | Handle change events on the input
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
117
117
|
| `tabSelectsValue` | `AsyncProps['tabSelectsValue']` | | | Select the currently focused option when the user presses tab
<br>
[Props from React select was used](https://react-select.com/props) |
|
|
@@ -136,13 +136,13 @@ export default Example;
|
|
|
136
136
|
### Signature `onBlur`
|
|
137
137
|
|
|
138
138
|
```ts
|
|
139
|
-
(event:
|
|
139
|
+
(event: TCustomEvent) => void
|
|
140
140
|
```
|
|
141
141
|
|
|
142
142
|
### Signature `onChange`
|
|
143
143
|
|
|
144
144
|
```ts
|
|
145
|
-
(event:
|
|
145
|
+
(event: TCustomEvent, info: ActionMeta<unknown>) => void
|
|
146
146
|
```
|
|
147
147
|
|
|
148
148
|
### Signature `renderError`
|
|
@@ -178,3 +178,21 @@ When the `key` is known, and when the value is truthy, and when `renderError` re
|
|
|
178
178
|
Known error keys are:
|
|
179
179
|
|
|
180
180
|
- `missing`: tells the user that this field is required
|
|
181
|
+
|
|
182
|
+
## Static methods
|
|
183
|
+
|
|
184
|
+
### `SearchSelectField.toFieldErrors`
|
|
185
|
+
|
|
186
|
+
Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
type FormValues = {
|
|
190
|
+
myField: string;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
<SearchSelectField
|
|
194
|
+
// ...
|
|
195
|
+
name="my-field"
|
|
196
|
+
errors={SearchSelectField.toFieldErrors<FormValues>(formik.errors).myField}
|
|
197
|
+
/>;
|
|
198
|
+
```
|
|
@@ -18,6 +18,7 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/obje
|
|
|
18
18
|
var react = require('react');
|
|
19
19
|
var utils = require('@commercetools-uikit/utils');
|
|
20
20
|
var Constraints = require('@commercetools-uikit/constraints');
|
|
21
|
+
var hooks = require('@commercetools-uikit/hooks');
|
|
21
22
|
var Spacings = require('@commercetools-uikit/spacings');
|
|
22
23
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
23
24
|
var SearchSelectInput = require('@commercetools-uikit/search-select-input');
|
|
@@ -59,7 +60,11 @@ var sequentialErrorsId = utils.createSequentialId('search-select-field-error-')(
|
|
|
59
60
|
|
|
60
61
|
var SearchSelectField = function SearchSelectField(props) {
|
|
61
62
|
var hasError = Boolean(props.touched) && hasErrors(props.errors);
|
|
62
|
-
var id = props.id
|
|
63
|
+
var id = hooks.useFieldId(props.id, sequentialId);
|
|
64
|
+
|
|
65
|
+
if (!props.isReadOnly) {
|
|
66
|
+
process.env.NODE_ENV !== "production" ? utils.warning(typeof props.onChange === 'function', 'SearchSelectField: `onChange` is required when field is not read only.') : void 0;
|
|
67
|
+
}
|
|
63
68
|
|
|
64
69
|
if (props.hintIcon) {
|
|
65
70
|
process.env.NODE_ENV !== "production" ? utils.warning(typeof props.hint === 'string' || /*#__PURE__*/react.isValidElement(props.hint), 'SearchSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
@@ -144,7 +149,7 @@ SearchSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
144
149
|
menuShouldBlockScroll: _pt__default["default"].bool,
|
|
145
150
|
showOptionGroupDivider: _pt__default["default"].bool,
|
|
146
151
|
onBlur: _pt__default["default"].func,
|
|
147
|
-
onChange: _pt__default["default"].func
|
|
152
|
+
onChange: _pt__default["default"].func,
|
|
148
153
|
loadingMessage: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].func]),
|
|
149
154
|
optionType: _pt__default["default"].oneOf(['single-property', 'double-property', 'multiple-properties']),
|
|
150
155
|
errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
|
|
@@ -159,10 +164,20 @@ SearchSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
159
164
|
badge: _pt__default["default"].node
|
|
160
165
|
} : {};
|
|
161
166
|
SearchSelectField.displayName = 'SearchSelectField';
|
|
167
|
+
/**
|
|
168
|
+
* Use this function to convert the Formik `errors` object type to
|
|
169
|
+
* our custom field errors type.
|
|
170
|
+
* This is primarly useful when using TypeScript.
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
SearchSelectField.toFieldErrors = function toFieldErrors(errors) {
|
|
174
|
+
return errors;
|
|
175
|
+
};
|
|
176
|
+
|
|
162
177
|
var SearchSelectField$1 = SearchSelectField;
|
|
163
178
|
|
|
164
179
|
// NOTE: This string will be replaced on build time with the package version.
|
|
165
|
-
var version = "
|
|
180
|
+
var version = "14.0.2";
|
|
166
181
|
|
|
167
182
|
exports["default"] = SearchSelectField$1;
|
|
168
183
|
exports.version = version;
|
|
@@ -18,6 +18,7 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/obje
|
|
|
18
18
|
require('react');
|
|
19
19
|
var utils = require('@commercetools-uikit/utils');
|
|
20
20
|
var Constraints = require('@commercetools-uikit/constraints');
|
|
21
|
+
var hooks = require('@commercetools-uikit/hooks');
|
|
21
22
|
var Spacings = require('@commercetools-uikit/spacings');
|
|
22
23
|
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
23
24
|
var SearchSelectInput = require('@commercetools-uikit/search-select-input');
|
|
@@ -57,7 +58,9 @@ var sequentialErrorsId = utils.createSequentialId('search-select-field-error-')(
|
|
|
57
58
|
|
|
58
59
|
var SearchSelectField = function SearchSelectField(props) {
|
|
59
60
|
var hasError = Boolean(props.touched) && hasErrors(props.errors);
|
|
60
|
-
var id = props.id
|
|
61
|
+
var id = hooks.useFieldId(props.id, sequentialId);
|
|
62
|
+
|
|
63
|
+
if (!props.isReadOnly) ;
|
|
61
64
|
|
|
62
65
|
if (props.hintIcon) ;
|
|
63
66
|
|
|
@@ -127,10 +130,20 @@ var SearchSelectField = function SearchSelectField(props) {
|
|
|
127
130
|
|
|
128
131
|
SearchSelectField.propTypes = {};
|
|
129
132
|
SearchSelectField.displayName = 'SearchSelectField';
|
|
133
|
+
/**
|
|
134
|
+
* Use this function to convert the Formik `errors` object type to
|
|
135
|
+
* our custom field errors type.
|
|
136
|
+
* This is primarly useful when using TypeScript.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
SearchSelectField.toFieldErrors = function toFieldErrors(errors) {
|
|
140
|
+
return errors;
|
|
141
|
+
};
|
|
142
|
+
|
|
130
143
|
var SearchSelectField$1 = SearchSelectField;
|
|
131
144
|
|
|
132
145
|
// NOTE: This string will be replaced on build time with the package version.
|
|
133
|
-
var version = "
|
|
146
|
+
var version = "14.0.2";
|
|
134
147
|
|
|
135
148
|
exports["default"] = SearchSelectField$1;
|
|
136
149
|
exports.version = version;
|
|
@@ -14,6 +14,7 @@ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object
|
|
|
14
14
|
import { isValidElement } from 'react';
|
|
15
15
|
import { createSequentialId, warning, filterDataAttributes } from '@commercetools-uikit/utils';
|
|
16
16
|
import Constraints from '@commercetools-uikit/constraints';
|
|
17
|
+
import { useFieldId } from '@commercetools-uikit/hooks';
|
|
17
18
|
import Spacings from '@commercetools-uikit/spacings';
|
|
18
19
|
import FieldLabel from '@commercetools-uikit/field-label';
|
|
19
20
|
import SearchSelectInput from '@commercetools-uikit/search-select-input';
|
|
@@ -35,7 +36,11 @@ var sequentialErrorsId = createSequentialId('search-select-field-error-')();
|
|
|
35
36
|
|
|
36
37
|
var SearchSelectField = function SearchSelectField(props) {
|
|
37
38
|
var hasError = Boolean(props.touched) && hasErrors(props.errors);
|
|
38
|
-
var id = props.id
|
|
39
|
+
var id = useFieldId(props.id, sequentialId);
|
|
40
|
+
|
|
41
|
+
if (!props.isReadOnly) {
|
|
42
|
+
process.env.NODE_ENV !== "production" ? warning(typeof props.onChange === 'function', 'SearchSelectField: `onChange` is required when field is not read only.') : void 0;
|
|
43
|
+
}
|
|
39
44
|
|
|
40
45
|
if (props.hintIcon) {
|
|
41
46
|
process.env.NODE_ENV !== "production" ? warning(typeof props.hint === 'string' || /*#__PURE__*/isValidElement(props.hint), 'SearchSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
|
|
@@ -120,7 +125,7 @@ SearchSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
120
125
|
menuShouldBlockScroll: _pt.bool,
|
|
121
126
|
showOptionGroupDivider: _pt.bool,
|
|
122
127
|
onBlur: _pt.func,
|
|
123
|
-
onChange: _pt.func
|
|
128
|
+
onChange: _pt.func,
|
|
124
129
|
loadingMessage: _pt.oneOfType([_pt.string, _pt.func]),
|
|
125
130
|
optionType: _pt.oneOf(['single-property', 'double-property', 'multiple-properties']),
|
|
126
131
|
errors: _pt.objectOf(_pt.bool),
|
|
@@ -135,9 +140,19 @@ SearchSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
135
140
|
badge: _pt.node
|
|
136
141
|
} : {};
|
|
137
142
|
SearchSelectField.displayName = 'SearchSelectField';
|
|
143
|
+
/**
|
|
144
|
+
* Use this function to convert the Formik `errors` object type to
|
|
145
|
+
* our custom field errors type.
|
|
146
|
+
* This is primarly useful when using TypeScript.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
SearchSelectField.toFieldErrors = function toFieldErrors(errors) {
|
|
150
|
+
return errors;
|
|
151
|
+
};
|
|
152
|
+
|
|
138
153
|
var SearchSelectField$1 = SearchSelectField;
|
|
139
154
|
|
|
140
155
|
// NOTE: This string will be replaced on build time with the package version.
|
|
141
|
-
var version = "
|
|
156
|
+
var version = "14.0.2";
|
|
142
157
|
|
|
143
158
|
export { SearchSelectField$1 as default, version };
|
|
@@ -2,15 +2,19 @@ import { type ReactNode, type MouseEvent, type KeyboardEvent, type ReactElement
|
|
|
2
2
|
import type { ActionMeta, GroupBase } from 'react-select';
|
|
3
3
|
import type { AsyncProps } from 'react-select/async';
|
|
4
4
|
declare type ReactSelectAsyncProps = AsyncProps<unknown, boolean, GroupBase<unknown>>;
|
|
5
|
-
declare type
|
|
5
|
+
declare type TCustomEvent = {
|
|
6
6
|
target: {
|
|
7
|
-
|
|
7
|
+
id?: ReactSelectAsyncProps['inputId'];
|
|
8
|
+
name?: ReactSelectAsyncProps['name'];
|
|
8
9
|
value?: unknown;
|
|
9
10
|
};
|
|
10
11
|
persist: () => void;
|
|
11
12
|
};
|
|
12
|
-
declare type TFieldErrors = Record<string, boolean>;
|
|
13
13
|
declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
|
|
14
|
+
declare type TFieldErrors = Record<string, boolean>;
|
|
15
|
+
declare type TCustomFormErrors<Values> = {
|
|
16
|
+
[K in keyof Values]?: TFieldErrors;
|
|
17
|
+
};
|
|
14
18
|
declare type TSearchSelectFieldProps = {
|
|
15
19
|
horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
|
|
16
20
|
'aria-label'?: ReactSelectAsyncProps['aria-label'];
|
|
@@ -37,8 +41,8 @@ declare type TSearchSelectFieldProps = {
|
|
|
37
41
|
menuPortalZIndex?: number;
|
|
38
42
|
menuShouldBlockScroll?: boolean;
|
|
39
43
|
showOptionGroupDivider?: boolean;
|
|
40
|
-
onBlur?: (event:
|
|
41
|
-
onChange
|
|
44
|
+
onBlur?: (event: TCustomEvent) => void;
|
|
45
|
+
onChange?: (event: TCustomEvent, info: ActionMeta<unknown>) => void;
|
|
42
46
|
onFocus?: ReactSelectAsyncProps['onFocus'];
|
|
43
47
|
onInputChange?: ReactSelectAsyncProps['onInputChange'];
|
|
44
48
|
tabSelectsValue?: ReactSelectAsyncProps['tabSelectsValue'];
|
|
@@ -61,5 +65,6 @@ declare type TSearchSelectFieldProps = {
|
|
|
61
65
|
declare const SearchSelectField: {
|
|
62
66
|
(props: TSearchSelectFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
63
67
|
displayName: string;
|
|
68
|
+
toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
|
|
64
69
|
};
|
|
65
70
|
export default SearchSelectField;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/search-select-field",
|
|
3
3
|
"description": "A search select field built on top of search select input, allowing users to asynchronously search for options",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "14.0.2",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"directory": "packages/components/fields/search-select-field"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://uikit.commercetools.com",
|
|
12
|
-
"keywords": ["javascript", "design
|
|
12
|
+
"keywords": ["javascript", "typescript", "design-system", "react", "uikit"],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
@@ -19,15 +19,16 @@
|
|
|
19
19
|
"module": "dist/commercetools-uikit-search-select-field.esm.js",
|
|
20
20
|
"files": ["dist"],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@babel/runtime": "7.17.2",
|
|
23
|
-
"@babel/runtime-corejs3": "7.17.2",
|
|
24
|
-
"@commercetools-uikit/constraints": "
|
|
25
|
-
"@commercetools-uikit/design-system": "
|
|
26
|
-
"@commercetools-uikit/field-errors": "
|
|
27
|
-
"@commercetools-uikit/field-label": "
|
|
28
|
-
"@commercetools-uikit/
|
|
29
|
-
"@commercetools-uikit/
|
|
30
|
-
"@commercetools-uikit/
|
|
22
|
+
"@babel/runtime": "^7.17.2",
|
|
23
|
+
"@babel/runtime-corejs3": "^7.17.2",
|
|
24
|
+
"@commercetools-uikit/constraints": "14.0.1",
|
|
25
|
+
"@commercetools-uikit/design-system": "14.0.0",
|
|
26
|
+
"@commercetools-uikit/field-errors": "14.0.1",
|
|
27
|
+
"@commercetools-uikit/field-label": "14.0.2",
|
|
28
|
+
"@commercetools-uikit/hooks": "14.0.1",
|
|
29
|
+
"@commercetools-uikit/search-select-input": "14.0.2",
|
|
30
|
+
"@commercetools-uikit/spacings": "14.0.1",
|
|
31
|
+
"@commercetools-uikit/utils": "14.0.1",
|
|
31
32
|
"@emotion/react": "^11.4.0",
|
|
32
33
|
"@emotion/styled": "^11.3.0",
|
|
33
34
|
"prop-types": "15.8.1",
|