@commercetools-uikit/money-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
@@ -77,7 +77,7 @@ export default Example;
77
77
  | `isDisabled` | `boolean` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
78
78
  | `isReadOnly` | `boolean` | | | Indicates that the field is displaying read-only content |
79
79
  | `isAutofocussed` | `boolean` | | | Focus the input on initial render |
80
- | `onChange` | `Function`<br/>[See signature.](#signature-onChange) || | Called with the event of the input or dropdown when either the currency or the amount have changed. |
80
+ | `onChange` | `Function`<br/>[See signature.](#signature-onChange) | | | Called with the event of the input or dropdown when either the currency or the amount have changed. |
81
81
  | `menuPortalTarget` | `ReactSelectProps['menuPortalTarget']` | | | Dom element to portal the currency select menu to&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
82
82
  | `menuPortalZIndex` | `number` | | | z-index value for the currency select menu portal |
83
83
  | `menuShouldBlockScroll` | `ReactSelectProps['menuShouldBlockScroll']` | | | whether the menu should block scroll while open&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props) |
@@ -117,19 +117,19 @@ 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 `onFocus`
124
124
 
125
125
  ```ts
126
- (event: TEvent) => void
126
+ (event: TCustomEvent) => void
127
127
  ```
128
128
 
129
129
  ### Signature `onChange`
130
130
 
131
131
  ```ts
132
- (event: TEvent) => void
132
+ (event: TCustomEvent) => void
133
133
  ```
134
134
 
135
135
  ### Signature `onInfoButtonClick`
@@ -157,3 +157,21 @@ Known error keys are:
157
157
  ## Main Functions and use cases are:
158
158
 
159
159
  - Getting monetary value input with a currency from users (with cent precision or high precision)
160
+
161
+ ## Static methods
162
+
163
+ ### `MoneyField.toFieldErrors`
164
+
165
+ Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.
166
+
167
+ ```ts
168
+ type FormValues = {
169
+ myField: string;
170
+ };
171
+
172
+ <MoneyField
173
+ // ...
174
+ name="my-field"
175
+ errors={MoneyField.toFieldErrors<FormValues>(formik.errors).myField}
176
+ />;
177
+ ```
@@ -101,6 +101,11 @@ var MoneyField = /*#__PURE__*/function (_Component) {
101
101
  // This avoids showing an error when the user just selected a language but
102
102
  // didn't add an amount yet.
103
103
  var hasError = MoneyInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
104
+
105
+ if (!this.props.isReadOnly) {
106
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.onChange === 'function', 'MoneyField: `onChange` is required when field is not read only.') : void 0;
107
+ }
108
+
104
109
  process.env.NODE_ENV !== "production" ? utils.warning(!has__default["default"](this.props, 'isTouched'), 'MoneyField: Invalid prop isTouched supplied to MoneyField. Use touched instead.') : void 0;
105
110
 
106
111
  if (this.props.hintIcon) {
@@ -149,6 +154,17 @@ var MoneyField = /*#__PURE__*/function (_Component) {
149
154
  })
150
155
  });
151
156
  }
157
+ }], [{
158
+ key: "toFieldErrors",
159
+ value:
160
+ /**
161
+ * Use this function to convert the Formik `errors` object type to
162
+ * our custom field errors type.
163
+ * This is primarly useful when using TypeScript.
164
+ */
165
+ function toFieldErrors(errors) {
166
+ return errors;
167
+ }
152
168
  }]);
153
169
 
154
170
  return MoneyField;
@@ -189,7 +205,7 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
189
205
  isDisabled: _pt__default["default"].bool,
190
206
  isReadOnly: _pt__default["default"].bool,
191
207
  isAutofocussed: _pt__default["default"].bool,
192
- onChange: _pt__default["default"].func.isRequired,
208
+ onChange: _pt__default["default"].func,
193
209
  menuPortalZIndex: _pt__default["default"].number,
194
210
  title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
195
211
  hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
@@ -201,7 +217,7 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
201
217
  var MoneyField$1 = MoneyField;
202
218
 
203
219
  // NOTE: This string will be replaced on build time with the package version.
204
- var version = "13.0.4";
220
+ var version = "14.0.2";
205
221
 
206
222
  exports["default"] = MoneyField$1;
207
223
  exports.version = version;
@@ -100,6 +100,8 @@ var MoneyField = /*#__PURE__*/function (_Component) {
100
100
  // didn't add an amount yet.
101
101
  var hasError = MoneyInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
102
102
 
103
+ if (!this.props.isReadOnly) ;
104
+
103
105
  if (this.props.hintIcon) ;
104
106
 
105
107
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
@@ -144,6 +146,17 @@ var MoneyField = /*#__PURE__*/function (_Component) {
144
146
  })
145
147
  });
146
148
  }
149
+ }], [{
150
+ key: "toFieldErrors",
151
+ value:
152
+ /**
153
+ * Use this function to convert the Formik `errors` object type to
154
+ * our custom field errors type.
155
+ * This is primarly useful when using TypeScript.
156
+ */
157
+ function toFieldErrors(errors) {
158
+ return errors;
159
+ }
147
160
  }]);
148
161
 
149
162
  return MoneyField;
@@ -164,7 +177,7 @@ MoneyField.propTypes = {};
164
177
  var MoneyField$1 = MoneyField;
165
178
 
166
179
  // NOTE: This string will be replaced on build time with the package version.
