@synerise/ds-input-number 0.8.33 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +11 -0
- package/dist/InputNumber.d.ts +2 -3
- package/dist/InputNumber.js +27 -11
- package/dist/InputNumber.types.d.ts +11 -9
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,17 @@
|
|
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.9.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.33...@synerise/ds-input-number@0.9.0) (2024-01-15)
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* **input-number:** handle defaultValue prop ([1b5a378](https://github.com/Synerise/synerise-design/commit/1b5a3781db429748b2926d41969d8c298b3513e5))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
6
17
|
## [0.8.33](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.32...@synerise/ds-input-number@0.8.33) (2023-12-13)
|
7
18
|
|
8
19
|
**Note:** Version bump only for package @synerise/ds-input-number
|
package/dist/InputNumber.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import * as React from 'react';
|
2
1
|
import '@synerise/ds-core/dist/js/style';
|
3
2
|
import './style/index.less';
|
4
|
-
import {
|
5
|
-
declare const InputNumber:
|
3
|
+
import { InputNumberProps } from './InputNumber.types';
|
4
|
+
declare const InputNumber: ({ label, description, errorText, raw, error, prefixel, suffixel, style, tooltip, tooltipConfig, value, defaultValue, valueFormatOptions, onChange, ...antdProps }: InputNumberProps) => JSX.Element;
|
6
5
|
export default InputNumber;
|
package/dist/InputNumber.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
var _excluded = ["label", "description", "errorText", "raw", "error", "prefixel", "suffixel", "style", "tooltip", "tooltipConfig", "valueFormatOptions", "onChange"];
|
1
|
+
var _excluded = ["label", "description", "errorText", "raw", "error", "prefixel", "suffixel", "style", "tooltip", "tooltipConfig", "value", "defaultValue", "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
|
|
5
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
6
6
|
|
7
|
-
import
|
7
|
+
import React, { useState, useCallback, useMemo, useEffect } from 'react';
|
8
8
|
import { v4 as uuid } from 'uuid';
|
9
9
|
import '@synerise/ds-core/dist/js/style';
|
10
10
|
import Tooltip from '@synerise/ds-tooltip';
|
@@ -25,6 +25,8 @@ var InputNumber = function InputNumber(_ref) {
|
|
25
25
|
style = _ref.style,
|
26
26
|
tooltip = _ref.tooltip,
|
27
27
|
tooltipConfig = _ref.tooltipConfig,
|
28
|
+
value = _ref.value,
|
29
|
+
defaultValue = _ref.defaultValue,
|
28
30
|
valueFormatOptions = _ref.valueFormatOptions,
|
29
31
|
onChange = _ref.onChange,
|
30
32
|
antdProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
@@ -34,23 +36,35 @@ var InputNumber = function InputNumber(_ref) {
|
|
34
36
|
thousandDelimiter = _useDataFormat.thousandDelimiter,
|
35
37
|
decimalDelimiter = _useDataFormat.decimalDelimiter;
|
36
38
|
|
37
|
-
var
|
39
|
+
var _useState = useState(value || defaultValue),
|
40
|
+
localValue = _useState[0],
|
41
|
+
setLocalValue = _useState[1];
|
42
|
+
|
43
|
+
useEffect(function () {
|
44
|
+
if (value && value !== localValue) {
|
45
|
+
setLocalValue(value);
|
46
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
47
|
+
|
48
|
+
}, [value]);
|
49
|
+
var id = useMemo(function () {
|
38
50
|
return uuid();
|
39
51
|
}, []);
|
40
52
|
var showError = Boolean(error || errorText);
|
41
|
-
var formatter =
|
42
|
-
|
53
|
+
var formatter = useCallback(function (inputValue) {
|
54
|
+
var formatted = formatNumber(inputValue, formatValue, thousandDelimiter, decimalDelimiter, valueFormatOptions);
|
55
|
+
return formatted;
|
43
56
|
}, [formatValue, valueFormatOptions, thousandDelimiter, decimalDelimiter]);
|
44
|
-
var parser =
|
45
|
-
return parseFormattedNumber(
|
57
|
+
var parser = useCallback(function (inputValue) {
|
58
|
+
return parseFormattedNumber(inputValue, formatValue, thousandDelimiter, decimalDelimiter);
|
46
59
|
}, [formatValue, thousandDelimiter, decimalDelimiter]);
|
47
|
-
var handleOnChange =
|
48
|
-
var formattedValue = formatter(
|
60
|
+
var handleOnChange = useCallback(function (changedValue) {
|
61
|
+
var formattedValue = formatter(changedValue);
|
49
62
|
var parsedFormattedValue = parser(formattedValue);
|
50
63
|
var valueAsNumber = typeof parsedFormattedValue === 'string' ? parseFloat(parsedFormattedValue) : parsedFormattedValue;
|
51
|
-
var resultValue = Number.isNaN(valueAsNumber) ?
|
64
|
+
var resultValue = Number.isNaN(valueAsNumber) ? defaultValue : valueAsNumber;
|
65
|
+
setLocalValue(resultValue);
|
52
66
|
onChange && onChange(resultValue);
|
53
|
-
}, [
|
67
|
+
}, [formatter, parser, defaultValue, onChange]);
|
54
68
|
return /*#__PURE__*/React.createElement(S.InputNumberContainer, null, label && !raw && /*#__PURE__*/React.createElement(S.ContentAbove, null, /*#__PURE__*/React.createElement(S.Label, {
|
55
69
|
htmlFor: id
|
56
70
|
}, label, (tooltip || tooltipConfig) && /*#__PURE__*/React.createElement(Tooltip, _extends({
|
@@ -73,6 +87,8 @@ var InputNumber = function InputNumber(_ref) {
|
|
73
87
|
autoComplete: "off",
|
74
88
|
formatter: formatter,
|
75
89
|
parser: parser,
|
90
|
+
defaultValue: defaultValue,
|
91
|
+
value: localValue,
|
76
92
|
decimalSeparator: decimalDelimiter
|
77
93
|
})), !!suffixel && /*#__PURE__*/React.createElement(S.Suffixel, null, suffixel)), (showError || description) && !raw && /*#__PURE__*/React.createElement(S.ContentBelow, null, showError && /*#__PURE__*/React.createElement(S.ErrorText, null, errorText), description && /*#__PURE__*/React.createElement(S.Description, null, description)));
|
78
94
|
};
|
@@ -1,16 +1,18 @@
|
|
1
|
-
import
|
2
|
-
import { InputNumberProps } from 'antd/lib/input-number';
|
1
|
+
import { ReactNode } from 'react';
|
2
|
+
import { InputNumberProps as AntdInputNumberProps } from 'antd/lib/input-number';
|
3
3
|
import type { TooltipProps } from '@synerise/ds-tooltip';
|
4
4
|
import { NumberToFormatOptions } from '@synerise/ds-data-format';
|
5
|
-
export
|
6
|
-
errorText?:
|
7
|
-
label?:
|
8
|
-
|
5
|
+
export type InputNumberProps = AntdInputNumberProps & {
|
6
|
+
errorText?: ReactNode;
|
7
|
+
label?: ReactNode;
|
8
|
+
defaultValue?: number;
|
9
|
+
description?: ReactNode;
|
9
10
|
error?: boolean;
|
10
|
-
prefixel?:
|
11
|
-
suffixel?:
|
11
|
+
prefixel?: ReactNode;
|
12
|
+
suffixel?: ReactNode;
|
12
13
|
raw?: boolean;
|
13
14
|
tooltip?: string;
|
14
15
|
tooltipConfig?: TooltipProps;
|
15
16
|
valueFormatOptions?: NumberToFormatOptions;
|
16
|
-
}
|
17
|
+
};
|
18
|
+
export type Props = InputNumberProps;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@synerise/ds-input-number",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.0",
|
4
4
|
"description": "Input-Number UI Component for the Synerise Design System",
|
5
5
|
"license": "ISC",
|
6
6
|
"repository": "Synerise/synerise-design",
|
@@ -34,8 +34,8 @@
|
|
34
34
|
"types": "dist/index.d.ts",
|
35
35
|
"dependencies": {
|
36
36
|
"@synerise/ds-data-format": "^0.4.6",
|
37
|
-
"@synerise/ds-icon": "^0.
|
38
|
-
"@synerise/ds-tooltip": "^0.14.
|
37
|
+
"@synerise/ds-icon": "^0.59.0",
|
38
|
+
"@synerise/ds-tooltip": "^0.14.14",
|
39
39
|
"@synerise/ds-utils": "^0.24.23",
|
40
40
|
"uuid": "^8.3.2"
|
41
41
|
},
|
@@ -50,5 +50,5 @@
|
|
50
50
|
"@testing-library/react-hooks": "^8.0.1",
|
51
51
|
"@types/uuid": "9.0.4"
|
52
52
|
},
|
53
|
-
"gitHead": "
|
53
|
+
"gitHead": "ba51e38beff83b8adba409f09311131f429ada01"
|
54
54
|
}
|