@commercetools-uikit/creatable-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
@@ -78,7 +78,7 @@ export default Example;
78
78
  | `name` | `CreatableProps['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#creatable-props) |
79
79
  | `noOptionsMessage` | `CreatableProps['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#creatable-props) |
80
80
  | `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Handle blur events on the control |
81
- | `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`. |
81
+ | `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
82
  | `onFocus` | `CreatableProps['onFocus']` | | | Handle focus events on the control&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props#creatable-props) |
83
83
  | `onInputChange` | `CreatableProps['onInputChange']` | | | Handle change events on the input&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props#creatable-props) |
84
84
  | `options` | `union`<br/>Possible values:<br/>`TValue[] , { options: TValue[] }[]` | | | Array of options that populate the select menu |
@@ -112,13 +112,13 @@ export default Example;
112
112
  ### Signature `onBlur`
113
113
 
114
114
  ```ts
115
- (event: TEvent) => void
115
+ (event: TCustomEvent) => void
116
116
  ```
117
117
 
118
118
  ### Signature `onChange`
119
119
 
120
120
  ```ts
121
- (event: TEvent, info: ActionMeta<unknown>) => void
121
+ (event: TCustomEvent, info: ActionMeta<unknown>) => void
122
122
  ```
123
123
 
124
124
  ### Signature `onInfoButtonClick`
@@ -147,3 +147,21 @@ When the `key` is known, and when the value is truthy, and when `renderError` re
147
147
  Known error keys are:
148
148
 
149
149
  - `missing`: tells the user that this field is required
150
+
151
+ ## Static methods
152
+
153
+ ### `CreatableSelectField.toFieldErrors`
154
+
155
+ Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
156
+
157
+ ```ts
158
+ type FormValues = {
159
+ myField: string;
160
+ };
161
+
162
+ <CreatableSelectField
163
+ // ...
164
+ name="my-field"
165
+ errors={CreatableSelectField.toFieldErrors<FormValues>(formik.errors).myField}
166
+ />;
167
+ ```
@@ -99,6 +99,10 @@ var CreatableSelectField = /*#__PURE__*/function (_Component) {
99
99
  value: function render() {
100
100
  var hasError = CreatableSelectInput__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', 'CreatableSelectField: `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), 'CreatableSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
104
108
  }
@@ -173,6 +177,17 @@ var CreatableSelectField = /*#__PURE__*/function (_Component) {
173
177
  })
174
178
  });
175
179
  }
180
+ }], [{
181
+ key: "toFieldErrors",
182
+ value:
183
+ /**
184
+ * Use this function to convert the Formik `errors` object type to
185
+ * our custom field errors type.
186
+ * This is primarly useful when using TypeScript.
187
+ */
188
+ function toFieldErrors(errors) {
189
+ return errors;
190
+ }
176
191
  }]);
177
192
 
178
193
  return CreatableSelectField;
@@ -199,7 +214,7 @@ CreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
199
214
  hasWarning: _pt__default["default"].bool,
200
215
  menuPortalZIndex: _pt__default["default"].number,
201
216
  onBlur: _pt__default["default"].func,
202
- onChange: _pt__default["default"].func.isRequired,
217
+ onChange: _pt__default["default"].func,
203
218
  options: _pt__default["default"].oneOfType([_pt__default["default"].arrayOf(_pt__default["default"].shape({
204
219
  value: _pt__default["default"].string.isRequired
205
220
  })), _pt__default["default"].arrayOf(_pt__default["default"].shape({
@@ -218,7 +233,7 @@ CreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
218
233
  } : {};
219
234
 
220
235
  // NOTE: This string will be replaced on build time with the package version.
221
- var version = "13.0.4";
236
+ var version = "14.0.2";
222
237
 
223
238
  exports["default"] = CreatableSelectField;
224
239
  exports.version = version;
@@ -97,6 +97,8 @@ var CreatableSelectField = /*#__PURE__*/function (_Component) {
97
97
  value: function render() {
98
98
  var hasError = CreatableSelectInput__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) ;
@@ -166,6 +168,17 @@ var CreatableSelectField = /*#__PURE__*/function (_Component) {
166
168
  })
167
169
  });
168
170
  }
171
+ }], [{
172
+ key: "toFieldErrors",
173
+ value:
174
+ /**
175
+ * Use this function to convert the Formik `errors` object type to
176
+ * our custom field errors type.
177
+ * This is primarly useful when using TypeScript.
178
+ */
179
+ function toFieldErrors(errors) {
180
+ return errors;
181
+ }
169
182
  }]);
170
183
 
171
184
  return CreatableSelectField;
@@ -184,7 +197,7 @@ CreatableSelectField.getDerivedStateFromProps = function (props, state) {
184
197
  CreatableSelectField.propTypes = {};
185
198
 
186
199
  // NOTE: This string will be replaced on build time with the package version.
187
- var version = "13.0.4";
200
+ var version = "14.0.2";
188
201
 
189
202
  exports["default"] = CreatableSelectField;
190
203
  exports.version = version;
@@ -73,6 +73,10 @@ var CreatableSelectField = /*#__PURE__*/function (_Component) {
73
73
  value: function render() {
74
74
  var hasError = CreatableSelectInput.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', 'CreatableSelectField: `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), 'CreatableSelectField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
78
82
  }
@@ -147,6 +151,17 @@ var CreatableSelectField = /*#__PURE__*/function (_Component) {
147
151
  })