167
- var version = "13.0.4";
180
+ var version = "14.0.2";
168
181
 
169
182
  exports["default"] = MoneyField$1;
170
183
  exports.version = version;
@@ -75,6 +75,11 @@ var MoneyField = /*#__PURE__*/function (_Component) {
75
75
  // This avoids showing an error when the user just selected a language but
76
76
  // didn't add an amount yet.
77
77
  var hasError = MoneyInput.isTouched(this.props.touched) && hasErrors(this.props.errors);
78
+
79
+ if (!this.props.isReadOnly) {
80
+ process.env.NODE_ENV !== "production" ? warning(typeof this.props.onChange === 'function', 'MoneyField: `onChange` is required when field is not read only.') : void 0;
81
+ }
82
+
78
83
  process.env.NODE_ENV !== "production" ? warning(!has(this.props, 'isTouched'), 'MoneyField: Invalid prop isTouched supplied to MoneyField. Use touched instead.') : void 0;
79
84
 
80
85
  if (this.props.hintIcon) {
@@ -123,6 +128,17 @@ var MoneyField = /*#__PURE__*/function (_Component) {
123
128
  })
124
129
  });
125
130
  }
131
+ }], [{
132
+ key: "toFieldErrors",
133
+ value:
134
+ /**
135
+ * Use this function to convert the Formik `errors` object type to
136
+ * our custom field errors type.
137
+ * This is primarly useful when using TypeScript.
138
+ */
139
+ function toFieldErrors(errors) {
140
+ return errors;
141
+ }
126
142
  }]);
127
143
 
128
144
  return MoneyField;
@@ -163,7 +179,7 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
163
179
  isDisabled: _pt.bool,
164
180
  isReadOnly: _pt.bool,
165
181
  isAutofocussed: _pt.bool,
166
- onChange: _pt.func.isRequired,
182
+ onChange: _pt.func,
167
183
  menuPortalZIndex: _pt.number,
168
184
  title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
169
185
  hint: _pt.oneOfType([_pt.string, _pt.node]),
@@ -175,6 +191,6 @@ MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
175
191
  var MoneyField$1 = MoneyField;
176
192
 
177
193
  // NOTE: This string will be replaced on build time with the package version.
178
- var version = "13.0.4";
194
+ var version = "14.0.2";
179
195
 
180
196
  export { MoneyField$1 as default, version };
@@ -1,8 +1,11 @@
1
1
  import { Component, type ReactElement, type ReactNode } from 'react';
2
2
  import { type Props as ReactSelectProps } from 'react-select';
3
3
  import { type TCurrencyCode } from '@commercetools-uikit/money-input';
4
- declare type TFieldErrors = Record<string, boolean>;
5
4
  declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
5
+ declare type TFieldErrors = Record<string, boolean>;
6
+ declare type TCustomFormErrors<Values> = {
7
+ [K in keyof Values]?: TFieldErrors;
8
+ };
6
9
  declare type TTouched = {
7
10
  amount?: boolean;
8
11
  currencyCode?: boolean;
@@ -11,7 +14,7 @@ declare type TValue = {
11
14
  amount: string;
12
15
  currencyCode: TCurrencyCode;
13
16
  };
14
- declare type TEvent = {
17
+ declare type TCustomEvent = {
15
18
  target: {
16
19
  id?: string;
17
20
  name?: string;
@@ -32,12 +35,12 @@ declare type TMoneyFieldProps = {
32
35
  value: TValue;
33
36
  currencies?: string[];
34
37
  placeholder?: string;
35
- onBlur?: (event: TEvent) => void;
36
- onFocus?: (event: TEvent) => void;
38
+ onBlur?: (event: TCustomEvent) => void;
39
+ onFocus?: (event: TCustomEvent) => void;
37
40
  isDisabled?: boolean;
38
41
  isReadOnly?: boolean;
39
42
  isAutofocussed?: boolean;
40
- onChange: (event: TEvent) => void;
43
+ onChange?: (event: TCustomEvent) => void;
41
44
  menuPortalTarget?: ReactSelectProps['menuPortalTarget'];
42
45
  menuPortalZIndex?: number;
43
46
  menuShouldBlockScroll?: ReactSelectProps['menuShouldBlockScroll'];
@@ -60,6 +63,7 @@ declare class MoneyField extends Component<TMoneyFieldProps, TMoneyFieldState> {
60
63
  static getDerivedStateFromProps: (props: TMoneyFieldProps, state: TMoneyFieldState) => {
61
64
  id: string;
62
65
  };
66
+ static toFieldErrors<FormValues>(errors: unknown): TCustomFormErrors<FormValues>;
63
67
  render(): import("@emotion/react/jsx-runtime").JSX.Element;
64
68
  }
65
69
  export default MoneyField;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-uikit/money-field",
3
3
  "description": "A controlled input component for money values with validation states and a label.",
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/money-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-money-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/design-system": "13.0.0",
26
- "@commercetools-uikit/field-errors": "13.0.4",
27
- "@commercetools-uikit/field-label": "13.0.4",
28
- "@commercetools-uikit/money-input": "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/design-system": "14.0.0",
26
+ "@commercetools-uikit/field-errors": "14.0.1",
27
+ "@commercetools-uikit/field-label": "14.0.2",
28
+ "@commercetools-uikit/money-input": "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
  "lodash": "4.17.21",