@synerise/ds-input-number 0.8.15 → 0.8.17

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.8.17](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.16...@synerise/ds-input-number@0.8.17) (2023-07-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **input-number:** pass formatted and parsed (validated) val to onchange ([6caa1bf](https://github.com/Synerise/synerise-design/commit/6caa1bf5d7e4ab3fd52861d8252e4c33ae950232))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.8.16](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.15...@synerise/ds-input-number@0.8.16) (2023-07-26)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **input-number:** allow minus sign as valid value ([a04e032](https://github.com/Synerise/synerise-design/commit/a04e0322df969ac1f199ab2448b0a50dc550a2cc))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.8.15](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.14...@synerise/ds-input-number@0.8.15) (2023-07-17)
7
29
 
8
30
  **Note:** Version bump only for package @synerise/ds-input-number
package/README.md CHANGED
@@ -25,7 +25,7 @@ Input-Number UI Component
25
25
  | label | Input label | string | - |
26
26
  | max | Max value | number | Infinity |
27
27
  | min | Min value | number | -Infinity |
28
- | onChange | The callback triggered when the value is changed. | (value: number / string) => void |
28
+ | onChange | The callback triggered when the value is changed. The return value is either a number or empty string '' if NaN | (value: number / string) => void |
29
29
  | onPressEnter | The callback function that is triggered when Enter key is pressed. | (e:Event) => void |
30
30
  | parser | Specifies the value extracted from formatter | (val: number / string) => string | - |
31
31
  | precision | Precision of input value | number | - |
@@ -1,4 +1,4 @@
1
- var _excluded = ["label", "description", "errorText", "raw", "error", "prefixel", "suffixel", "style", "tooltip", "tooltipConfig", "valueFormatOptions"];
1
+ var _excluded = ["label", "description", "errorText", "raw", "error", "prefixel", "suffixel", "style", "tooltip", "tooltipConfig", "valueFormatOptions", "onChange"];
2
2
 
3
3
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
 
@@ -26,6 +26,7 @@ var InputNumber = function InputNumber(_ref) {
26
26
  tooltip = _ref.tooltip,
27
27
  tooltipConfig = _ref.tooltipConfig,
28
28
  valueFormatOptions = _ref.valueFormatOptions,
29
+ onChange = _ref.onChange,
29
30
  antdProps = _objectWithoutPropertiesLoose(_ref, _excluded);
30
31
 
31
32
  var _useDataFormat = useDataFormat(),
@@ -33,7 +34,6 @@ var InputNumber = function InputNumber(_ref) {
33
34
  thousandDelimiter = _useDataFormat.thousandDelimiter,
34
35
  decimalDelimiter = _useDataFormat.decimalDelimiter;
35
36
 
36
- formatValue(new Date(), {});
37
37
  var id = React.useMemo(function () {
38
38
  return uuid();
39
39
  }, []);
@@ -44,6 +44,13 @@ var InputNumber = function InputNumber(_ref) {
44
44
  var parser = React.useCallback(function (value) {
45
45
  return parseFormattedNumber(value, formatValue, thousandDelimiter, decimalDelimiter);
46
46
  }, [formatValue, thousandDelimiter, decimalDelimiter]);
47
+ var handleOnChange = React.useCallback(function (value) {
48
+ var formattedValue = formatter(value);
49
+ var parsedFormattedValue = parser(formattedValue);
50
+ var valueAsNumber = typeof parsedFormattedValue === 'string' ? parseFloat(parsedFormattedValue) : parsedFormattedValue;
51
+ var resultValue = Number.isNaN(valueAsNumber) ? '' : valueAsNumber;
52
+ onChange && onChange(resultValue);
53
+ }, [onChange, formatter, parser]);
47
54
  return /*#__PURE__*/React.createElement(S.InputNumberContainer, null, label && !raw && /*#__PURE__*/React.createElement(S.ContentAbove, null, /*#__PURE__*/React.createElement(S.Label, {
48
55
  htmlFor: id
49
56
  }, label, (tooltip || tooltipConfig) && /*#__PURE__*/React.createElement(Tooltip, _extends({
@@ -59,6 +66,7 @@ var InputNumber = function InputNumber(_ref) {
59
66
  suffixel: !!suffixel,
60
67
  style: style
61
68
  }, !!prefixel && /*#__PURE__*/React.createElement(S.Prefixel, null, prefixel), /*#__PURE__*/React.createElement(S.AntdInputNumber, _extends({}, antdProps, {
69
+ onChange: handleOnChange,
62
70
  id: id,
63
71
  error: showError,
64
72
  className: showError ? 'error' : undefined,
@@ -12,6 +12,7 @@ export var formatNumber = function formatNumber(value, formatValue, notationThou
12
12
  var _value$match, _value$match2;
13
13
 
14
14
  if (value === undefined || value === '') return '';
15
+ if (value === '-') return '-';
15
16
 
16
17
  var formatOptions = _objectSpread({
17
18
  maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-input-number",
3
- "version": "0.8.15",
3
+ "version": "0.8.17",
4
4
  "description": "Input-Number UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,7 +33,7 @@
33
33
  "types": "dist/index.d.ts",
34
34
  "dependencies": {
35
35
  "@synerise/ds-icon": "^0.53.0",
36
- "@synerise/ds-tooltip": "^0.13.7",
36
+ "@synerise/ds-tooltip": "^0.14.0",
37
37
  "@synerise/ds-utils": "^0.24.11",
38
38
  "uuid": "^7.0.2"
39
39
  },
@@ -45,5 +45,5 @@
45
45
  "devDependencies": {
46
46
  "@types/uuid": "7.0.0"
47
47
  },
48
- "gitHead": "b2df0b45094602990b6ef46e20fb0eb655baf126"
48
+ "gitHead": "17f1b9fd56fd6bae3d8c500ebb4406c8b35ef712"
49
49
  }