@synerise/ds-input-number 1.2.34 → 1.2.35
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/CHANGELOG.md +4 -0
- package/dist/InputNumber.d.ts +2 -4
- package/dist/InputNumber.js +79 -121
- package/dist/InputNumber.styles.d.ts +10 -10
- package/dist/InputNumber.styles.js +32 -40
- package/dist/InputNumber.types.d.ts +5 -5
- package/dist/InputNumber.types.js +1 -1
- package/dist/assets/style/index-tn0RQdqM.css +0 -0
- package/dist/constants/inputNumber.constants.d.ts +1 -1
- package/dist/constants/inputNumber.constants.js +8 -3
- package/dist/index.js +4 -1
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/dist/utils/inputNumber.utils.d.ts +2 -2
- package/dist/utils/inputNumber.utils.js +37 -41
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
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
|
+
## [1.2.35](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@1.2.34...@synerise/ds-input-number@1.2.35) (2026-03-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-input-number
|
|
9
|
+
|
|
6
10
|
## [1.2.34](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@1.2.33...@synerise/ds-input-number@1.2.34) (2026-03-20)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @synerise/ds-input-number
|
package/dist/InputNumber.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '
|
|
3
|
-
import { type InputNumberProps } from './InputNumber.types';
|
|
4
|
-
import './style/index.less';
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { InputNumberProps } from './InputNumber.types';
|
|
5
3
|
declare const InputNumber: ({ label, description, errorText, raw, error, prefixel, suffixel, style, tooltip, tooltipConfig, value, defaultValue, valueFormatOptions, onChange, autoResize, autoResizeProps, ...antdProps }: InputNumberProps) => React.JSX.Element;
|
|
6
4
|
export default InputNumber;
|
package/dist/InputNumber.js
CHANGED
|
@@ -1,154 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import { useResizeObserver } from '@synerise/ds-utils';
|
|
11
|
-
import * as S from './InputNumber.styles';
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useEffect, useMemo, useCallback } from "react";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
import { useDataFormat } from "@synerise/ds-core";
|
|
5
|
+
import FormField from "@synerise/ds-form-field";
|
|
6
|
+
import { AutosizeWrapper } from "@synerise/ds-input";
|
|
7
|
+
import { useResizeObserver } from "@synerise/ds-utils";
|
|
8
|
+
import { InputNumberWrapper, AntdInputNumber, InputNumberAutosize, InputNumberContainer } from "./InputNumber.styles.js";
|
|
9
|
+
import { formatNumber, parseFormattedNumber } from "./utils/inputNumber.utils.js";
|
|
12
10
|
import "./style/index.css";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
formatValue
|
|
35
|
-
thousandDelimiter
|
|
36
|
-
decimalDelimiter
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var scrollLeftRef = useRef(0);
|
|
48
|
-
useEffect(function () {
|
|
49
|
-
if (value !== undefined && value !== localValue) {
|
|
11
|
+
const AUTOSIZE_EXTRA_WIDTH = 45;
|
|
12
|
+
const InputNumber = ({
|
|
13
|
+
label,
|
|
14
|
+
description,
|
|
15
|
+
errorText,
|
|
16
|
+
raw,
|
|
17
|
+
error,
|
|
18
|
+
prefixel,
|
|
19
|
+
suffixel,
|
|
20
|
+
style,
|
|
21
|
+
tooltip,
|
|
22
|
+
tooltipConfig,
|
|
23
|
+
value,
|
|
24
|
+
defaultValue,
|
|
25
|
+
valueFormatOptions,
|
|
26
|
+
onChange,
|
|
27
|
+
autoResize,
|
|
28
|
+
autoResizeProps,
|
|
29
|
+
...antdProps
|
|
30
|
+
}) => {
|
|
31
|
+
const {
|
|
32
|
+
formatValue,
|
|
33
|
+
thousandDelimiter,
|
|
34
|
+
decimalDelimiter
|
|
35
|
+
} = useDataFormat();
|
|
36
|
+
const [displayValue, setDisplayValue] = useState("");
|
|
37
|
+
const [localValue, setLocalValue] = useState(value ?? defaultValue);
|
|
38
|
+
const antdInputRef = useRef(null);
|
|
39
|
+
const inputRef = useRef(null);
|
|
40
|
+
const inputNumberRef = useRef(null);
|
|
41
|
+
const elementRef = useRef(null);
|
|
42
|
+
const scrollLeftRef = useRef(0);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (value !== void 0 && value !== localValue) {
|
|
50
45
|
setLocalValue(value);
|
|
51
46
|
}
|
|
52
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
47
|
}, [value]);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var formatter = useCallback(function (inputValue) {
|
|
59
|
-
var formatted = formatNumber(inputValue, formatValue, thousandDelimiter, decimalDelimiter, valueFormatOptions);
|
|
48
|
+
const id = useMemo(() => v4(), []);
|
|
49
|
+
const showError = Boolean(error || errorText);
|
|
50
|
+
const formatter = useCallback((inputValue) => {
|
|
51
|
+
const formatted = formatNumber(inputValue, formatValue, thousandDelimiter, decimalDelimiter, valueFormatOptions);
|
|
60
52
|
return formatted;
|
|
61
53
|
}, [formatValue, valueFormatOptions, thousandDelimiter, decimalDelimiter]);
|
|
62
|
-
|
|
63
|
-
return parseFloat(
|
|
54
|
+
const parser = useCallback((inputValue) => {
|
|
55
|
+
return parseFloat(`${parseFormattedNumber(inputValue, formatValue, thousandDelimiter, decimalDelimiter)}`);
|
|
64
56
|
}, [formatValue, thousandDelimiter, decimalDelimiter]);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
const handleOnChange = useCallback((changedValue) => {
|
|
58
|
+
const formattedValue = formatter(changedValue);
|
|
59
|
+
const parsedFormattedValue = parser(formattedValue);
|
|
60
|
+
const valueAsNumber = typeof parsedFormattedValue === "string" ? parseFloat(parsedFormattedValue) : parsedFormattedValue;
|
|
61
|
+
const resultValue = Number.isNaN(valueAsNumber) ? defaultValue : valueAsNumber;
|
|
70
62
|
setDisplayValue(formattedValue);
|
|
71
63
|
setLocalValue(resultValue);
|
|
72
|
-
onChange && onChange(resultValue
|
|
64
|
+
onChange && onChange(resultValue ?? null);
|
|
73
65
|
}, [formatter, parser, defaultValue, onChange]);
|
|
74
|
-
useEffect(
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const input = antdInputRef.current;
|
|
68
|
+
const cancelNonNumeric = (event) => {
|
|
77
69
|
if (!/^-?\d*(\.|,)?\d*$/i.test(event.key)) {
|
|
78
70
|
event.preventDefault();
|
|
79
71
|
}
|
|
80
72
|
};
|
|
81
73
|
if (input) {
|
|
82
|
-
input.addEventListener(
|
|
74
|
+
input.addEventListener("keypress", cancelNonNumeric);
|
|
83
75
|
}
|
|
84
|
-
return
|
|
76
|
+
return () => {
|
|
85
77
|
if (input) {
|
|
86
|
-
input.removeEventListener(
|
|
78
|
+
input.removeEventListener("keypress", cancelNonNumeric);
|
|
87
79
|
}
|
|
88
80
|
};
|
|
89
81
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
inputNumberRef.current && inputNumberRef.current.style.removeProperty('max-width');
|
|
82
|
+
const stretchToFit = autoResize && autoResize !== true && Boolean(autoResize.stretchToFit);
|
|
83
|
+
const handlePreAutosize = useCallback(() => {
|
|
84
|
+
scrollLeftRef.current = inputRef.current?.scrollLeft || 0;
|
|
85
|
+
inputNumberRef.current && inputNumberRef.current.style.removeProperty("max-width");
|
|
95
86
|
}, []);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (stretchToFit && inputNumberRef.current && parentRect
|
|
99
|
-
inputNumberRef.current.style.maxWidth =
|
|
87
|
+
const handleAutosize = useCallback(() => {
|
|
88
|
+
const parentRect = elementRef.current && elementRef.current.getBoundingClientRect();
|
|
89
|
+
if (stretchToFit && inputNumberRef.current && parentRect?.width) {
|
|
90
|
+
inputNumberRef.current.style.maxWidth = `${parentRect?.width}px`;
|
|
100
91
|
inputRef.current && inputRef.current.scrollTo(scrollLeftRef.current, 0);
|
|
101
92
|
}
|
|
102
93
|
}, [stretchToFit]);
|
|
103
|
-
|
|
94
|
+
const handleWrapperToResize = useCallback(() => {
|
|
104
95
|
handlePreAutosize();
|
|
105
96
|
handleAutosize();
|
|
106
97
|
}, [handleAutosize, handlePreAutosize]);
|
|
107
|
-
|
|
98
|
+
const transformRef = useCallback((element) => {
|
|
108
99
|
inputNumberRef.current = element;
|
|
109
|
-
return element.querySelector(
|
|
100
|
+
return element.querySelector("input");
|
|
110
101
|
}, []);
|
|
111
102
|
useResizeObserver(elementRef, handleWrapperToResize);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}, /*#__PURE__*/React.createElement(S.AntdInputNumber, _extends({}, antdProps, {
|
|
115
|
-
ref: antdInputRef,
|
|
116
|
-
onChange: handleOnChange,
|
|
117
|
-
addonBefore: prefixel,
|
|
118
|
-
addonAfter: suffixel,
|
|
119
|
-
id: id,
|
|
120
|
-
error: showError,
|
|
121
|
-
className: showError ? 'error' : undefined,
|
|
122
|
-
autoComplete: "off",
|
|
123
|
-
formatter: formatter,
|
|
124
|
-
parser: parser,
|
|
125
|
-
defaultValue: defaultValue,
|
|
126
|
-
value: localValue,
|
|
127
|
-
decimalSeparator: decimalDelimiter
|
|
128
|
-
})));
|
|
129
|
-
var autoSizeInput = /*#__PURE__*/React.createElement(S.InputNumberAutosize, {
|
|
130
|
-
ref: elementRef,
|
|
131
|
-
autoResize: autoResize
|
|
132
|
-
}, /*#__PURE__*/React.createElement(AutosizeWrapper, _extends({}, autoResizeProps, {
|
|
133
|
-
extraWidth: AUTOSIZE_EXTRA_WIDTH,
|
|
134
|
-
autoResize: !!autoResize,
|
|
135
|
-
value: displayValue,
|
|
136
|
-
transformRef: transformRef,
|
|
137
|
-
preAutosize: handlePreAutosize,
|
|
138
|
-
onAutosize: handleAutosize
|
|
139
|
-
}), rawInput));
|
|
103
|
+
const rawInput = /* @__PURE__ */ jsx(InputNumberWrapper, { style, children: /* @__PURE__ */ jsx(AntdInputNumber, { ...antdProps, ref: antdInputRef, onChange: handleOnChange, addonBefore: prefixel, addonAfter: suffixel, id, error: showError, className: showError ? "error" : void 0, autoComplete: "off", formatter, parser, defaultValue, value: localValue, decimalSeparator: decimalDelimiter }) });
|
|
104
|
+
const autoSizeInput = /* @__PURE__ */ jsx(InputNumberAutosize, { ref: elementRef, autoResize, children: /* @__PURE__ */ jsx(AutosizeWrapper, { ...autoResizeProps, extraWidth: AUTOSIZE_EXTRA_WIDTH, autoResize: !!autoResize, value: displayValue, transformRef, preAutosize: handlePreAutosize, onAutosize: handleAutosize, children: rawInput }) });
|
|
140
105
|
if (raw) {
|
|
141
|
-
return
|
|
106
|
+
return /* @__PURE__ */ jsx(InputNumberContainer, { children: rawInput });
|
|
142
107
|
}
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
label: label,
|
|
148
|
-
tooltip: tooltip,
|
|
149
|
-
tooltipConfig: tooltipConfig,
|
|
150
|
-
description: description,
|
|
151
|
-
errorText: errorText
|
|
152
|
-
}, autoResize ? autoSizeInput : rawInput));
|
|
108
|
+
return /* @__PURE__ */ jsx(InputNumberContainer, { autoResize, children: /* @__PURE__ */ jsx(FormField, { id, label, tooltip, tooltipConfig, description, errorText, children: autoResize ? autoSizeInput : rawInput }) });
|
|
109
|
+
};
|
|
110
|
+
export {
|
|
111
|
+
InputNumber as default
|
|
153
112
|
};
|
|
154
|
-
export default InputNumber;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export declare const InputNumberContainer: import(
|
|
1
|
+
import { InputNumberProps } from 'antd/lib/input-number';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { ThemeProps } from '@synerise/ds-core';
|
|
4
|
+
import { AutoResizeProp } from '@synerise/ds-input';
|
|
5
|
+
export declare const InputNumberContainer: import('styled-components').StyledComponent<"div", any, {
|
|
6
6
|
autoResize?: AutoResizeProp;
|
|
7
7
|
}, never>;
|
|
8
|
-
export declare const InputNumberAutosize: import(
|
|
8
|
+
export declare const InputNumberAutosize: import('styled-components').StyledComponent<"div", any, {
|
|
9
9
|
autoResize?: AutoResizeProp;
|
|
10
10
|
}, never>;
|
|
11
|
-
export declare const AntdInputNumber: import(
|
|
11
|
+
export declare const AntdInputNumber: import('styled-components').StyledComponent<React.ForwardRefExoticComponent<InputNumberProps<number> & React.RefAttributes<HTMLInputElement>>, any, {
|
|
12
12
|
error: boolean;
|
|
13
13
|
} & ThemeProps, never>;
|
|
14
|
-
export declare const Prefixel: import(
|
|
15
|
-
export declare const Suffixel: import(
|
|
16
|
-
export declare const InputNumberWrapper: import(
|
|
14
|
+
export declare const Prefixel: import('styled-components').StyledComponent<"div", any, ThemeProps, never>;
|
|
15
|
+
export declare const Suffixel: import('styled-components').StyledComponent<"div", any, ThemeProps, never>;
|
|
16
|
+
export declare const InputNumberWrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
@@ -1,52 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
import BaseAntInputNumber from
|
|
3
|
-
import
|
|
4
|
-
import styled from
|
|
5
|
-
import { autoresizeConfObjToCss } from
|
|
6
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import BaseAntInputNumber from "antd/lib/input-number";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
import { autoresizeConfObjToCss } from "@synerise/ds-input/dist/Input.styles";
|
|
6
|
+
const InputNumberContainer = /* @__PURE__ */ styled.div.withConfig({
|
|
7
7
|
displayName: "InputNumberstyles__InputNumberContainer",
|
|
8
8
|
componentId: "sc-abrul0-0"
|
|
9
|
-
})(["display:flex;flex-direction:column;align-items:stretch;justify-content:flex-start;&&& .ant-input-number-input{padding:", ";}"],
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
export var InputNumberAutosize = styled.div.withConfig({
|
|
9
|
+
})(["display:flex;flex-direction:column;align-items:stretch;justify-content:flex-start;&&& .ant-input-number-input{padding:", ";}"], (props) => props.autoResize ? "0" : "6px 11px");
|
|
10
|
+
const InputNumberAutosize = /* @__PURE__ */ styled.div.withConfig({
|
|
13
11
|
displayName: "InputNumberstyles__InputNumberAutosize",
|
|
14
12
|
componentId: "sc-abrul0-1"
|
|
15
|
-
})(["&&& .ant-input-number{width:", ";", ";grid-area:1 / 1;}input{text-indent:4px;}input.ant-input-number-input{letter-spacing:normal;font-feature-settings:'tnum' 0;font-variant-numeric:proportional-nums;}"],
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
var NumberOnlyBaseAntInputNumber = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
23
|
-
return /*#__PURE__*/React.createElement(BaseAntInputNumber, _extends({}, props, {
|
|
24
|
-
ref: ref
|
|
25
|
-
}));
|
|
26
|
-
});
|
|
27
|
-
export var AntdInputNumber = styled(NumberOnlyBaseAntInputNumber).withConfig({
|
|
13
|
+
})(["&&& .ant-input-number{width:", ";", ";grid-area:1 / 1;}input{text-indent:4px;}input.ant-input-number-input{letter-spacing:normal;font-feature-settings:'tnum' 0;font-variant-numeric:proportional-nums;}"], (props) => props.autoResize ? "100%" : "200px", (props) => autoresizeConfObjToCss({
|
|
14
|
+
...props,
|
|
15
|
+
boxSizing: "border-box"
|
|
16
|
+
}));
|
|
17
|
+
const NumberOnlyBaseAntInputNumber = forwardRef((props, ref) => /* @__PURE__ */ jsx(BaseAntInputNumber, { ...props, ref }));
|
|
18
|
+
const AntdInputNumber = /* @__PURE__ */ styled(NumberOnlyBaseAntInputNumber).withConfig({
|
|
28
19
|
displayName: "InputNumberstyles__AntdInputNumber",
|
|
29
20
|
componentId: "sc-abrul0-2"
|
|
30
|
-
})(["color:", ";input,input:focus{", ";}.ant-input-number-group-addon{background-color:", ";padding:0 12px;}"],
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return props.theme.palette['grey-050'];
|
|
36
|
-
});
|
|
37
|
-
export var Prefixel = styled.div.withConfig({
|
|
21
|
+
})(["color:", ";input,input:focus{", ";}.ant-input-number-group-addon{background-color:", ";padding:0 12px;}"], (props) => props.theme.palette["grey-700"], (props) => !!props.error && `
|
|
22
|
+
background: ${props.theme.palette["red-050"]};
|
|
23
|
+
border: 0;
|
|
24
|
+
`, (props) => props.theme.palette["grey-050"]);
|
|
25
|
+
const Prefixel = /* @__PURE__ */ styled.div.withConfig({
|
|
38
26
|
displayName: "InputNumberstyles__Prefixel",
|
|
39
27
|
componentId: "sc-abrul0-3"
|
|
40
|
-
})(["border:1px solid ", ";border-radius:3px 0 0 3px;border-right-width:0;"],
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
export var Suffixel = styled.div.withConfig({
|
|
28
|
+
})(["border:1px solid ", ";border-radius:3px 0 0 3px;border-right-width:0;"], (props) => props.theme.palette["grey-300"]);
|
|
29
|
+
const Suffixel = /* @__PURE__ */ styled.div.withConfig({
|
|
44
30
|
displayName: "InputNumberstyles__Suffixel",
|
|
45
31
|
componentId: "sc-abrul0-4"
|
|
46
|
-
})(["border:1px solid ", ";border-radius:0 3px 3px 0;border-left-width:0;"],
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
export var InputNumberWrapper = styled.div.withConfig({
|
|
32
|
+
})(["border:1px solid ", ";border-radius:0 3px 3px 0;border-left-width:0;"], (props) => props.theme.palette["grey-300"]);
|
|
33
|
+
const InputNumberWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
50
34
|
displayName: "InputNumberstyles__InputNumberWrapper",
|
|
51
35
|
componentId: "sc-abrul0-5"
|
|
52
|
-
})([""]);
|
|
36
|
+
})([""]);
|
|
37
|
+
export {
|
|
38
|
+
AntdInputNumber,
|
|
39
|
+
InputNumberAutosize,
|
|
40
|
+
InputNumberContainer,
|
|
41
|
+
InputNumberWrapper,
|
|
42
|
+
Prefixel,
|
|
43
|
+
Suffixel
|
|
44
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { InputNumberProps as AntdInputNumberProps } from 'antd/lib/input-number';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { NumberToFormatOptions } from '@synerise/ds-core';
|
|
4
|
+
import { FormFieldCommonProps } from '@synerise/ds-form-field';
|
|
5
|
+
import { AutoResizeProp, AutosizeInputProps } from '@synerise/ds-input';
|
|
6
6
|
export type InputNumberProps = AntdInputNumberProps<number> & {
|
|
7
7
|
defaultValue?: number | null;
|
|
8
8
|
error?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
File without changes
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const MAXIMUM_FRACTION_DIGITS = 20;
|
|
2
|
+
const NUMBER_DELIMITER = ".";
|
|
3
|
+
const MAXIMUM_NUMBER_DIGITS = 15;
|
|
4
|
+
export {
|
|
5
|
+
MAXIMUM_FRACTION_DIGITS,
|
|
6
|
+
MAXIMUM_NUMBER_DIGITS,
|
|
7
|
+
NUMBER_DELIMITER
|
|
8
|
+
};
|
package/dist/index.js
CHANGED
package/dist/modules.d.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReactText } from 'react';
|
|
2
|
+
import { Delimiter, NumberToFormatOptions } from '@synerise/ds-core';
|
|
3
3
|
export declare const formatNumber: (
|
|
4
4
|
/** Important: value can be null when input string is '' */
|
|
5
5
|
value: string | number | undefined | null, formatValue: (value: number, options: NumberToFormatOptions) => string, notationThousandDelimiter: Delimiter, notationDecimalDelimiter: Delimiter, valueFormatOptions?: NumberToFormatOptions) => string;
|
|
@@ -1,60 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
var formatOptions = _extends({
|
|
16
|
-
maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
|
|
17
|
-
}, valueFormatOptions);
|
|
18
|
-
if (typeof value === 'number') {
|
|
1
|
+
import { MAXIMUM_FRACTION_DIGITS, NUMBER_DELIMITER, MAXIMUM_NUMBER_DIGITS } from "../constants/inputNumber.constants.js";
|
|
2
|
+
const formatNumber = (value, formatValue, notationThousandDelimiter, notationDecimalDelimiter, valueFormatOptions) => {
|
|
3
|
+
if (value === void 0 || value === "" || value === null) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
if (value === "-") {
|
|
7
|
+
return "-";
|
|
8
|
+
}
|
|
9
|
+
const formatOptions = {
|
|
10
|
+
maximumFractionDigits: MAXIMUM_FRACTION_DIGITS,
|
|
11
|
+
...valueFormatOptions
|
|
12
|
+
};
|
|
13
|
+
if (typeof value === "number") {
|
|
19
14
|
return formatValue(value, formatOptions);
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
let result = "";
|
|
17
|
+
const lastChar = value?.slice(-1);
|
|
18
|
+
const numberResult = parseFloat(value);
|
|
19
|
+
const notationDecimalChar = lastChar === NUMBER_DELIMITER ? notationDecimalDelimiter : "";
|
|
20
|
+
const zerosAtTheEnd = value.match(new RegExp("0+$"))?.[0];
|
|
21
|
+
const zerosWithDecimalDelimiterAtTheEnd = value.match(new RegExp(`\\${NUMBER_DELIMITER}0+$`))?.[0];
|
|
22
|
+
const numberDelimiterExists = new RegExp(`\\${NUMBER_DELIMITER}`).test(value);
|
|
28
23
|
if (Number.isNaN(numberResult)) {
|
|
29
|
-
return
|
|
24
|
+
return "";
|
|
30
25
|
}
|
|
31
26
|
result = formatValue(numberResult, formatOptions);
|
|
32
|
-
result =
|
|
27
|
+
result = `${result}${notationDecimalChar}`;
|
|
33
28
|
if (zerosWithDecimalDelimiterAtTheEnd) {
|
|
34
|
-
result =
|
|
29
|
+
result = `${result}${zerosWithDecimalDelimiterAtTheEnd}`;
|
|
35
30
|
} else if (zerosAtTheEnd && numberDelimiterExists) {
|
|
36
|
-
result =
|
|
31
|
+
result = `${result}${zerosAtTheEnd}`;
|
|
37
32
|
}
|
|
38
33
|
return result;
|
|
39
34
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
var result = value;
|
|
48
|
-
result = result.split(notationThousandDelimiter).join('');
|
|
35
|
+
const parseFormattedNumber = (value, formatValue, notationThousandDelimiter, notationDecimalDelimiter) => {
|
|
36
|
+
if (value === void 0 || value === "") {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
let result = value;
|
|
40
|
+
result = result.split(notationThousandDelimiter).join("");
|
|
49
41
|
if (result.length > MAXIMUM_NUMBER_DIGITS) {
|
|
50
42
|
result = result.slice(0, MAXIMUM_NUMBER_DIGITS);
|
|
51
43
|
}
|
|
52
44
|
if (notationDecimalDelimiter !== NUMBER_DELIMITER) {
|
|
53
45
|
result = result.replace(notationDecimalDelimiter, NUMBER_DELIMITER);
|
|
54
46
|
}
|
|
55
|
-
if ((result.match(new RegExp(
|
|
56
|
-
|
|
47
|
+
if ((result.match(new RegExp(`\\${NUMBER_DELIMITER}`, "g")) || []).length > 1) {
|
|
48
|
+
const lastDecimalDelimiterIndex = result.lastIndexOf(NUMBER_DELIMITER);
|
|
57
49
|
result = result.slice(0, lastDecimalDelimiterIndex);
|
|
58
50
|
}
|
|
59
51
|
return result;
|
|
60
|
-
};
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
formatNumber,
|
|
55
|
+
parseFormattedNumber
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-input-number",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.35",
|
|
4
4
|
"description": "Input-Number UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "vite build",
|
|
20
20
|
"build:css": "node ../../../scripts/style/less.js",
|
|
21
21
|
"build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
|
|
22
|
-
"build:watch": "
|
|
22
|
+
"build:watch": "vite build --watch",
|
|
23
23
|
"defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
|
|
24
24
|
"pack:ci": "pnpm pack --pack-destination ../../storybook/storybook-static/static",
|
|
25
25
|
"prepublish": "pnpm run build",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
],
|
|
36
36
|
"types": "dist/index.d.ts",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@synerise/ds-form-field": "^1.3.
|
|
39
|
-
"@synerise/ds-input": "^1.6.
|
|
40
|
-
"@synerise/ds-utils": "^1.7.
|
|
38
|
+
"@synerise/ds-form-field": "^1.3.10",
|
|
39
|
+
"@synerise/ds-input": "^1.6.10",
|
|
40
|
+
"@synerise/ds-utils": "^1.7.1",
|
|
41
41
|
"uuid": "^8.3.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"react": ">=16.9.0 <= 18.3.1",
|
|
47
47
|
"styled-components": "^5.3.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "e4ecca8944fc9b41c1b9d59c8bcad5e5e2013225"
|
|
50
50
|
}
|