@commercetools-uikit/money-field 12.2.9 → 13.0.3

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
@@ -58,40 +58,85 @@ export default Example;
58
58
 
59
59
  ## Properties
60
60
 
61
- | Props | Type | Required | Default | Description |
62
- | ----------------------- | -------------------------------------------------------------------------------------------------- | :------: | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
63
- | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
64
- | `horizontalConstraint` | `enum`<br/>Possible values:<br/>`3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
65
- | `errors` | `object` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError` |
66
- | `errors.missing` | `bool` | | | |
67
- | `renderError` | `func` | | | Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.&#xA;<br />&#xA;Signature: `(key, error) => React.node` |
68
- | `isRequired` | `bool` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
69
- | `touched` | `object` | | | Indicates whether the `currencyCode` or `amount` fields were touched.&#xA;<br />&#xA;Errors will only be shown when the field was touched. |
70
- | `touched.amount` | `bool` | | | |
71
- | `touched.currencyCode` | `bool` | | | |
72
- | `isTouched` | `custom` | | | |
73
- | `autoComplete` | `string` | | | Used as HTML `autocomplete` property |
74
- | `name` | `string` | | | The prefix used to create a HTML `name` property for the amount input field (`${name}.amount`) and the currency dropdown (`${name}.currencyCode`). |
75
- | `value` | `object` || | Value of the input. Consists of the currency code and an amount. `amount` is a string representing the amount. A dot has to be used as the decimal separator. |
76
- | `value.amount` | `string` || | |
77
- | `value.currencyCode` | `string` || | |
78
- | `currencies` | Array of `string` | | | List of possible currencies. When not provided or empty, the component renders a label with the value's currency instead of a dropdown. |
79
- | `placeholder` | `string` | | | Placeholder text for the amount input |
80
- | `onBlur` | `func` | | | Called when input is blurred |
81
- | `onFocus` | `func` | | | Called when input is focused |
82
- | `isDisabled` | `bool` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
83
- | `isReadOnly` | `bool` | | | Indicates that the field is displaying read-only content |
84
- | `isAutofocussed` | `bool` | | | Focus the input on initial render |
85
- | `onChange` | `func` || | Called with the event of the input or dropdown when either the currency or the amount have changed.&#xA;<br />&#xA;Signature: `(event) => void` |
86
- | `menuPortalTarget` | `SafeHTMLElement` | | | Dom element to portal the currency select menu to |
87
- | `menuPortalZIndex` | `number` | | | z-index value for the currency select menu portal |
88
- | `menuShouldBlockScroll` | `bool` | | | whether the menu should block scroll while open |
89
- | `title` | `<string, node>` || | Title of the label |
90
- | `hint` | `custom` | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`. |
91
- | `description` | `<string, node>` | | | Provides a description for the title. |
92
- | `onInfoButtonClick` | `func` | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed.&#xA;<br />&#xA;Signature: `(event) => void` |
93
- | `hintIcon` | `node` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
94
- | `hasHighPrecisionBadge` | `bool` | | | Shows high precision badge in case current value uses high precision. |
61
+ | Props | Type | Required | Default | Description |
62
+ | ----------------------- | ----------------------------------------------------------------------------------------------------- | :------: | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
63
+ | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
64
+ | `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
65
+ | `errors` | `Record` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError` |
66
+ | `renderError` | `Function`<br/>[See signature.](#signature-renderError) | | | Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error. |
67
+ | `isRequired` | `boolean` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
68
+ | `touched` | `Object`<br/>[See signature.](#signature-touched) | | | Indicates whether the `currencyCode` or `amount` fields were touched.&#xA;<br />&#xA;Errors will only be shown when the field was touched. |
69
+ | `isTouched` | `unknown` | | | |
70
+ | `autoComplete` | `string` | | | Used as HTML `autocomplete` property |
71
+ | `name` | `string` | | | The prefix used to create a HTML `name` property for the amount input field (`${name}.amount`) and the currency dropdown (`${name}.currencyCode`). |
72
+ | `value` | `Object`<br/>[See signature.](#signature-value) || | Value of the input. Consists of the currency code and an amount. `amount` is a string representing the amount. A dot has to be used as the decimal separator. |
73
+ | `currencies` | `Array: string[]` | | | List of possible currencies. When not provided or empty, the component renders a label with the value's currency instead of a dropdown. |
74
+ | `placeholder` | `string` | | | Placeholder text for the amount input |
75
+ | `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Called when input is blurred |
76
+ | `onFocus` | `Function`<br/>[See signature.](#signature-onFocus) | | | Called when input is focused |
77
+ | `isDisabled` | `boolean` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
78
+ | `isReadOnly` | `boolean` | | | Indicates that the field is displaying read-only content |
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. |
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
+ | `menuPortalZIndex` | `number` | | | z-index value for the currency select menu portal |
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) |
84
+ | `title` | `union`<br/>Possible values:<br/>`string , ReactNode` || | Title of the label |
85
+ | `hint` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`. |
86
+ | `description` | `union`<br/>Possible values:<br/>`string , ReactNode` | | | Provides a description for the title. |
87
+ | `onInfoButtonClick` | `Function`<br/>[See signature.](#signature-onInfoButtonClick) | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed. |
88
+ | `hintIcon` | `ReactElement` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
89
+ | `hasHighPrecisionBadge` | `boolean` | | | Shows high precision badge in case current value uses high precision. |
90
+
91
+ ## Signatures
92
+
93
+ ### Signature `renderError`
94
+
95
+ ```ts
96
+ (key: string, error?: boolean) => ReactNode;
97
+ ```
98
+
99
+ ### Signature `touched`
100
+
101
+ ```ts
102
+ {
103
+ amount?: boolean;
104
+ currencyCode?: boolean;
105
+ }
106
+ ```
107
+
108
+ ### Signature `value`
109
+
110
+ ```ts
111
+ {
112
+ amount: string;
113
+ currencyCode: TCurrencyCode;
114
+ }
115
+ ```
116
+
117
+ ### Signature `onBlur`
118
+
119
+ ```ts
120
+ (event: TEvent) => void
121
+ ```
122
+
123
+ ### Signature `onFocus`
124
+
125
+ ```ts
126
+ (event: TEvent) => void
127
+ ```
128
+
129
+ ### Signature `onChange`
130
+
131
+ ```ts
132
+ (event: TEvent) => void
133
+ ```
134
+
135
+ ### Signature `onInfoButtonClick`
136
+
137
+ ```ts
138
+ () => void
139
+ ```
95
140
 
96
141
  ## `data-*` props
97
142
 
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index";
2
+ export { default } from "./declarations/src/index";
@@ -17,12 +17,11 @@ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
17
17
  var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
18
18
  var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
19
19
  var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
20
+ var _pt = require('prop-types');
20
21
  var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
21
22
  var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
22
23
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
23
24
  var react = require('react');
24
- var PropTypes = require('prop-types');
25
- var requiredIf = require('react-required-if');
26
25
  var has = require('lodash/has');
27
26
  var utils = require('@commercetools-uikit/utils');
28
27
  var Constraints = require('@commercetools-uikit/constraints');
@@ -43,11 +42,10 @@ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachIns
43
42
  var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
44
43
  var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
45
44
  var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
45
+ var _pt__default = /*#__PURE__*/_interopDefault(_pt);
46
46
  var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
47
47
  var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
48
48
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
49
- var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
50
- var requiredIf__default = /*#__PURE__*/_interopDefault(requiredIf);
51
49
  var has__default = /*#__PURE__*/_interopDefault(has);
52
50
  var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
53
51
  var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
@@ -55,9 +53,9 @@ var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
55
53
  var MoneyInput__default = /*#__PURE__*/_interopDefault(MoneyInput);
56
54
  var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
57
55
 
58
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
56
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
59
57
 
60
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context5; _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
58
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
61
59
 
62
60
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
63
61
 
@@ -102,6 +100,12 @@ var MoneyField = /*#__PURE__*/function (_Component) {
102
100
  // This avoids showing an error when the user just selected a language but
103
101
  // didn't add an amount yet.
104
102
  var hasError = MoneyInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
103
+ 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;
104
+
105
+ if (this.props.hintIcon) {
106
+ process.env.NODE_ENV !== "production" ? utils.warning(typeof this.props.hint === 'string' || /*#__PURE__*/react.isValidElement(this.props.hint), 'MoneyField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
107
+ }
108
+
105
109
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
106
110
  max: this.props.horizontalConstraint,
107
111
  children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
@@ -157,181 +161,42 @@ MoneyField.getDerivedStateFromProps = function (props, state) {
157
161
  };
158
162
 
159
163
  MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
160
- // MoneyField
161
-
162
- /**
163
- * Used as HTML id property. An id is auto-generated when it is not specified.
164
- */
165
- id: PropTypes__default["default"].string,
166
-
167
- /**
168
- * Horizontal size limit of the input fields.
169
- */
170
- horizontalConstraint: PropTypes__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
171
-
172
- /**
173
- * A map of errors. Error messages for known errors are rendered automatically.
174
- * <br />
175
- * Unknown errors will be forwarded to `renderError`
176
- */
177
- errors: PropTypes__default["default"].shape({
178
- missing: PropTypes__default["default"].bool
179
- }),
180
-
181
- /**
182
- * Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
183
- * <br />
184
- * Signature: `(key, error) => React.node`
185
- */
186
- renderError: PropTypes__default["default"].func,
187
-
188
- /**
189
- * Indicates if the value is required. Shows an the "required asterisk" if so.
190
- */
191
- isRequired: PropTypes__default["default"].bool,
192
-
193
- /**
194
- * Indicates whether the `currencyCode` or `amount` fields were touched.
195
- * <br />
196
- * Errors will only be shown when the field was touched.
197
- */
198
- touched: PropTypes__default["default"].shape({
199
- amount: PropTypes__default["default"].bool,
200
- currencyCode: PropTypes__default["default"].bool
164
+ id: _pt__default["default"].string,
165
+ horizontalConstraint: _pt__default["default"].oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
166
+ errors: _pt__default["default"].objectOf(_pt__default["default"].bool),
167
+ renderError: _pt__default["default"].func,
168
+ isRequired: _pt__default["default"].bool,
169
+ touched: _pt__default["default"].shape({
170
+ amount: _pt__default["default"].bool,
171
+ currencyCode: _pt__default["default"].bool
201
172
  }),
202
- // Some other fields use isTouched, but the check isn't as simple here.
203
- // isTouched accepts a boolean, whereas touched takes an object.
204
- // Maybe we should upgrade them all to just be "touched"?
205
- // eslint-disable-next-line react/no-unused-prop-types
206
- isTouched: function isTouched(props, propName, componentName) {
207
- if (has__default["default"](props, propName)) {
208
- var _context3;
209
-
210
- return new Error(_concatInstanceProperty__default["default"](_context3 = "Invalid prop `".concat(propName, "` supplied to `")).call(_context3, componentName, "`. Use `touched` instead."));
211
- }
212
-
213
- return undefined;
214
- },
215
- // MoneyInput
216
-
217
- /**
218
- * Used as HTML `autocomplete` property
219
- */
220
- autoComplete: PropTypes__default["default"].string,
221
-
222
- /**
223
- * The prefix used to create a HTML `name` property for the amount input field (`${name}.amount`) and the currency dropdown (`${name}.currencyCode`).
224
- */
225
- name: PropTypes__default["default"].string,
226
-
227
- /**
228
- * Value of the input. Consists of the currency code and an amount. `amount` is a string representing the amount. A dot has to be used as the decimal separator.
229
- */
230
- value: PropTypes__default["default"].shape({
231
- amount: PropTypes__default["default"].string.isRequired,
232
- currencyCode: PropTypes__default["default"].string.isRequired
173
+ isTouched: _pt__default["default"].any,
174
+ autoComplete: _pt__default["default"].string,
175
+ name: _pt__default["default"].string,
176
+ value: _pt__default["default"].shape({
177
+ amount: _pt__default["default"].string.isRequired,
178
+ currencyCode: _pt__default["default"].any.isRequired
233
179
  }).isRequired,
234
-
235
- /**
236
- * List of possible currencies. When not provided or empty, the component renders a label with the value's currency instead of a dropdown.
237
- */
238
- currencies: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string),
239
-
240
- /**
241
- * Placeholder text for the amount input
242
- */
243
- placeholder: PropTypes__default["default"].string,
244
-
245
- /**
246
- * Called when input is blurred
247
- */
248
- onBlur: PropTypes__default["default"].func,
249
-
250
- /**
251
- * Called when input is focused
252
- */
253
- onFocus: PropTypes__default["default"].func,
254
-
255
- /**
256
- * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
257
- */
258
- isDisabled: PropTypes__default["default"].bool,
259
-
260
- /**
261
- * Indicates that the field is displaying read-only content
262
- */
263
- isReadOnly: PropTypes__default["default"].bool,
264
-
265
- /**
266
- * Focus the input on initial render
267
- */
268
- isAutofocussed: PropTypes__default["default"].bool,
269
-
270
- /**
271
- * Called with the event of the input or dropdown when either the currency or the amount have changed.
272
- * <br />
273
- * Signature: `(event) => void`
274
- */
275
- onChange: PropTypes__default["default"].func.isRequired,
276
-
277
- /**
278
- * Dom element to portal the currency select menu to
279
- */
280
- menuPortalTarget: PropTypes__default["default"].instanceOf(utils.SafeHTMLElement),
281
-
282
- /**
283
- * z-index value for the currency select menu portal
284
- */
285
- menuPortalZIndex: PropTypes__default["default"].number,
286
-
287
- /**
288
- * whether the menu should block scroll while open
289
- */
290
- menuShouldBlockScroll: PropTypes__default["default"].bool,
291
- // LabelField
292
-
293
- /**
294
- * Title of the label
295
- */
296
- title: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]).isRequired,
297
-
298
- /**
299
- * Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`.
300
- */
301
- hint: requiredIf__default["default"](PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]), function (props) {
302
- return props.hintIcon;
303
- }),
304
-
305
- /**
306
- * Provides a description for the title.
307
- */
308
- description: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]),
309
-
310
- /**
311
- * Function called when info button is pressed.
312
- * <br />
313
- * Info button will only be visible when this prop is passed.
314
- * <br />
315
- * Signature: `(event) => void`
316
- */
317
- onInfoButtonClick: PropTypes__default["default"].func,
318
-
319
- /**
320
- * Icon to be displayed beside the hint text.
321
- * <br />
322
- * Will only get rendered when `hint` is passed as well.
323
- */
324
- hintIcon: PropTypes__default["default"].node,
325
-
326
- /**
327
- * Shows high precision badge in case current value uses high precision.
328
- */
329
- hasHighPrecisionBadge: PropTypes__default["default"].bool
180
+ currencies: _pt__default["default"].arrayOf(_pt__default["default"].string),
181
+ placeholder: _pt__default["default"].string,
182
+ onBlur: _pt__default["default"].func,
183
+ onFocus: _pt__default["default"].func,
184
+ isDisabled: _pt__default["default"].bool,
185
+ isReadOnly: _pt__default["default"].bool,
186
+ isAutofocussed: _pt__default["default"].bool,
187
+ onChange: _pt__default["default"].func.isRequired,
188
+ menuPortalZIndex: _pt__default["default"].number,
189
+ title: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]).isRequired,
190
+ hint: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
191
+ description: _pt__default["default"].oneOfType([_pt__default["default"].string, _pt__default["default"].node]),
192
+ onInfoButtonClick: _pt__default["default"].func,
193
+ hintIcon: _pt__default["default"].element,
194
+ hasHighPrecisionBadge: _pt__default["default"].bool
330
195
  } : {};
