@commercetools-uikit/async-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 CHANGED
@@ -79,7 +79,7 @@ export default Example;
79
79
  | `name` | `AsyncProps['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) |
80
80
  | `noOptionsMessage` | `AsyncProps['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;[Props from React select was used](https://react-select.com/props) |
81
81
  | `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Handle blur events on the control |
82
- | `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`. |
82
+ | `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`. |
83
83
  | `onFocus` | `FocusEventHandler` | | | Handle focus events on the control |
84
84
  | `onInputChange` | `AsyncProps['onInputChange']` | | | Handle change events on the input&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
85
85
  | `placeholder` | `AsyncProps['placeholder']` | | | Placeholder text for the select value&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
@@ -110,13 +110,13 @@ export default Example;
110
110
  ### Signature `onBlur`
111
111
 
112
112
  ```ts
113
- (event: TEvent) => void
113
+ (event: TCustomEvent) => void
114
114
  ```
115
115
 
116
116
  ### Signature `onChange`
117
117
 
118
118
  ```ts
119
- (event: TEvent, info: ActionMeta<unknown>) => void
119
+ (event: TCustomEvent, info: ActionMeta<unknown>) => void
120
120
  ```
121
121
 
122
122
  ### Signature `onInfoButtonClick`
@@ -145,3 +145,21 @@ When the `key` is known, and when the value is truthy, and when `renderError` re
145
145
  Known error keys are:
146
146
 
147
147
  - `missing`: tells the user that this field is required
148
+
149
+ ## Static methods
150
+
151
+ ### `AsyncSelectField.toFieldErrors`
152
+
153
+ Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
154
+
155
+ ```ts
156
+ type FormValues = {
157
+ myField: string;
158
+ };
159
+
160
+ <AsyncSelectField
161
+ // ...
162
+ name="my-field"
163
+ errors={AsyncSelectField.toFieldErrors<FormValues>(formik.errors).myField}
164
+ />;
165
+ ```
@@ -99,6 +99,10 @@ var AsyncSelectField = /*#__PURE__*/function (_Component) {
99
99
  value: function render() {
100
100
  var hasError = AsyncSelectInput__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', 'AsyncSelectField: `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), 'AsyncSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
104
108
  }
@@ -171,6 +175,17 @@ var AsyncSelectField = /*#__PURE__*/function (_Component) {
171
175
  })
172
176
  });
173
177
  }
178
+ }], [{
179
+ key: "toFieldErrors",
180
+ value:
181
+ /**
182
+ * Use this function to convert the Formik `errors` object type to
183
+ * our custom field errors type.
184
+ * This is primarly useful when using TypeScript.
185
+ */
186
+ function toFieldErrors(errors) {
187
+ return errors;
188
+ }
174
189
  }]);
175
190
 
176
191
  return AsyncSelectField;
@@ -197,7 +212,7 @@ AsyncSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
197
212
  hasWarning: _pt__default["default"].bool,
198
213
  menuPortalZIndex: _pt__default["default"].number,
199
214
  onBlur: _pt__default["default"].func,
200
- onChange: _pt__default["default"].func.isRequired,
215
+ onChange: _pt__default["default"].func,
201
216
  onFocus: _pt__default["default"].func,
202
217
  loadingMessage: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].func]),
203
218
  showOptionGroupDivider: _pt__default["default"].bool,
@@ -212,7 +227,7 @@ AsyncSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
212
227
  } : {};
213
228
 
214
229
  // NOTE: This string will be replaced on build time with the package version.
215
- var version = "13.0.4";
230
+ var version = "14.0.2";
216
231
 
217
232
  exports["default"] = AsyncSelectField;
218
233
  exports.version = version;
@@ -97,6 +97,8 @@ var AsyncSelectField = /*#__PURE__*/function (_Component) {
97
97
  value: function render() {
98
98
  var hasError = AsyncSelectInput__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) ;
@@ -164,6 +166,17 @@ var AsyncSelectField = /*#__PURE__*/function (_Component) {
164
166
  })
165
167
  });
166
168
  }
169
+ }], [{
170
+ key: "toFieldErrors",
171
+ value:
172
+ /**
173
+ * Use this function to convert the Formik `errors` object type to
174
+ * our custom field errors type.
175
+ * This is primarly useful when using TypeScript.
176
+ */
177
+ function toFieldErrors(errors) {
178
+ return errors;
179
+ }
167
180
  }]);
168
181
 
169
182
  return AsyncSelectField;
