@commercetools-uikit/async-creatable-select-field 14.0.0 → 14.0.6

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 CHANGED
@@ -81,7 +81,7 @@ export default Example;
81
81
  | `name` | `AsyncCreatableProps['name']` | | | Name of the HTML Input (optional - without this, no input will be rendered)&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
82
82
  | `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).&#xA;<br/>&#xA;Gets called with `{ inputValue: String }`. `inputValue` will be an empty string when no search text is present.&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
83
83
  | `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Handle blur events on the control |
84
- | `onChange` | `Function`<br/>[See signature.](#signature-onChange) || | Called with a fake event when value changes.&#xA;<br />&#xA;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`.&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
84
+ | `onChange` | `Function`<br/>[See signature.](#signature-onChange) | | | Called with a fake event when value changes.&#xA;<br />&#xA;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`.&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
85
85
  | `onFocus` | `AsyncCreatableProps['onFocus']` | | | Handle focus events on the control&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
86
86
  | `onInputChange` | `AsyncCreatableProps['onInputChange']` | | | Handle change events on the input&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
87
87
  | `placeholder` | `AsyncCreatableProps['placeholder']` | | | Placeholder text for the select value&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
@@ -117,13 +117,13 @@ export default Example;
117
117
  ### Signature `onBlur`
118
118
 
119
119
  ```ts
120
- (event: TEvent) => void
120
+ (event: TCustomEvent) => void
121
121
  ```
122
122
 
123
123
  ### Signature `onChange`
124
124
 
125
125
  ```ts
126
- (event: TEvent, info: ActionMeta<unknown>) => void
126
+ (event: TCustomEvent, info: ActionMeta<unknown>) => void
127
127
  ```
128
128
 
129
129
  ### Signature `onInfoButtonClick`
@@ -152,3 +152,23 @@ When the `key` is known, and when the value is truthy, and when `renderError` re
152
152
  Known error keys are:
153
153
 
154
154
  - `missing`: tells the user that this field is required
155
+
156
+ ## Static methods
157
+
158
+ ### `AsyncCreatableSelectField.toFieldErrors`
159
+
160
+ Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
161
+
162
+ ```ts
163
+ type FormValues = {
164
+ myField: string;
165
+ };
166
+
167
+ <AsyncCreatableSelectField
168
+ // ...
169
+ name="my-field"
170
+ errors={
171
+ AsyncCreatableSelectField.toFieldErrors<FormValues>(formik.errors).myField
172
+ }
173
+ />;
174
+ ```
@@ -99,13 +99,17 @@ var AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
99
99
  value: function render() {
100
100
  var hasError = AsyncCreatableSelectInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
101
101
 
102
+ if (!this.props.isReadOnly) {
103
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'AsyncCreatableSelectField: `onChange` is required when field is not read only.') : void 0;
104
+ }
105
+
102
106
  if (this.props.hintIcon) {
103
107
  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;
104
108
  }
105
109
 
106
110
  if (this.props.isMulti) {
107
111
  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;
108
- process.env.NODE_ENV !== "production" ? utils.warning(_Array$isArray__default["default"](this.props.touched), 'AsyncCreatableSelectField: `touched` is expected to be an array of boolean when isMulti is true') : void 0;
112
+ 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;
109
113
  }
110
114
 
111
115
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
@@ -177,6 +181,17 @@ var AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
177
181
  })
178
182
  });
179
183
  }
184
+ }], [{
185
+ key: "toFieldErrors",
186
+ value:
187
+ /**
188
+ * Use this function to convert the Formik `errors` object type to
189
+ * our custom field errors type.
190
+ * This is primarly useful when using TypeScript.
191
+ */
192
+ function toFieldErrors(errors) {
193
+ return errors;
194
+ }
180
195
  }]);
181
196
 
182
197
  return AsyncCreatableSelectField;
@@ -203,7 +218,7 @@ AsyncCreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
203
218
  hasWarning: _pt__default["default"].bool,