148
152
  });
149
153
  }
154
+ }], [{
155
+ key: "toFieldErrors",
156
+ value:
157
+ /**
158
+ * Use this function to convert the Formik `errors` object type to
159
+ * our custom field errors type.
160
+ * This is primarly useful when using TypeScript.
161
+ */
162
+ function toFieldErrors(errors) {
163
+ return errors;
164
+ }
150
165
  }]);
151
166
 
152
167
  return CreatableSelectField;
@@ -173,7 +188,7 @@ CreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
173
188
  hasWarning: _pt.bool,
174
189
  menuPortalZIndex: _pt.number,
175
190
  onBlur: _pt.func,
176
- onChange: _pt.func.isRequired,
191
+ onChange: _pt.func,
177
192
  options: _pt.oneOfType([_pt.arrayOf(_pt.shape({
178
193
  value: _pt.string.isRequired
179
194
  })), _pt.arrayOf(_pt.shape({
@@ -192,6 +207,6 @@ CreatableSelectField.propTypes = process.env.NODE_ENV !== "production" ? {
192
207
  } : {};
193
208
 
194
209
  // NOTE: This string will be replaced on build time with the package version.
195
- var version = "13.0.4";
210
+ var version = "14.0.2";
196
211
 
197
212
  export { CreatableSelectField as default, version };
@@ -4,14 +4,18 @@ import type { CreatableProps } from 'react-select/creatable';
4
4
  declare type ReactSelectCreatableProps = CreatableProps<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 TCustomFormErrors<Values> = {
8
+ [K in keyof Values]?: TFieldErrors;
9
+ };
7
10
  declare type TValue = {
8
11
  value: string;
9
12
  };
10
13
  declare type TOptions = TValue[] | {
11
14
  options: TValue[];
12
15
  }[];
13
- declare type TEvent = {
16
+ declare type TCustomEvent = {
14
17
  target: {
18
+ id?: string;
15
19
  name?: string;
16
20
  value?: unknown;
17
21
  };
@@ -44,8 +48,8 @@ declare type TCreatableSelectFieldProps = {
44
48
  menuShouldBlockScroll?: ReactSelectCreatableProps['menuShouldBlockScroll'];
45
49
  name?: ReactSelectCreatableProps['name'];
46
50
  noOptionsMessage?: ReactSelectCreatableProps['noOptionsMessage'];
47
- onBlur?: (event: TEvent) => void;
48
- onChange: (event: TEvent, info: ActionMeta<unknown>) => void;
51
+ onBlur?: (event: TCustomEvent) => void;
52
+ onChange?: (event: TCustomEvent, info: ActionMeta<unknown>) => void;
49
53
  onFocus?: ReactSelectCreatableProps['onFocus'];
50
54
  onInputChange?: ReactSelectCreatableProps['onInputChange'];
51
55
  options?: TOptions;
@@ -80,6 +84,7 @@ export default class CreatableSelectField extends Component<TCreatableSelectFiel
80
84
  static getDerivedStateFromProps: (props: TCreatableSelectFieldProps, state: TCreatableSelectFieldState) => {
81
85
  id: string;
82
86
  };
87
+ static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
83
88
  render(): import("@emotion/react/jsx-runtime").JSX.Element;
84
89
  }
85
90
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/creatable-select-field",
3
3
  "description": "A controlled input component with validation states and a label getting a selection from the user, and where options can also be created by 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/creatable-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-creatable-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": "13.0.2",
25
- "@commercetools-uikit/creatable-select-input": "13.0.4",
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/constraints": "14.0.1",
25
+ "@commercetools-uikit/creatable-select-input": "14.0.2",
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",