@@ -182,7 +195,7 @@ AsyncSelectField.getDerivedStateFromProps = function (props, state) {
182
195
  AsyncSelectField.propTypes = {};
183
196
 
184
197
  // NOTE: This string will be replaced on build time with the package version.
185
- var version = "13.0.4";
198
+ var version = "14.0.2";
186
199
 
187
200
  exports["default"] = AsyncSelectField;
188
201
  exports.version = version;
@@ -73,6 +73,10 @@ var AsyncSelectField = /*#__PURE__*/function (_Component) {
73
73
  value: function render() {
74
74
  var hasError = AsyncSelectInput.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', 'AsyncSelectField: `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), 'AsyncSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
78
82
  }
@@ -145,6 +149,17 @@ var AsyncSelectField = /*#__PURE__*/function (_Component) {
145
149
  })
146
150
  });
147
151
  }
152
+ }], [{
153
+ key: "toFieldErrors",
154
+ value:
155
+ /**
156
+ * Use this function to convert the Formik `errors` object type to
157
+ * our custom field errors type.
158
+ * This is primarly useful when using TypeScript.
159
+ */
160
+ function toFieldErrors(errors) {
161
+ return errors;
162
+ }
148
163
  }]);
149
164
 
150
165
  return AsyncSelectField;
@@ -171,7 +186,7 @@ AsyncSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
171
186
  hasWarning: _pt.bool,
172
187
  menuPortalZIndex: _pt.number,
173
188
  onBlur: _pt.func,
174
- onChange: _pt.func.isRequired,
189
+ onChange: _pt.func,
175
190
  onFocus: _pt.func,
176
191
  loadingMessage: _pt.oneOfType([_pt.string, _pt.func]),
177
192
  showOptionGroupDivider: _pt.bool,
@@ -186,6 +201,6 @@ AsyncSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
186
201
  } : {};
187
202
 
188
203
  // NOTE: This string will be replaced on build time with the package version.
189
- var version = "13.0.4";
204
+ var version = "14.0.2";
190
205
 
191
206
  export { AsyncSelectField as default, version };
@@ -4,9 +4,13 @@ import type { GroupBase, OptionsOrGroups, ActionMeta } from 'react-select';
4
4
  declare type ReactSelectAsyncProps = AsyncProps<unknown, boolean, GroupBase<unknown>>;
5
5
  declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
6
6
  declare type TFieldErrors = Record<string, boolean>;
7
- declare type TEvent = {
7
+ declare type TCustomFormErrors<Values> = {
8
+ [K in keyof Values]?: TFieldErrors;
9
+ };
10
+ declare type TCustomEvent = {
8
11
  target: {
9
- name?: string;
12
+ id?: ReactSelectAsyncProps['inputId'];
13
+ name?: ReactSelectAsyncProps['name'];
10
14
  value?: unknown;
11
15
  };
12
16
  persist: () => void;
@@ -38,8 +42,8 @@ declare type TAsyncSelectFieldProps = {
38
42
  menuShouldBlockScroll?: ReactSelectAsyncProps['menuShouldBlockScroll'];
39
43
  name?: ReactSelectAsyncProps['name'];
40
44
  noOptionsMessage?: ReactSelectAsyncProps['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?: FocusEventHandler;
44
48
  onInputChange?: ReactSelectAsyncProps['onInputChange'];
45
49
  placeholder?: ReactSelectAsyncProps['placeholder'];
@@ -69,6 +73,7 @@ export default class AsyncSelectField extends Component<TAsyncSelectFieldProps,
69
73
  static getDerivedStateFromProps: (props: TAsyncSelectFieldProps, state: TAsyncSelectFieldState) => {
70
74
  id: string;
71
75
  };
76
+ static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
72
77
  render(): import("@emotion/react/jsx-runtime").JSX.Element;
73
78
  }
74
79
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/async-select-field",
3
3
  "description": "A controlled input component with validation states and a label getting a selection from an asynchronously loaded list from the user.",
4
- "version": "13.0.4",
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/async-select-field"
10
10
  },
11
11
  "homepage": "https://uikit.commercetools.com",
12
- "keywords": ["javascript", "design system", "react", "uikit"],
12
+ "keywords": ["javascript", "typescript", "design-system", "react", "uikit"],
13
13
  "license": "MIT",
14
14
  "publishConfig": {
15
15
  "access": "public"
@@ -19,15 +19,15 @@
19
19
  "module": "dist/commercetools-uikit-async-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/async-select-input": "13.0.4",
25
- "@commercetools-uikit/constraints": "13.0.2",
26
- "@commercetools-uikit/design-system": "13.0.0",
27
- "@commercetools-uikit/field-errors": "13.0.4",
28
- "@commercetools-uikit/field-label": "13.0.4",
29
- "@commercetools-uikit/spacings": "13.0.2",
30
- "@commercetools-uikit/utils": "13.0.2",
22
+ "@babel/runtime": "^7.17.2",
23
+ "@babel/runtime-corejs3": "^7.17.2",
24
+ "@commercetools-uikit/async-select-input": "14.0.2",
25
+ "@commercetools-uikit/constraints": "14.0.1",
26
+ "@commercetools-uikit/design-system": "14.0.0",
27
+ "@commercetools-uikit/field-errors": "14.0.1",
28
+ "@commercetools-uikit/field-label": "14.0.2",
29
+ "@commercetools-uikit/spacings": "14.0.1",
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",