204
219
  menuPortalZIndex: _pt__default["default"].number,
205
220
  onBlur: _pt__default["default"].func,
206
- onChange: _pt__default["default"].func.isRequired,
221
+ onChange: _pt__default["default"].func,
207
222
  showOptionGroupDivider: _pt__default["default"].bool,
208
223
  title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
209
224
  hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
@@ -215,7 +230,7 @@ AsyncCreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
215
230
  } : {};
216
231
 
217
232
  // NOTE: This string will be replaced on build time with the package version.
218
- var version = "14.0.0";
233
+ var version = "14.0.6";
219
234
 
220
235
  exports["default"] = AsyncCreatableSelectField;
221
236
  exports.version = version;
@@ -97,6 +97,8 @@ var AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
97
97
  value: function render() {
98
98
  var hasError = AsyncCreatableSelectInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
99
99
 
100
+ if (!this.props.isReadOnly) ;
101
+
100
102
  if (this.props.hintIcon) ;
101
103
 
102
104
  if (this.props.isMulti) ;
@@ -170,6 +172,17 @@ var AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
170
172
  })
171
173
  });
172
174
  }
175
+ }], [{
176
+ key: "toFieldErrors",
177
+ value:
178
+ /**
179
+ * Use this function to convert the Formik `errors` object type to
180
+ * our custom field errors type.
181
+ * This is primarly useful when using TypeScript.
182
+ */
183
+ function toFieldErrors(errors) {
184
+ return errors;
185
+ }
173
186
  }]);
174
187
 
175
188
  return AsyncCreatableSelectField;
@@ -188,7 +201,7 @@ AsyncCreatableSelectField.getDerivedStateFromProps = function (props, state) {
188
201
  AsyncCreatableSelectField.propTypes = {};
189
202
 
190
203
  // NOTE: This string will be replaced on build time with the package version.
191
- var version = "14.0.0";
204
+ var version = "14.0.6";
192
205
 
193
206
  exports["default"] = AsyncCreatableSelectField;
194
207
  exports.version = version;
@@ -73,13 +73,17 @@ var AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
73
73
  value: function render() {
74
74
  var hasError = AsyncCreatableSelectInput.isTouched(this.props.touched) && hasErrors(this.props.errors);
75
75
 
76
+ if (!this.props.isReadOnly) {
77
+ process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'AsyncCreatableSelectField: `onChange` is required when field is not read only.') : void 0;
78
+ }
79
+
76
80
  if (this.props.hintIcon) {
77
81
  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;
78
82
  }
79
83
 
80
84
  if (this.props.isMulti) {
81
85
  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;
82
- process.env.NODE_ENV !== "production" ? warning(_Array$isArray(this.props.touched), 'AsyncCreatableSelectField: `touched` is expected to be an array of boolean when isMulti is true') : void 0;
86
+ 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;
83
87
  }
84
88
 
85
89
  return jsx(Constraints.Horizontal, {
@@ -151,6 +155,17 @@ var AsyncCreatableSelectField = /*#__PURE__*/function (_Component) {
151
155
  })
152
156
  });
153
157
  }
158
+ }], [{
159
+ key: "toFieldErrors",
160
+ value:
161
+ /**
162
+ * Use this function to convert the Formik `errors` object type to
163
+ * our custom field errors type.
164
+ * This is primarly useful when using TypeScript.
165
+ */
166
+ function toFieldErrors(errors) {
167
+ return errors;
168
+ }
154
169
  }]);
155
170
 
156
171
  return AsyncCreatableSelectField;
@@ -177,7 +192,7 @@ AsyncCreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
177
192
  hasWarning: _pt.bool,
178
193
  menuPortalZIndex: _pt.number,
179
194
  onBlur: _pt.func,
180
- onChange: _pt.func.isRequired,
195
+ onChange: _pt.func,
181
196
  showOptionGroupDivider: _pt.bool,
182
197
  title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
183
198
  hint: _pt.oneOfType([_pt.string, _pt.node]),
