@commercetools-uikit/money-input 12.2.9 → 13.0.0
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 +50 -23
- package/dist/commercetools-uikit-money-input.cjs.d.ts +2 -0
- package/dist/commercetools-uikit-money-input.cjs.dev.js +82 -152
- package/dist/commercetools-uikit-money-input.cjs.prod.js +44 -34
- package/dist/commercetools-uikit-money-input.esm.js +82 -151
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/declarations/src/messages.d.ts +8 -0
- package/dist/declarations/src/money-input.d.ts +95 -0
- package/dist/declarations/src/money-input.styles.d.ts +11 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/package.json +12 -12
|
@@ -10,11 +10,11 @@ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/in
|
|
|
10
10
|
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
11
11
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
12
12
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
13
|
-
require('@babel/runtime-corejs3/helpers/typeof');
|
|
14
13
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
15
14
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
16
15
|
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
17
16
|
var _styled = require('@emotion/styled/base');
|
|
17
|
+
var _pt = require('prop-types');
|
|
18
18
|
var _lastIndexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/last-index-of');
|
|
19
19
|
var _parseFloat = require('@babel/runtime-corejs3/core-js-stable/parse-float');
|
|
20
20
|
var _Math$trunc = require('@babel/runtime-corejs3/core-js-stable/math/trunc');
|
|
@@ -26,9 +26,7 @@ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/insta
|
|
|
26
26
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
27
27
|
var react$1 = require('react');
|
|
28
28
|
var ReactDOM = require('react-dom');
|
|
29
|
-
require('prop-types');
|
|
30
29
|
require('lodash/has');
|
|
31
|
-
require('react-required-if');
|
|
32
30
|
var Select = require('react-select');
|
|
33
31
|
var reactIntl = require('react-intl');
|
|
34
32
|
var react = require('@emotion/react');
|
|
@@ -53,6 +51,7 @@ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_O
|
|
|
53
51
|
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
54
52
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
55
53
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
54
|
+
var _pt__default = /*#__PURE__*/_interopDefault(_pt);
|
|
56
55
|
var _lastIndexOfInstanceProperty__default = /*#__PURE__*/_interopDefault(_lastIndexOfInstanceProperty);
|
|
57
56
|
var _parseFloat__default = /*#__PURE__*/_interopDefault(_parseFloat);
|
|
58
57
|
var _Math$trunc__default = /*#__PURE__*/_interopDefault(_Math$trunc);
|
|
@@ -753,12 +752,12 @@ var messages = reactIntl.defineMessages({
|
|
|
753
752
|
|
|
754
753
|
var _excluded = ["id"];
|
|
755
754
|
|
|
756
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object);
|
|
755
|
+
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; }
|
|
757
756
|
|
|
758
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
757
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context14, _context15; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context14 = ownKeys(Object(source), !0)).call(_context14, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context15 = ownKeys(Object(source))).call(_context15, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
759
758
|
|
|
760
759
|
var TooltipWrapper = _styled__default["default"]("div", {
|
|
761
|
-
target: "
|
|
760
|
+
target: "e1u90zjc0"
|
|
762
761
|
} )({
|
|
763
762
|
name: "zjik7",
|
|
764
763
|
styles: "display:flex"
|
|
@@ -774,7 +773,18 @@ var getPortalNode = function getPortalNode(id) {
|
|
|
774
773
|
|
|
775
774
|
var Portal = function Portal(props) {
|
|
776
775
|
var domNode = getPortalNode(props.id);
|
|
777
|
-
|
|
776
|
+
|
|
777
|
+
if (domNode) {
|
|
778
|
+
return /*#__PURE__*/ReactDOM__default["default"].createPortal(props.children, domNode);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return null;
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
Portal.propTypes = {
|
|
785
|
+
id: _pt__default["default"].string.isRequired,
|
|
786
|
+
children: _pt__default["default"].node,
|
|
787
|
+
isDisabled: _pt__default["default"].bool
|
|
778
788
|
};
|
|
779
789
|
|
|
780
790
|
var CurrencyLabel = function CurrencyLabel(props) {
|
|
@@ -785,8 +795,8 @@ var CurrencyLabel = function CurrencyLabel(props) {
|
|
|
785
795
|
});
|
|
786
796
|
};
|
|
787
797
|
|
|
788
|
-
CurrencyLabel.displayName = 'CurrencyLabel';
|
|
789
798
|
CurrencyLabel.propTypes = {};
|
|
799
|
+
CurrencyLabel.displayName = 'CurrencyLabel';
|
|
790
800
|
|
|
791
801
|
var _SingleValue = function SingleValue(_ref3) {
|
|
792
802
|
var id = _ref3.id,
|
|
@@ -800,9 +810,10 @@ var _SingleValue = function SingleValue(_ref3) {
|
|
|
800
810
|
}));
|
|
801
811
|
};
|
|
802
812
|
|
|
813
|
+
_SingleValue.propTypes = {};
|
|
803
814
|
_SingleValue.displayName = 'SingleValue';
|
|
804
|
-
_SingleValue.propTypes = {}; // overwrite styles of createSelectStyles
|
|
805
815
|
|
|
816
|
+
// overwrite styles of createSelectStyles
|
|
806
817
|
var createCurrencySelectStyles = function createCurrencySelectStyles(_ref4, theme) {
|
|
807
818
|
var hasWarning = _ref4.hasWarning,
|
|
808
819
|
hasError = _ref4.hasError,
|
|
@@ -948,7 +959,7 @@ var parseRawAmountToNumber = function parseRawAmountToNumber(rawAmount, locale)
|
|
|
948
959
|
var normalizedAmount = String(rawAmount).replace(new RegExp("[^0-9".concat(fractionsSeparator, "]"), 'g'), '') // we just keep the numbers and the fraction symbol
|
|
949
960
|
.replace(fractionsSeparator, '.'); // then we change whatever `fractionsSeparator` was to `.` so we can parse it as float
|
|
950
961
|
|
|
951
|
-
return _parseFloat__default["default"](normalizedAmount
|
|
962
|
+
return _parseFloat__default["default"](normalizedAmount);
|
|
952
963
|
}; // Turns the user input into a value the MoneyInput can pass up through onChange
|
|
953
964
|
// In case the number of fraction digits contained in "amount" exceeds the
|
|
954
965
|
// number of fraction digits the currency uses, it will emit a price of
|
|
@@ -1043,6 +1054,12 @@ var getCurrencyDropdownName = function getCurrencyDropdownName(name) {
|
|
|
1043
1054
|
return name ? "".concat(name, ".currencyCode") : undefined;
|
|
1044
1055
|
};
|
|
1045
1056
|
|
|
1057
|
+
var defaultProps = {
|
|
1058
|
+
currencies: [],
|
|
1059
|
+
horizontalConstraint: 'scale',
|
|
1060
|
+
menuPortalZIndex: 1
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1046
1063
|
var _ref = {
|
|
1047
1064
|
name: "pw7jst",
|
|
1048
1065
|
styles: "position:relative;width:100%"
|
|
@@ -1068,8 +1085,11 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1068
1085
|
amountHasFocus = _useToggleState4[0],
|
|
1069
1086
|
toggleAmountHasFocus = _useToggleState4[1];
|
|
1070
1087
|
|
|
1071
|
-
var containerRef = react$1.useRef();
|
|
1072
|
-
var amountInputRef = react$1.useRef();
|
|
1088
|
+
var containerRef = react$1.useRef(null);
|
|
1089
|
+
var amountInputRef = react$1.useRef(null);
|
|
1090
|
+
|
|
1091
|
+
if (!props.isReadOnly) ;
|
|
1092
|
+
|
|
1073
1093
|
var onFocus = props.onFocus;
|
|
1074
1094
|
var handleAmountFocus = react$1.useCallback(function () {
|
|
1075
1095
|
if (onFocus) onFocus({
|
|
@@ -1096,7 +1116,6 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1096
1116
|
if (String(formattedAmount) !== amount) {
|
|
1097
1117
|
// We need to emit an event with the now formatted value
|
|
1098
1118
|
var fakeEvent = {
|
|
1099
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1100
1119
|
persist: function persist() {},
|
|
1101
1120
|
target: {
|
|
1102
1121
|
id: MoneyInput.getAmountInputId(props.id),
|
|
@@ -1111,7 +1130,6 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1111
1130
|
var handleAmountChange = react$1.useCallback(function (event) {
|
|
1112
1131
|
if (utils.isNumberish(event.target.value)) {
|
|
1113
1132
|
onChange({
|
|
1114
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1115
1133
|
persist: function persist() {},
|
|
1116
1134
|
target: {
|
|
1117
1135
|
id: MoneyInput.getAmountInputId(props.id),
|
|
@@ -1125,7 +1143,7 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1125
1143
|
var currencyCode = option.value;
|
|
1126
1144
|
|
|
1127
1145
|
if (props.value.currencyCode !== currencyCode) {
|
|
1128
|
-
var _context6;
|
|
1146
|
+
var _context6, _amountInputRef$curre;
|
|
1129
1147
|
|
|
1130
1148
|
// When the user changes from a currency with 3 fraction digits to
|
|
1131
1149
|
// a currency with 2 fraction digits, and when the input value was
|
|
@@ -1137,10 +1155,9 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1137
1155
|
// or while the amount is invalid. In these cases, we don't attempt to
|
|
1138
1156
|
// format the amount.
|
|
1139
1157
|
|
|
1140
|
-
var nextAmount = isNaN(formattedAmount) ? props.value.amount : formattedAmount; // change currency code
|
|
1158
|
+
var nextAmount = isNaN(Number(formattedAmount)) ? props.value.amount : formattedAmount; // change currency code
|
|
1141
1159
|
|
|
1142
1160
|
var fakeCurrencyEvent = {
|
|
1143
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1144
1161
|
persist: function persist() {},
|
|
1145
1162
|
target: {
|
|
1146
1163
|
id: MoneyInput.getCurrencyDropdownId(props.id),
|
|
@@ -1152,7 +1169,6 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1152
1169
|
|
|
1153
1170
|
if (props.value.amount !== nextAmount) {
|
|
1154
1171
|
onChange({
|
|
1155
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1156
1172
|
persist: function persist() {},
|
|
1157
1173
|
target: {
|
|
1158
1174
|
id: MoneyInput.getAmountInputId(props.id),
|
|
@@ -1162,7 +1178,7 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1162
1178
|
});
|
|
1163
1179
|
}
|
|
1164
1180
|
|
|
1165
|
-
amountInputRef.current.focus();
|
|
1181
|
+
(_amountInputRef$curre = amountInputRef.current) === null || _amountInputRef$curre === void 0 ? void 0 : _amountInputRef$curre.focus();
|
|
1166
1182
|
}
|
|
1167
1183
|
}, [intl.locale, onChange, props.id, props.name, props.value.amount, props.value.currencyCode]);
|
|
1168
1184
|
var handleCurrencyFocus = react$1.useCallback(function () {
|
|
@@ -1217,9 +1233,11 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1217
1233
|
var isHighPrecision = !MoneyInput.isEmpty(props.value) && MoneyInput.isHighPrecision(props.value, intl.locale);
|
|
1218
1234
|
var onBlur = props.onBlur;
|
|
1219
1235
|
var handleContainerBlur = react$1.useCallback(function (event) {
|
|
1236
|
+
var _containerRef$current;
|
|
1237
|
+
|
|
1220
1238
|
// ensures that both fields are marked as touched when one of them
|
|
1221
1239
|
// is blurred
|
|
1222
|
-
if (typeof onBlur === 'function' && !containerRef.current.contains(event.relatedTarget)) {
|
|
1240
|
+
if (typeof onBlur === 'function' && !((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(event.relatedTarget))) {
|
|
1223
1241
|
onBlur({
|
|
1224
1242
|
target: {
|
|
1225
1243
|
id: MoneyInput.getCurrencyDropdownId(props.id),
|
|
@@ -1257,19 +1275,15 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1257
1275
|
isDisabled: props.isDisabled,
|
|
1258
1276
|
isSearchable: false,
|
|
1259
1277
|
components: {
|
|
1260
|
-
// eslint-disable-next-line react/display-name
|
|
1261
1278
|
SingleValue: function SingleValue(innerProps) {
|
|
1262
1279
|
return jsxRuntime.jsx(_SingleValue, _objectSpread(_objectSpread({}, innerProps), {}, {
|
|
1263
1280
|
id: id
|
|
1264
1281
|
}));
|
|
1265
1282
|
},
|
|
1266
|
-
// eslint-disable-next-line react/display-name
|
|
1267
1283
|
Input: function Input(ownProps) {
|
|
1268
|
-
return (
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
}))
|
|
1272
|
-
);
|
|
1284
|
+
return jsxRuntime.jsx(Select.components.Input, _objectSpread(_objectSpread({}, ownProps), {}, {
|
|
1285
|
+
readOnly: props.isReadOnly
|
|
1286
|
+
}));
|
|
1273
1287
|
},
|
|
1274
1288
|
DropdownIndicator: selectUtils.DropdownIndicator
|
|
1275
1289
|
},
|
|
@@ -1338,6 +1352,7 @@ var MoneyInput = function MoneyInput(props) {
|
|
|
1338
1352
|
});
|
|
1339
1353
|
};
|
|
1340
1354
|
|
|
1355
|
+
MoneyInput.propTypes = {};
|
|
1341
1356
|
MoneyInput.displayName = 'MoneyInput';
|
|
1342
1357
|
MoneyInput.getAmountInputId = getAmountInputName;
|
|
1343
1358
|
MoneyInput.getCurrencyDropdownId = getCurrencyDropdownName;
|
|
@@ -1377,16 +1392,11 @@ MoneyInput.isTouched = function (touched) {
|
|
|
1377
1392
|
return Boolean(touched && touched.currencyCode && touched.amount);
|
|
1378
1393
|
};
|
|
1379
1394
|
|
|
1380
|
-
MoneyInput.
|
|
1381
|
-
MoneyInput.defaultProps = {
|
|
1382
|
-
currencies: [],
|
|
1383
|
-
horizontalConstraint: 'scale',
|
|
1384
|
-
menuPortalZIndex: 1
|
|
1385
|
-
};
|
|
1395
|
+
MoneyInput.defaultProps = defaultProps;
|
|
1386
1396
|
var MoneyInput$1 = MoneyInput;
|
|
1387
1397
|
|
|
1388
1398
|
// NOTE: This string will be replaced on build time with the package version.
|
|
1389
|
-
var version = "
|
|
1399
|
+
var version = "13.0.0";
|
|
1390
1400
|
|
|
1391
1401
|
exports["default"] = MoneyInput$1;
|
|
1392
1402
|
exports.version = version;
|