@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 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
@@ -1,6 +1,4 @@
1
- import React from 'react';
2
- import '@synerise/ds-core/dist/js/style';
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;
@@ -1,154 +1,112 @@
1
- var _excluded = ["label", "description", "errorText", "raw", "error", "prefixel", "suffixel", "style", "tooltip", "tooltipConfig", "value", "defaultValue", "valueFormatOptions", "onChange", "autoResize", "autoResizeProps"];
2
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
- import { v4 as uuid } from 'uuid';
6
- import { useDataFormat } from '@synerise/ds-core';
7
- import '@synerise/ds-core/dist/js/style';
8
- import FormField from '@synerise/ds-form-field';
9
- import { AutosizeWrapper } from '@synerise/ds-input';
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
- import { formatNumber, parseFormattedNumber } from './utils/inputNumber.utils';
14
- var AUTOSIZE_EXTRA_WIDTH = 45;
15
- var InputNumber = function InputNumber(_ref) {
16
- var label = _ref.label,
17
- description = _ref.description,
18
- errorText = _ref.errorText,
19
- raw = _ref.raw,
20
- error = _ref.error,
21
- prefixel = _ref.prefixel,
22
- suffixel = _ref.suffixel,
23
- style = _ref.style,
24
- tooltip = _ref.tooltip,
25
- tooltipConfig = _ref.tooltipConfig,
26
- value = _ref.value,
27
- defaultValue = _ref.defaultValue,
28
- valueFormatOptions = _ref.valueFormatOptions,
29
- onChange = _ref.onChange,
30
- autoResize = _ref.autoResize,
31
- autoResizeProps = _ref.autoResizeProps,
32
- antdProps = _objectWithoutPropertiesLoose(_ref, _excluded);
33
- var _useDataFormat = useDataFormat(),
34
- formatValue = _useDataFormat.formatValue,
35
- thousandDelimiter = _useDataFormat.thousandDelimiter,
36
- decimalDelimiter = _useDataFormat.decimalDelimiter;
37
- var _useState = useState(''),
38
- displayValue = _useState[0],
39
- setDisplayValue = _useState[1];
40
- var _useState2 = useState(value != null ? value : defaultValue),
41
- localValue = _useState2[0],
42
- setLocalValue = _useState2[1];
43
- var antdInputRef = useRef(null);
44
- var inputRef = useRef(null);
45
- var inputNumberRef = useRef(null);
46
- var elementRef = useRef(null);
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
- var id = useMemo(function () {
55
- return uuid();
56
- }, []);
57
- var showError = Boolean(error || errorText);
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
- var parser = useCallback(function (inputValue) {
63
- return parseFloat("" + parseFormattedNumber(inputValue, formatValue, thousandDelimiter, decimalDelimiter));
54
+ const parser = useCallback((inputValue) => {
55
+ return parseFloat(`${parseFormattedNumber(inputValue, formatValue, thousandDelimiter, decimalDelimiter)}`);
64
56
  }, [formatValue, thousandDelimiter, decimalDelimiter]);
65
- var handleOnChange = useCallback(function (changedValue) {
66
- var formattedValue = formatter(changedValue);
67
- var parsedFormattedValue = parser(formattedValue);
68
- var valueAsNumber = typeof parsedFormattedValue === 'string' ? parseFloat(parsedFormattedValue) : parsedFormattedValue;
69
- var resultValue = Number.isNaN(valueAsNumber) ? defaultValue : valueAsNumber;
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 != null ? resultValue : null);
64
+ onChange && onChange(resultValue ?? null);
73
65
  }, [formatter, parser, defaultValue, onChange]);
74
- useEffect(function () {
75
- var input = antdInputRef.current;
76
- var cancelNonNumeric = function cancelNonNumeric(event) {
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('keypress', cancelNonNumeric);
74
+ input.addEventListener("keypress", cancelNonNumeric);
83
75
  }
84
- return function () {
76
+ return () => {
85
77
  if (input) {
86
- input.removeEventListener('keypress', cancelNonNumeric);
78
+ input.removeEventListener("keypress", cancelNonNumeric);
87
79
  }
88
80
  };
89
81
  });
90
- var stretchToFit = autoResize && autoResize !== true && Boolean(autoResize.stretchToFit);
91
- var handlePreAutosize = useCallback(function () {
92
- var _inputRef$current;
93
- scrollLeftRef.current = ((_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.scrollLeft) || 0;
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
- var handleAutosize = useCallback(function () {
97
- var parentRect = elementRef.current && elementRef.current.getBoundingClientRect();
98
- if (stretchToFit && inputNumberRef.current && parentRect != null && parentRect.width) {
99
- inputNumberRef.current.style.maxWidth = (parentRect == null ? void 0 : parentRect.width) + "px";
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
- var handleWrapperToResize = useCallback(function () {
94
+ const handleWrapperToResize = useCallback(() => {
104
95
  handlePreAutosize();
105
96
  handleAutosize();
106
97
  }, [handleAutosize, handlePreAutosize]);
107
- var transformRef = useCallback(function (element) {
98
+ const transformRef = useCallback((element) => {
108
99
  inputNumberRef.current = element;
109
- return element.querySelector('input');
100
+ return element.querySelector("input");
110
101
  }, []);
111
102
  useResizeObserver(elementRef, handleWrapperToResize);
112
- var rawInput = /*#__PURE__*/React.createElement(S.InputNumberWrapper, {
113
- style: style
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 /*#__PURE__*/React.createElement(S.InputNumberContainer, null, rawInput);
106
+ return /* @__PURE__ */ jsx(InputNumberContainer, { children: rawInput });
142
107
  }
143
- return /*#__PURE__*/React.createElement(S.InputNumberContainer, {
144
- autoResize: autoResize
145
- }, /*#__PURE__*/React.createElement(FormField, {
146
- id: id,
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 { type InputNumberProps } from 'antd/lib/input-number';
2
- import React from 'react';
3
- import { type ThemeProps } from '@synerise/ds-core';
4
- import { type AutoResizeProp } from '@synerise/ds-input';
5
- export declare const InputNumberContainer: import("styled-components").StyledComponent<"div", any, {
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("styled-components").StyledComponent<"div", any, {
8
+ export declare const InputNumberAutosize: import('styled-components').StyledComponent<"div", any, {
9
9
  autoResize?: AutoResizeProp;
10
10
  }, never>;
11
- export declare const AntdInputNumber: import("styled-components").StyledComponent<React.ForwardRefExoticComponent<InputNumberProps<number> & React.RefAttributes<HTMLInputElement>>, any, {
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("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>;
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
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import BaseAntInputNumber from 'antd/lib/input-number';
3
- import React, { forwardRef } from 'react';
4
- import styled from 'styled-components';
5
- import { autoresizeConfObjToCss } from '@synerise/ds-input/dist/Input.styles';
6
- export var InputNumberContainer = styled.div.withConfig({
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:", ";}"], function (props) {
10
- return props.autoResize ? '0' : '6px 11px';
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;}"], function (props) {
16
- return props.autoResize ? '100%' : '200px';
17
- }, function (props) {
18
- return autoresizeConfObjToCss(_extends({}, props, {
19
- boxSizing: 'border-box'
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;}"], function (props) {
31
- return props.theme.palette['grey-700'];
32
- }, function (props) {
33
- return !!props.error && "\n background: " + props.theme.palette['red-050'] + ";\n border: 0;\n ";
34
- }, function (props) {
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;"], function (props) {
41
- return props.theme.palette['grey-300'];
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;"], function (props) {
47
- return props.theme.palette['grey-300'];
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 type { InputNumberProps as AntdInputNumberProps } from 'antd/lib/input-number';
2
- import type { ReactNode } from 'react';
3
- import type { NumberToFormatOptions } from '@synerise/ds-core';
4
- import type { FormFieldCommonProps } from '@synerise/ds-form-field';
5
- import { type AutoResizeProp, type AutosizeInputProps } from '@synerise/ds-input';
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
- export {};
1
+
File without changes
@@ -1,4 +1,4 @@
1
- import { type Delimiter } from '@synerise/ds-core';
1
+ import { Delimiter } from '@synerise/ds-core';
2
2
  export declare const MAXIMUM_FRACTION_DIGITS = 20;
3
3
  export declare const NUMBER_DELIMITER: Delimiter;
4
4
  export declare const MAXIMUM_NUMBER_DIGITS = 15;
@@ -1,3 +1,8 @@
1
- export var MAXIMUM_FRACTION_DIGITS = 20;
2
- export var NUMBER_DELIMITER = '.';
3
- export var MAXIMUM_NUMBER_DIGITS = 15;
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
@@ -1 +1,4 @@
1
- export { default } from './InputNumber';
1
+ import { default as default2 } from "./InputNumber.js";
2
+ export {
3
+ default2 as default
4
+ };
package/dist/modules.d.js CHANGED
@@ -1 +1 @@
1
- import '@testing-library/jest-dom';
1
+ import "@testing-library/jest-dom";
File without changes
@@ -1,5 +1,5 @@
1
- import { type ReactText } from 'react';
2
- import { type Delimiter, type NumberToFormatOptions } from '@synerise/ds-core';
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
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import { MAXIMUM_FRACTION_DIGITS, MAXIMUM_NUMBER_DIGITS, NUMBER_DELIMITER } from '../constants/inputNumber.constants';
3
-
4
- // input case 1: not formatted number string (on input change)
5
- // input case 2: not formatted number (on blur)
6
- // output: formatted number string with decimal char
7
- export var formatNumber = function formatNumber(value, formatValue, notationThousandDelimiter, notationDecimalDelimiter, valueFormatOptions) {
8
- var _value$match, _value$match2;
9
- if (value === undefined || value === '' || value === null) {
10
- return '';
11
- }
12
- if (value === '-') {
13
- return '-';
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
- var result = '';
22
- var lastChar = value == null ? void 0 : value.slice(-1);
23
- var numberResult = parseFloat(value);
24
- var notationDecimalChar = lastChar === NUMBER_DELIMITER ? notationDecimalDelimiter : '';
25
- var zerosAtTheEnd = (_value$match = value.match(new RegExp('0+$'))) == null ? void 0 : _value$match[0];
26
- var zerosWithDecimalDelimiterAtTheEnd = (_value$match2 = value.match(new RegExp("\\" + NUMBER_DELIMITER + "0+$"))) == null ? void 0 : _value$match2[0];
27
- var numberDelimiterExists = new RegExp("\\" + NUMBER_DELIMITER).test(value);
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 = "" + result + notationDecimalChar;
27
+ result = `${result}${notationDecimalChar}`;
33
28
  if (zerosWithDecimalDelimiterAtTheEnd) {
34
- result = "" + result + zerosWithDecimalDelimiterAtTheEnd;
29
+ result = `${result}${zerosWithDecimalDelimiterAtTheEnd}`;
35
30
  } else if (zerosAtTheEnd && numberDelimiterExists) {
36
- result = "" + result + zerosAtTheEnd;
31
+ result = `${result}${zerosAtTheEnd}`;
37
32
  }
38
33
  return result;
39
34
  };
40
-
41
- // input: formatted number string
42
- // output: not formatted number string with decimal char
43
- export var parseFormattedNumber = function parseFormattedNumber(value, formatValue, notationThousandDelimiter, notationDecimalDelimiter) {
44
- if (value === undefined || value === '') {
45
- return '';
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("\\" + NUMBER_DELIMITER, 'g')) || []).length > 1) {
56
- var lastDecimalDelimiterIndex = result.lastIndexOf(NUMBER_DELIMITER);
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.34",
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": "pnpm run build:js && pnpm run build:css && pnpm run defs",
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": "pnpm run build:js -- --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.9",
39
- "@synerise/ds-input": "^1.6.9",
40
- "@synerise/ds-utils": "^1.7.0",
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": "8efc031fa688c0b87c7b3915bae93546bb63bcac"
49
+ "gitHead": "e4ecca8944fc9b41c1b9d59c8bcad5e5e2013225"
50
50
  }