@@ -189,6 +204,6 @@ AsyncCreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
189
204
  } : {};
190
205
 
191
206
  // NOTE: This string will be replaced on build time with the package version.
192
- var version = "14.0.0";
207
+ var version = "14.0.6";
193
208
 
194
209
  export { AsyncCreatableSelectField as default, version };
@@ -2,10 +2,14 @@ import { Component, type ReactElement, type ReactNode } from 'react';
2
2
  import type { GroupBase, ActionMeta } from 'react-select';
3
3
  import type { AsyncCreatableProps } from 'react-select/async-creatable';
4
4
  declare type ReactSelectAsyncCreatableProps = AsyncCreatableProps<unknown, boolean, GroupBase<unknown>>;
5
- declare type TFieldErrors = Record<string, boolean>;
6
5
  declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
7
- declare type TEvent = {
6
+ declare type TFieldErrors = Record<string, boolean>;
7
+ declare type TCustomFormErrors<Values> = {
8
+ [K in keyof Values]?: TFieldErrors;
9
+ };
10
+ declare type TCustomEvent = {
8
11
  target: {
12
+ id?: string;
9
13
  name?: string;
10
14
  value?: unknown;
11
15
  };
@@ -38,8 +42,8 @@ declare type TAsyncCreatableSelectFieldProps = {
38
42
  menuShouldBlockScroll?: ReactSelectAsyncCreatableProps['menuShouldBlockScroll'];
39
43
  name?: ReactSelectAsyncCreatableProps['name'];
40
44
  noOptionsMessage?: ReactSelectAsyncCreatableProps['noOptionsMessage'];
41
- onBlur?: (event: TEvent) => void;
42
- onChange: (event: TEvent, info: ActionMeta<unknown>) => void;
45
+ onBlur?: (event: TCustomEvent) => void;
46
+ onChange?: (event: TCustomEvent, info: ActionMeta<unknown>) => void;
43
47
  onFocus?: ReactSelectAsyncCreatableProps['onFocus'];
44
48
  onInputChange?: ReactSelectAsyncCreatableProps['onInputChange'];
45
49
  placeholder?: ReactSelectAsyncCreatableProps['placeholder'];
@@ -74,6 +78,7 @@ export default class AsyncCreatableSelectField extends Component<TAsyncCreatable
74
78
  static getDerivedStateFromProps: (props: TAsyncCreatableSelectFieldProps, state: TAsyncCreatableSelectFieldState) => {
75
79
  id: string;
76
80
  };
81
+ static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
77
82
  render(): import("@emotion/react/jsx-runtime").JSX.Element;
78
83
  }
79
84
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/async-creatable-select-field",
3
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": "14.0.0",
4
+ "version": "14.0.6",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -21,13 +21,13 @@
21
21
  "dependencies": {
22
22
  "@babel/runtime": "^7.17.2",
23
23
  "@babel/runtime-corejs3": "^7.17.2",
24
- "@commercetools-uikit/async-creatable-select-input": "14.0.0",
25
- "@commercetools-uikit/constraints": "14.0.0",
24
+ "@commercetools-uikit/async-creatable-select-input": "14.0.6",
25
+ "@commercetools-uikit/constraints": "14.0.1",
26
26
  "@commercetools-uikit/design-system": "14.0.0",
27
- "@commercetools-uikit/field-errors": "14.0.0",
28
- "@commercetools-uikit/field-label": "14.0.0",
29
- "@commercetools-uikit/spacings": "14.0.0",
30
- "@commercetools-uikit/utils": "14.0.0",
27
+ "@commercetools-uikit/field-errors": "14.0.1",
28
+ "@commercetools-uikit/field-label": "14.0.6",
29
+ "@commercetools-uikit/spacings": "14.0.6",
30
+ "@commercetools-uikit/utils": "14.0.1",
31
31
  "@emotion/react": "^11.4.0",
32
32
  "@emotion/styled": "^11.3.0",
33
33
  "prop-types": "15.8.1",