331
196
  var MoneyField$1 = MoneyField;
332
197
 
333
198
  // NOTE: This string will be replaced on build time with the package version.
334
- var version = "12.2.9";
199
+ var version = "13.0.3";
335
200
 
336
201
  exports["default"] = MoneyField$1;
337
202
  exports.version = version;
@@ -17,12 +17,11 @@ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
17
17
  var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
18
18
  var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
19
19
  var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
20
+ require('prop-types');
20
21
  var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
21
22
  var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
22
23
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
23
24
  var react = require('react');
24
- require('prop-types');
25
- require('react-required-if');
26
25
  require('lodash/has');
27
26
  var utils = require('@commercetools-uikit/utils');
28
27
  var Constraints = require('@commercetools-uikit/constraints');
@@ -52,9 +51,9 @@ var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
52
51
  var MoneyInput__default = /*#__PURE__*/_interopDefault(MoneyInput);
53
52
  var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
54
53
 
55
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
54
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
56
55
 
57
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default["default"]) { _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)); } else { var _context5; _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } } return target; }
56
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
58
57
 
59
58
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
60
59
 
@@ -99,6 +98,9 @@ var MoneyField = /*#__PURE__*/function (_Component) {
99
98
  // This avoids showing an error when the user just selected a language but
100
99
  // didn't add an amount yet.
101
100
  var hasError = MoneyInput__default["default"].isTouched(this.props.touched) && hasErrors(this.props.errors);
101
+
102
+ if (this.props.hintIcon) ;
103
+
102
104
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
103
105
  max: this.props.horizontalConstraint,
104
106
  children: jsxRuntime.jsxs(Spacings__default["default"].Stack, {
@@ -157,7 +159,7 @@ MoneyField.propTypes = {};
157
159
  var MoneyField$1 = MoneyField;
158
160
 
159
161
  // NOTE: This string will be replaced on build time with the package version.
160
- var version = "12.2.9";
162
+ var version = "13.0.3";
161
163
 
162
164
  exports["default"] = MoneyField$1;
163
165
  exports.version = version;
@@ -13,14 +13,13 @@ import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
13
13
  import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
14
14
  import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
15
15
  import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
16
+ import _pt from 'prop-types';
16
17
  import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
17
18
  import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
18
19
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
19
- import { Component } from 'react';
20
- import PropTypes from 'prop-types';
21
- import requiredIf from 'react-required-if';
20
+ import { isValidElement, Component } from 'react';
22
21
  import has from 'lodash/has';
23
- import { createSequentialId, filterDataAttributes, getFieldId, SafeHTMLElement } from '@commercetools-uikit/utils';
22
+ import { createSequentialId, warning, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
24
23
  import Constraints from '@commercetools-uikit/constraints';
25
24
  import Spacings from '@commercetools-uikit/spacings';
26
25
  import FieldLabel from '@commercetools-uikit/field-label';
@@ -28,9 +27,9 @@ import MoneyInput from '@commercetools-uikit/money-input';
28
27
  import FieldErrors from '@commercetools-uikit/field-errors';
29
28
  import { jsx, jsxs } from '@emotion/react/jsx-runtime';
30
29
 
31
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
30
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
32
31
 
33
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context5; _forEachInstanceProperty(_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
34
33
 
35
34
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
36
35
 
@@ -75,6 +74,12 @@ var MoneyField = /*#__PURE__*/function (_Component) {
75
74
  // This avoids showing an error when the user just selected a language but
76
75
  // didn't add an amount yet.
77
76
  var hasError = MoneyInput.isTouched(this.props.touched) && hasErrors(this.props.errors);
77
+ process.env.NODE_ENV !== "production" ? warning(!has(this.props, 'isTouched'), 'MoneyField: Invalid prop isTouched supplied to MoneyField. Use touched instead.') : void 0;
78
+
79
+ if (this.props.hintIcon) {
80
+ process.env.NODE_ENV !== "production" ? warning(typeof this.props.hint === 'string' || /*#__PURE__*/isValidElement(this.props.hint), 'MoneyField: `hint` is required to be string or ReactNode if hintIcon is present') : void 0;
81
+ }
82
+
78
83
  return jsx(Constraints.Horizontal, {
79
84
  max: this.props.horizontalConstraint,
80
85
  children: jsxs(Spacings.Stack, {
@@ -130,180 +135,41 @@ MoneyField.getDerivedStateFromProps = function (props, state) {
130
135
  };
131
136
 
132
137
  MoneyField.propTypes = process.env.NODE_ENV !== "production" ? {
133
- // MoneyField
134
-
135
- /**
136
- * Used as HTML id property. An id is auto-generated when it is not specified.
137
- */
138
- id: PropTypes.string,
139
-
140
- /**
141
- * Horizontal size limit of the input fields.
142
- */
143
- horizontalConstraint: PropTypes.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
144
-
145
- /**
146
- * A map of errors. Error messages for known errors are rendered automatically.
147
- * <br />
148
- * Unknown errors will be forwarded to `renderError`
149
- */
150
- errors: PropTypes.shape({
151
- missing: PropTypes.bool
152
- }),
153
-
154
- /**
155
- * Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
156
- * <br />
157
- * Signature: `(key, error) => React.node`
158
- */
159
- renderError: PropTypes.func,
160
-
161
- /**
162
- * Indicates if the value is required. Shows an the "required asterisk" if so.
163
- */
164
- isRequired: PropTypes.bool,
165
-
166
- /**
167
- * Indicates whether the `currencyCode` or `amount` fields were touched.
168
- * <br />
169
- * Errors will only be shown when the field was touched.
170
- */
171
- touched: PropTypes.shape({
172
- amount: PropTypes.bool,
173
- currencyCode: PropTypes.bool
138
+ id: _pt.string,
139
+ horizontalConstraint: _pt.oneOf([3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
140
+ errors: _pt.objectOf(_pt.bool),
141
+ renderError: _pt.func,
142
+ isRequired: _pt.bool,
143
+ touched: _pt.shape({
144
+ amount: _pt.bool,
145
+ currencyCode: _pt.bool
174
146
  }),
175
- // Some other fields use isTouched, but the check isn't as simple here.
176
- // isTouched accepts a boolean, whereas touched takes an object.
177
- // Maybe we should upgrade them all to just be "touched"?
178
- // eslint-disable-next-line react/no-unused-prop-types
179
- isTouched: function isTouched(props, propName, componentName) {
180
- if (has(props, propName)) {
181
- var _context3;
182
-
183
- return new Error(_concatInstanceProperty(_context3 = "Invalid prop `".concat(propName, "` supplied to `")).call(_context3, componentName, "`. Use `touched` instead."));
184
- }
185
-
186
- return undefined;
187
- },
188
- // MoneyInput
189
-
190
- /**
191
- * Used as HTML `autocomplete` property
192
- */
193
- autoComplete: PropTypes.string,
194
-
195
- /**
196
- * The prefix used to create a HTML `name` property for the amount input field (`${name}.amount`) and the currency dropdown (`${name}.currencyCode`).
197
- */
198
- name: PropTypes.string,
199
-
200
- /**
201
- * Value of the input. Consists of the currency code and an amount. `amount` is a string representing the amount. A dot has to be used as the decimal separator.
202
- */
203
- value: PropTypes.shape({
204
- amount: PropTypes.string.isRequired,
205
- currencyCode: PropTypes.string.isRequired
147
+ isTouched: _pt.any,
148
+ autoComplete: _pt.string,
149
+ name: _pt.string,
150
+ value: _pt.shape({
151
+ amount: _pt.string.isRequired,
152
+ currencyCode: _pt.any.isRequired
206
153
  }).isRequired,
207
-
208
- /**
209
- * List of possible currencies. When not provided or empty, the component renders a label with the value's currency instead of a dropdown.
210
- */
211
- currencies: PropTypes.arrayOf(PropTypes.string),
212
-
213
- /**
214
- * Placeholder text for the amount input
215
- */
216
- placeholder: PropTypes.string,
217
-
218
- /**
219
- * Called when input is blurred
220
- */
221
- onBlur: PropTypes.func,
222
-
223
- /**
224
- * Called when input is focused
225
- */
226
- onFocus: PropTypes.func,
227
-
228
- /**
229
- * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
230
- */
231
- isDisabled: PropTypes.bool,
232
-
233
- /**
234
- * Indicates that the field is displaying read-only content
235
- */
236
- isReadOnly: PropTypes.bool,
237
-
238
- /**
239
- * Focus the input on initial render
240
- */
241
- isAutofocussed: PropTypes.bool,
242
-
243
- /**
244
- * Called with the event of the input or dropdown when either the currency or the amount have changed.
245
- * <br />
246
- * Signature: `(event) => void`
247
- */
248
- onChange: PropTypes.func.isRequired,
249
-
250
- /**
251
- * Dom element to portal the currency select menu to
252
- */
253
- menuPortalTarget: PropTypes.instanceOf(SafeHTMLElement),
254
-
255
- /**
256
- * z-index value for the currency select menu portal
257
- */
258
- menuPortalZIndex: PropTypes.number,
259
-
260
- /**
261
- * whether the menu should block scroll while open
262
- */
263
- menuShouldBlockScroll: PropTypes.bool,
264
- // LabelField
265
-
266
- /**
267
- * Title of the label
268
- */
269
- title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
270
-
271
- /**
272
- * Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`.
273
- */
274
- hint: requiredIf(PropTypes.oneOfType([PropTypes.string, PropTypes.node]), function (props) {
275
- return props.hintIcon;
276
- }),
277
-
278
- /**
279
- * Provides a description for the title.
280
- */
281
- description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
282
-
283
- /**
284
- * Function called when info button is pressed.
285
- * <br />
286
- * Info button will only be visible when this prop is passed.
287
- * <br />
288
- * Signature: `(event) => void`
289
- */
290
- onInfoButtonClick: PropTypes.func,
291
-
292
- /**
293
- * Icon to be displayed beside the hint text.
294
- * <br />
295
- * Will only get rendered when `hint` is passed as well.
296
- */
297
- hintIcon: PropTypes.node,
298
-
299
- /**
300
- * Shows high precision badge in case current value uses high precision.
301
- */
302
- hasHighPrecisionBadge: PropTypes.bool
154
+ currencies: _pt.arrayOf(_pt.string),
155
+ placeholder: _pt.string,
156
+ onBlur: _pt.func,
157
+ onFocus: _pt.func,
158
+ isDisabled: _pt.bool,
159
+ isReadOnly: _pt.bool,
160
+ isAutofocussed: _pt.bool,
161
+ onChange: _pt.func.isRequired,
162
+ menuPortalZIndex: _pt.number,
163
+ title: _pt.oneOfType([_pt.string, _pt.node]).isRequired,
164
+ hint: _pt.oneOfType([_pt.string, _pt.node]),
165
+ description: _pt.oneOfType([_pt.string, _pt.node]),
166
+ onInfoButtonClick: _pt.func,
167
+ hintIcon: _pt.element,
168
+ hasHighPrecisionBadge: _pt.bool
303
169
  } : {};
304
170
  var MoneyField$1 = MoneyField;
305
171
 
306
172
  // NOTE: This string will be replaced on build time with the package version.
307
- var version = "12.2.9";
173
+ var version = "13.0.3";
308
174
 
309
175
  export { MoneyField$1 as default, version };
@@ -0,0 +1,2 @@
1
+ export { default } from './money-field';
2
+ export { default as version } from './version';
@@ -0,0 +1,65 @@
1
+ import { Component, type ReactElement, type ReactNode } from 'react';
2
+ import { type Props as ReactSelectProps } from 'react-select';
3
+ import { type TCurrencyCode } from '@commercetools-uikit/money-input';
4
+ declare type TFieldErrors = Record<string, boolean>;
5
+ declare type TErrorRenderer = (key: string, error?: boolean) => ReactNode;
6
+ declare type TTouched = {
7
+ amount?: boolean;
8
+ currencyCode?: boolean;
9
+ };
10
+ declare type TValue = {
11
+ amount: string;
12
+ currencyCode: TCurrencyCode;
13
+ };
14
+ declare type TEvent = {
15
+ target: {
16
+ id?: string;
17
+ name?: string;
18
+ value?: string | string[] | null;
19
+ };
20
+ persist?: () => void;
21
+ };
22
+ declare type TMoneyFieldProps = {
23
+ id?: string;
24
+ horizontalConstraint?: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 'scale' | 'auto';
25
+ errors?: TFieldErrors;
26
+ renderError?: TErrorRenderer;
27
+ isRequired?: boolean;
28
+ touched?: TTouched;
29
+ isTouched?: unknown;
30
+ autoComplete?: string;
31
+ name?: string;
32
+ value: TValue;
33
+ currencies?: string[];
34
+ placeholder?: string;
35
+ onBlur?: (event: TEvent) => void;
36
+ onFocus?: (event: TEvent) => void;
37
+ isDisabled?: boolean;
38
+ isReadOnly?: boolean;
39
+ isAutofocussed?: boolean;
40
+ onChange: (event: TEvent) => void;
41
+ menuPortalTarget?: ReactSelectProps['menuPortalTarget'];
42
+ menuPortalZIndex?: number;
43
+ menuShouldBlockScroll?: ReactSelectProps['menuShouldBlockScroll'];
44
+ title: string | ReactNode;
45
+ hint?: string | ReactNode;
46
+ description?: string | ReactNode;
47
+ onInfoButtonClick?: () => void;
48
+ hintIcon?: ReactElement;
49
+ hasHighPrecisionBadge?: boolean;
50
+ };
51
+ declare type TMoneyFieldState = Pick<TMoneyFieldProps, 'id'>;
52
+ declare class MoneyField extends Component<TMoneyFieldProps, TMoneyFieldState> {
53
+ static displayName: string;
54
+ static defaultProps: {
55
+ horizontalConstraint: string;
56
+ };
57
+ state: {
58
+ id: string | undefined;
59
+ };
60
+ static getDerivedStateFromProps: (props: TMoneyFieldProps, state: TMoneyFieldState) => {
61
+ id: string;
62
+ };
63
+ render(): import("@emotion/react/jsx-runtime").JSX.Element;
64
+ }
65
+ export default MoneyField;
@@ -0,0 +1,2 @@
1
+ declare const _default: "__@UI_KIT_PACKAGE/VERSION_OF_RELEASE__";
2
+ export default _default;
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": "12.2.9",
4
+ "version": "13.0.3",
5
5
  "bugs": "https://github.com/commercetools/ui-kit/issues",
6
6
  "repository": {
7
7
  "type": "git",
@@ -19,19 +19,19 @@
19
19
  "module": "dist/commercetools-uikit-money-field.esm.js",
20
20
  "files": ["dist"],
21
21
  "dependencies": {
22
- "@babel/runtime": "7.16.5",
23
- "@babel/runtime-corejs3": "7.16.5",
24
- "@commercetools-uikit/constraints": "12.2.9",
25
- "@commercetools-uikit/design-system": "12.2.9",
26
- "@commercetools-uikit/field-errors": "12.2.9",
27
- "@commercetools-uikit/field-label": "12.2.9",
28
- "@commercetools-uikit/money-input": "12.2.9",
29
- "@commercetools-uikit/spacings": "12.2.9",
30
- "@commercetools-uikit/utils": "12.2.9",
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.2",
27
+ "@commercetools-uikit/field-label": "13.0.2",
28
+ "@commercetools-uikit/money-input": "13.0.3",
29
+ "@commercetools-uikit/spacings": "13.0.2",
30
+ "@commercetools-uikit/utils": "13.0.2",
31
31
  "@emotion/react": "^11.4.0",
32
32
  "@emotion/styled": "^11.3.0",
33
33
  "lodash": "4.17.21",
34
- "prop-types": "15.7.2",
34
+ "prop-types": "15.8.1",
35
35
  "react-required-if": "1.0.3"
36
36
  },
37
37
  "devDependencies": {