@activecollab/components 1.0.403 → 1.0.405
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/dist/cjs/components/EditableCurrency/EditableCurrency.js +76 -0
- package/dist/cjs/components/EditableCurrency/EditableCurrency.js.map +1 -0
- package/dist/cjs/components/EditableCurrency/index.js +17 -0
- package/dist/cjs/components/EditableCurrency/index.js.map +1 -0
- package/dist/cjs/components/Input/InputCurrency.js.map +1 -1
- package/dist/cjs/components/Input/InputHours.js +2 -1
- package/dist/cjs/components/Input/InputHours.js.map +1 -1
- package/dist/cjs/components/Input/InputNumber.js +27 -131
- package/dist/cjs/components/Input/InputNumber.js.map +1 -1
- package/dist/cjs/hooks/index.js +11 -0
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/useInputNumber.js +147 -0
- package/dist/cjs/hooks/useInputNumber.js.map +1 -0
- package/dist/cjs/utils/currencyUtils.js +18 -15
- package/dist/cjs/utils/currencyUtils.js.map +1 -1
- package/dist/cjs/utils/currencyUtils.test.js +2 -2
- package/dist/cjs/utils/currencyUtils.test.js.map +1 -1
- package/dist/cjs/utils/validation.js +2 -2
- package/dist/cjs/utils/validation.js.map +1 -1
- package/dist/esm/components/EditableCurrency/EditableCurrency.d.ts +4 -0
- package/dist/esm/components/EditableCurrency/EditableCurrency.d.ts.map +1 -0
- package/dist/esm/components/EditableCurrency/EditableCurrency.js +63 -0
- package/dist/esm/components/EditableCurrency/EditableCurrency.js.map +1 -0
- package/dist/esm/components/EditableCurrency/index.d.ts +2 -0
- package/dist/esm/components/EditableCurrency/index.d.ts.map +1 -0
- package/dist/esm/components/EditableCurrency/index.js +2 -0
- package/dist/esm/components/EditableCurrency/index.js.map +1 -0
- package/dist/esm/components/Input/InputCurrency.d.ts +1 -1
- package/dist/esm/components/Input/InputCurrency.d.ts.map +1 -1
- package/dist/esm/components/Input/InputCurrency.js.map +1 -1
- package/dist/esm/components/Input/InputHours.d.ts.map +1 -1
- package/dist/esm/components/Input/InputHours.js +2 -1
- package/dist/esm/components/Input/InputHours.js.map +1 -1
- package/dist/esm/components/Input/InputNumber.d.ts +1 -10
- package/dist/esm/components/Input/InputNumber.d.ts.map +1 -1
- package/dist/esm/components/Input/InputNumber.js +28 -124
- package/dist/esm/components/Input/InputNumber.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.d.ts.map +1 -1
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useInputNumber.d.ts +22 -0
- package/dist/esm/hooks/useInputNumber.d.ts.map +1 -0
- package/dist/esm/hooks/useInputNumber.js +131 -0
- package/dist/esm/hooks/useInputNumber.js.map +1 -0
- package/dist/esm/utils/currencyUtils.d.ts +8 -2
- package/dist/esm/utils/currencyUtils.d.ts.map +1 -1
- package/dist/esm/utils/currencyUtils.js +16 -14
- package/dist/esm/utils/currencyUtils.js.map +1 -1
- package/dist/esm/utils/currencyUtils.test.js +2 -2
- package/dist/esm/utils/currencyUtils.test.js.map +1 -1
- package/dist/esm/utils/validation.js +2 -2
- package/dist/esm/utils/validation.js.map +1 -1
- package/dist/index.js +171 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { currencyMultiplier, formatCurrency, numberWithSeparator } from "../utils/currencyUtils";
|
|
3
|
+
export var useInputNumber = function useInputNumber(_ref, ref) {
|
|
4
|
+
var _ref$decimalSeparator = _ref.decimalSeparator,
|
|
5
|
+
decimalSeparator = _ref$decimalSeparator === void 0 ? "." : _ref$decimalSeparator,
|
|
6
|
+
_ref$thousandSeparato = _ref.thousandSeparator,
|
|
7
|
+
thousandSeparator = _ref$thousandSeparato === void 0 ? "," : _ref$thousandSeparato,
|
|
8
|
+
disableAbbreviation = _ref.disableAbbreviation,
|
|
9
|
+
disableMacros = _ref.disableMacros,
|
|
10
|
+
decimalLength = _ref.decimalLength,
|
|
11
|
+
value = _ref.value,
|
|
12
|
+
onValueChange = _ref.onValueChange,
|
|
13
|
+
onKeyDown = _ref.onKeyDown,
|
|
14
|
+
onBlur = _ref.onBlur,
|
|
15
|
+
onFocus = _ref.onFocus,
|
|
16
|
+
step = _ref.step;
|
|
17
|
+
var _useState = useState(value),
|
|
18
|
+
formattedValue = _useState[0],
|
|
19
|
+
setFormatted = _useState[1];
|
|
20
|
+
var _useState2 = useState(value),
|
|
21
|
+
rootValue = _useState2[0],
|
|
22
|
+
setRootValue = _useState2[1];
|
|
23
|
+
var _useState3 = useState(false),
|
|
24
|
+
focused = _useState3[0],
|
|
25
|
+
setFocused = _useState3[1];
|
|
26
|
+
var handleInputBlur = function handleInputBlur() {
|
|
27
|
+
if (ref && ref.current) {
|
|
28
|
+
ref.current.blur();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var handleSelect = function handleSelect() {
|
|
32
|
+
if (ref && ref.current) {
|
|
33
|
+
ref.current.select();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var handleChange = function handleChange(e) {
|
|
37
|
+
var inputValue = e.target.value;
|
|
38
|
+
var isValidInput = false;
|
|
39
|
+
if (inputValue.startsWith("00")) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
var numericInput = disableMacros ? inputValue : inputValue.replace(/([0-9.]+)([kmbtKMBT])/, function (_, num, unit) {
|
|
43
|
+
return (parseFloat(num) * currencyMultiplier[unit.toLowerCase()]).toString();
|
|
44
|
+
});
|
|
45
|
+
var regexString = "^(-?\\d{0,9}(?:[" + thousandSeparator + "]?\\d{0,3})*(?:\\" + decimalSeparator + "\\d{0," + decimalLength + "})?)?$";
|
|
46
|
+
if (thousandSeparator === ",") {
|
|
47
|
+
isValidInput = new RegExp(regexString).test(numericInput);
|
|
48
|
+
}
|
|
49
|
+
if (thousandSeparator === ".") {
|
|
50
|
+
isValidInput = new RegExp(regexString).test(numericInput);
|
|
51
|
+
}
|
|
52
|
+
if (!isValidInput) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setFormatted(numericInput);
|
|
56
|
+
onValueChange && onValueChange(numericInput);
|
|
57
|
+
};
|
|
58
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
59
|
+
var key = e.key;
|
|
60
|
+
var _step = parseFloat(String(step));
|
|
61
|
+
if (key === "Escape") {
|
|
62
|
+
handleInputBlur();
|
|
63
|
+
}
|
|
64
|
+
if (key === "ArrowUp") {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
updateValue("increment", _step);
|
|
67
|
+
}
|
|
68
|
+
if (key === "ArrowDown") {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
updateValue("decrement", _step);
|
|
71
|
+
}
|
|
72
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "a") {
|
|
73
|
+
handleSelect();
|
|
74
|
+
}
|
|
75
|
+
if (decimalLength === 0 && e.key === decimalSeparator) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
}
|
|
78
|
+
onKeyDown && onKeyDown(e);
|
|
79
|
+
};
|
|
80
|
+
var handleBlur = function handleBlur(e) {
|
|
81
|
+
if (disableAbbreviation) {
|
|
82
|
+
setFormatted(formattedValue);
|
|
83
|
+
} else {
|
|
84
|
+
setFormatted(formatCurrency(formattedValue, thousandSeparator));
|
|
85
|
+
}
|
|
86
|
+
setRootValue(formattedValue);
|
|
87
|
+
setFocused(false);
|
|
88
|
+
onBlur && onBlur(e);
|
|
89
|
+
};
|
|
90
|
+
var handleFocus = function handleFocus(e) {
|
|
91
|
+
setFormatted(rootValue);
|
|
92
|
+
setFocused(true);
|
|
93
|
+
onFocus && onFocus(e);
|
|
94
|
+
};
|
|
95
|
+
var updateValue = function updateValue(type, step) {
|
|
96
|
+
var value = String(formattedValue);
|
|
97
|
+
var decimalPart = "";
|
|
98
|
+
var increasedValue = 0;
|
|
99
|
+
var nonDecimalPart = value.replaceAll(thousandSeparator, "");
|
|
100
|
+
if (!value) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (value.includes(decimalSeparator)) {
|
|
104
|
+
nonDecimalPart = value.slice(0, value.indexOf(decimalSeparator)).replaceAll(thousandSeparator, "");
|
|
105
|
+
}
|
|
106
|
+
if (value.includes(decimalSeparator)) {
|
|
107
|
+
decimalPart = value.slice(value.indexOf(decimalSeparator));
|
|
108
|
+
}
|
|
109
|
+
if (type === "increment") {
|
|
110
|
+
increasedValue = parseFloat(nonDecimalPart) + step;
|
|
111
|
+
} else {
|
|
112
|
+
increasedValue = parseFloat(nonDecimalPart) - step;
|
|
113
|
+
}
|
|
114
|
+
if (value.includes(decimalSeparator)) {
|
|
115
|
+
increasedValue = parseFloat(increasedValue.toFixed(decimalLength));
|
|
116
|
+
}
|
|
117
|
+
var joinedValue = numberWithSeparator(increasedValue, thousandSeparator, value.includes(thousandSeparator));
|
|
118
|
+
setFormatted(decimalPart ? joinedValue + decimalPart : joinedValue);
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
focused: focused,
|
|
122
|
+
formattedValue: formattedValue,
|
|
123
|
+
rootValue: rootValue,
|
|
124
|
+
handleChange: handleChange,
|
|
125
|
+
handleKeyDown: handleKeyDown,
|
|
126
|
+
handleBlur: handleBlur,
|
|
127
|
+
handleFocus: handleFocus,
|
|
128
|
+
onValueChange: onValueChange
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=useInputNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInputNumber.js","names":["useState","currencyMultiplier","formatCurrency","numberWithSeparator","useInputNumber","ref","decimalSeparator","thousandSeparator","disableAbbreviation","disableMacros","decimalLength","value","onValueChange","onKeyDown","onBlur","onFocus","step","formattedValue","setFormatted","rootValue","setRootValue","focused","setFocused","handleInputBlur","current","blur","handleSelect","select","handleChange","e","inputValue","target","isValidInput","startsWith","numericInput","replace","_","num","unit","parseFloat","toLowerCase","toString","regexString","RegExp","test","handleKeyDown","key","_step","String","preventDefault","updateValue","metaKey","ctrlKey","handleBlur","handleFocus","type","decimalPart","increasedValue","nonDecimalPart","replaceAll","includes","slice","indexOf","toFixed","joinedValue"],"sources":["../../../src/hooks/useInputNumber.tsx"],"sourcesContent":["import {\n useState,\n ChangeEventHandler,\n KeyboardEventHandler,\n FocusEventHandler,\n MutableRefObject,\n} from \"react\";\nimport {\n currencyMultiplier,\n formatCurrency,\n numberWithSeparator,\n} from \"../utils/currencyUtils\";\nimport type { InputProps } from \"../components\";\n\nexport type Separators = \".\" | \",\";\n\n// https://www.youtube.com/watch?v=2AilA-M6N5U\n// @TODO: Pitati foo za testove.\nexport interface InputNumberProps extends InputProps {\n decimalLength?: number;\n decimalSeparator?: Separators;\n disableAbbreviation?: boolean;\n disableMacros?: boolean;\n thousandSeparator?: Separators;\n onValueChange?: (value: string) => void;\n}\n\nexport const useInputNumber = (\n {\n decimalSeparator = \".\",\n thousandSeparator = \",\",\n disableAbbreviation,\n disableMacros,\n decimalLength,\n value,\n onValueChange,\n onKeyDown,\n onBlur,\n onFocus,\n step,\n }: InputNumberProps,\n ref: MutableRefObject<HTMLInputElement | null>\n) => {\n const [formattedValue, setFormatted] = useState(value);\n const [rootValue, setRootValue] = useState(value);\n const [focused, setFocused] = useState<boolean>(false);\n\n const handleInputBlur = () => {\n if (ref && ref.current) {\n ref.current.blur();\n }\n };\n\n const handleSelect = () => {\n if (ref && ref.current) {\n ref.current.select();\n }\n };\n\n const handleChange: ChangeEventHandler<HTMLInputElement> = (e) => {\n const inputValue = e.target.value;\n let isValidInput = false;\n\n if (inputValue.startsWith(\"00\")) {\n return;\n }\n\n const numericInput = disableMacros\n ? inputValue\n : inputValue.replace(/([0-9.]+)([kmbtKMBT])/, (_, num, unit) => {\n return (\n parseFloat(num) * currencyMultiplier[unit.toLowerCase()]\n ).toString();\n });\n\n const regexString = `^(-?\\\\d{0,9}(?:[${thousandSeparator}]?\\\\d{0,3})*(?:\\\\${decimalSeparator}\\\\d{0,${decimalLength}})?)?$`;\n\n if (thousandSeparator === \",\") {\n isValidInput = new RegExp(regexString).test(numericInput);\n }\n\n if (thousandSeparator === \".\") {\n isValidInput = new RegExp(regexString).test(numericInput);\n }\n\n if (!isValidInput) {\n return;\n }\n\n setFormatted(numericInput);\n\n onValueChange && onValueChange(numericInput);\n };\n\n const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (e) => {\n const key = e.key;\n const _step = parseFloat(String(step));\n\n if (key === \"Escape\") {\n handleInputBlur();\n }\n\n if (key === \"ArrowUp\") {\n e.preventDefault();\n\n updateValue(\"increment\", _step);\n }\n\n if (key === \"ArrowDown\") {\n e.preventDefault();\n\n updateValue(\"decrement\", _step);\n }\n\n if ((e.metaKey || e.ctrlKey) && e.key === \"a\") {\n handleSelect();\n }\n\n if (decimalLength === 0 && e.key === decimalSeparator) {\n e.preventDefault();\n }\n\n onKeyDown && onKeyDown(e);\n };\n\n const handleBlur: FocusEventHandler<HTMLInputElement> = (e) => {\n if (disableAbbreviation) {\n setFormatted(formattedValue);\n } else {\n setFormatted(formatCurrency(formattedValue as string, thousandSeparator));\n }\n\n setRootValue(formattedValue);\n setFocused(false);\n\n onBlur && onBlur(e);\n };\n\n const handleFocus: FocusEventHandler<HTMLInputElement> = (e) => {\n setFormatted(rootValue);\n setFocused(true);\n\n onFocus && onFocus(e);\n };\n\n const updateValue = (type: \"increment\" | \"decrement\", step: number) => {\n const value = String(formattedValue);\n\n let decimalPart = \"\";\n let increasedValue = 0;\n let nonDecimalPart = value.replaceAll(thousandSeparator, \"\");\n\n if (!value) {\n return;\n }\n\n if (value.includes(decimalSeparator)) {\n nonDecimalPart = value\n .slice(0, value.indexOf(decimalSeparator))\n .replaceAll(thousandSeparator, \"\");\n }\n\n if (value.includes(decimalSeparator)) {\n decimalPart = value.slice(value.indexOf(decimalSeparator));\n }\n\n if (type === \"increment\") {\n increasedValue = parseFloat(nonDecimalPart) + step;\n } else {\n increasedValue = parseFloat(nonDecimalPart) - step;\n }\n\n if (value.includes(decimalSeparator)) {\n increasedValue = parseFloat(increasedValue.toFixed(decimalLength));\n }\n\n const joinedValue = numberWithSeparator(\n increasedValue,\n thousandSeparator,\n value.includes(thousandSeparator)\n );\n\n setFormatted(decimalPart ? joinedValue + decimalPart : joinedValue);\n };\n\n return {\n focused,\n formattedValue,\n rootValue,\n handleChange,\n handleKeyDown,\n handleBlur,\n handleFocus,\n onValueChange,\n } as const;\n};\n"],"mappings":"AAAA,SACEA,QAAQ,QAKH,OAAO;AACd,SACEC,kBAAkB,EAClBC,cAAc,EACdC,mBAAmB,QACd,wBAAwB;AAgB/B,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAc,OAczBC,GAA8C,EAC3C;EAAA,iCAbDC,gBAAgB;IAAhBA,gBAAgB,sCAAG,GAAG;IAAA,6BACtBC,iBAAiB;IAAjBA,iBAAiB,sCAAG,GAAG;IACvBC,mBAAmB,QAAnBA,mBAAmB;IACnBC,aAAa,QAAbA,aAAa;IACbC,aAAa,QAAbA,aAAa;IACbC,KAAK,QAALA,KAAK;IACLC,aAAa,QAAbA,aAAa;IACbC,SAAS,QAATA,SAAS;IACTC,MAAM,QAANA,MAAM;IACNC,OAAO,QAAPA,OAAO;IACPC,IAAI,QAAJA,IAAI;EAIN,gBAAuChB,QAAQ,CAACW,KAAK,CAAC;IAA/CM,cAAc;IAAEC,YAAY;EACnC,iBAAkClB,QAAQ,CAACW,KAAK,CAAC;IAA1CQ,SAAS;IAAEC,YAAY;EAC9B,iBAA8BpB,QAAQ,CAAU,KAAK,CAAC;IAA/CqB,OAAO;IAAEC,UAAU;EAE1B,IAAMC,eAAe,GAAG,SAAlBA,eAAe,GAAS;IAC5B,IAAIlB,GAAG,IAAIA,GAAG,CAACmB,OAAO,EAAE;MACtBnB,GAAG,CAACmB,OAAO,CAACC,IAAI,EAAE;IACpB;EACF,CAAC;EAED,IAAM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ACL3C,OAAO,EAAPA,OAAO;IACPJ,cAAc,EAAdA,cAAc;IACdE,SAAS,EAATA,SAAS;IACTS,YAAY,EAAZA,YAAY;IACZiB,aAAa,EAAbA,aAAa;IACbQ,UAAU,EAAVA,UAAU;IACVC,WAAW,EAAXA,WAAW;IACX1C,aAAa,EAAbA;EACF,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { Separators } from "../
|
|
2
|
-
export declare const
|
|
1
|
+
import { Separators } from "../hooks";
|
|
2
|
+
export declare const currencyMultiplier: {
|
|
3
|
+
k: number;
|
|
4
|
+
m: number;
|
|
5
|
+
b: number;
|
|
6
|
+
t: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const formatCurrency: (n: string, thousandSeparator?: string) => string;
|
|
3
9
|
export declare const numberWithSeparator: (x: number | string, thousandSeparator: Separators, format?: boolean) => string | number;
|
|
4
10
|
//# sourceMappingURL=currencyUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencyUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/currencyUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"currencyUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/currencyUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,eAAO,MAAM,kBAAkB;;;;;CAK9B,CAAC;AAEF,eAAO,MAAM,cAAc,MAAO,MAAM,uCA2BvC,CAAC;AAEF,eAAO,MAAM,mBAAmB,MAC3B,MAAM,GAAG,MAAM,qBACC,UAAU,sCAW9B,CAAC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export var currencyMultiplier = {
|
|
2
|
+
k: 1000,
|
|
3
|
+
m: 1000000,
|
|
4
|
+
b: 1000000000,
|
|
5
|
+
t: 1000000000000
|
|
6
|
+
};
|
|
1
7
|
export var formatCurrency = function formatCurrency(n, thousandSeparator) {
|
|
2
8
|
if (thousandSeparator === void 0) {
|
|
3
9
|
thousandSeparator = ",";
|
|
@@ -6,21 +12,17 @@ export var formatCurrency = function formatCurrency(n, thousandSeparator) {
|
|
|
6
12
|
if (isNaN(number)) {
|
|
7
13
|
return "";
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return _formattedNum.endsWith(".0") ? (number / 1000000).toFixed(0) + "M" : _formattedNum + "M";
|
|
17
|
-
} else if (number >= 1000000000 && number < 1000000000000) {
|
|
18
|
-
var _formattedNum2 = (number / 1000000000).toFixed(1);
|
|
19
|
-
return _formattedNum2.endsWith(".0") ? (number / 1000000000).toFixed(0) + "B" : _formattedNum2 + "B";
|
|
20
|
-
} else if (number >= 1000000000000 && number < 1000000000000000) {
|
|
21
|
-
var _formattedNum3 = (number / 1000000000000).toFixed(1);
|
|
22
|
-
return _formattedNum3.endsWith(".0") ? (number / 1000000000000).toFixed(0) + "T" : _formattedNum3 + "T";
|
|
15
|
+
var isNegative = number < 0;
|
|
16
|
+
var absoluteNumber = Math.abs(number);
|
|
17
|
+
var suffixes = ["", "K", "M", "B", "T"];
|
|
18
|
+
var scale = 0;
|
|
19
|
+
while (absoluteNumber >= 1000 && scale < suffixes.length - 1) {
|
|
20
|
+
absoluteNumber /= 1000;
|
|
21
|
+
scale++;
|
|
23
22
|
}
|
|
23
|
+
var formattedNum = scale === 0 ? absoluteNumber.toFixed(0) : absoluteNumber.toFixed(1);
|
|
24
|
+
var result = formattedNum.endsWith(".0") ? formattedNum.slice(0, -2) : formattedNum;
|
|
25
|
+
return isNegative ? "-" + result + suffixes[scale] : "" + result + suffixes[scale];
|
|
24
26
|
};
|
|
25
27
|
export var numberWithSeparator = function numberWithSeparator(x, thousandSeparator, format) {
|
|
26
28
|
if (format === void 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencyUtils.js","names":["formatCurrency","n","thousandSeparator","number","parseFloat","String","replaceAll","isNaN","formattedNum","toFixed","endsWith","numberWithSeparator","x","format","parts","toString","split","replace","join"],"sources":["../../../src/utils/currencyUtils.ts"],"sourcesContent":["import { Separators } from \"../
|
|
1
|
+
{"version":3,"file":"currencyUtils.js","names":["currencyMultiplier","k","m","b","t","formatCurrency","n","thousandSeparator","number","parseFloat","String","replaceAll","isNaN","isNegative","absoluteNumber","Math","abs","suffixes","scale","length","formattedNum","toFixed","result","endsWith","slice","numberWithSeparator","x","format","parts","toString","split","replace","join"],"sources":["../../../src/utils/currencyUtils.ts"],"sourcesContent":["import { Separators } from \"../hooks\";\n\nexport const currencyMultiplier = {\n k: 1_000,\n m: 1_000_000,\n b: 1_000_000_000,\n t: 1_000_000_000_000,\n};\n\nexport const formatCurrency = (n: string, thousandSeparator = \",\") => {\n const number = parseFloat(String(n).replaceAll(thousandSeparator, \"\"));\n\n if (isNaN(number)) {\n return \"\";\n }\n\n const isNegative = number < 0;\n let absoluteNumber = Math.abs(number);\n\n const suffixes = [\"\", \"K\", \"M\", \"B\", \"T\"];\n let scale = 0;\n\n while (absoluteNumber >= 1000 && scale < suffixes.length - 1) {\n absoluteNumber /= 1000;\n scale++;\n }\n\n const formattedNum =\n scale === 0 ? absoluteNumber.toFixed(0) : absoluteNumber.toFixed(1);\n const result = formattedNum.endsWith(\".0\")\n ? formattedNum.slice(0, -2)\n : formattedNum;\n\n return isNegative\n ? `-${result}${suffixes[scale]}`\n : `${result}${suffixes[scale]}`;\n};\n\nexport const numberWithSeparator = (\n x: number | string,\n thousandSeparator: Separators,\n format = true\n) => {\n if (!format) {\n return x;\n }\n\n const parts = x.toString().split(\".\");\n parts[0] = parts[0].replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousandSeparator);\n\n return parts.join(\".\");\n};\n"],"mappings":"AAEA,OAAO,IAAMA,kBAAkB,GAAG;EAChCC,CAAC,EAAE,IAAK;EACR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nB,iBAA6B,EAC7BoB,MAAM,EACH;EAAA,IADHA,MAAM;IAANA,MAAM,GAAG,IAAI;EAAA;EAEb,IAAI,CAACA,MAAM,EAAE;IACX,OAAOD,CAAC;EACV;EAEA,IAAME,KAAK,GAAGF,CAAC,CAACG,QAAQ,EAAE,CAACC,KAAK,CAAC,GAAG,CAAC;EACrCF,KAAK,CAAC,CAAC,CAAC,GAAGA,KAAK,CAAC,CAAC,CAAC,CAACG,OAAO,CAAC,uBAAuB,EAAExB,iBAAiB,CAAC;EAEvE,OAAOqB,KAAK,CAACI,IAAI,CAAC,GAAG,CAAC;AACxB,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { formatCurrency, numberWithSeparator } from "./currencyUtils";
|
|
2
2
|
describe("format currency with thousandseparator set to ',' and decimalSeparator to '.'", function () {
|
|
3
|
-
it.each([["", ""], ["10", "10"], ["1000", "1K"], ["1000.00", "1K"], ["1200.50", "1.2K"], ["1,200.00", "1.2K"], ["2,240.00", "2.2K"], ["22,240.00", "22.2K"], ["50,000,000.00", "50M"]])("should format currency", function (value, expected) {
|
|
3
|
+
it.each([["", ""], ["10", "10"], ["1000", "1K"], ["1000.00", "1K"], ["1200.50", "1.2K"], ["1,200.00", "1.2K"], ["2,240.00", "2.2K"], ["22,240.00", "22.2K"], ["50,000,000.00", "50M"], ["-50,000.00", "-50K"], ["-1,200", "-1.2K"], ["-90,000,000.00", "-90M"]])("should format currency", function (value, expected) {
|
|
4
4
|
expect(formatCurrency(value, ",")).toEqual(expected);
|
|
5
5
|
});
|
|
6
6
|
});
|
|
7
7
|
describe("format currency with thousandseparator set to '.' and decimalSeparator to ','", function () {
|
|
8
|
-
it.each([["", ""], ["10", "10"], ["1000", "1K"], ["1000,00", "1K"], ["1200,50", "1.2K"], ["1.200,00", "1.2K"], ["2.240,00", "2.2K"], ["22.240,00", "22.2K"], ["50.000.000,00", "50M"]])("should format currency", function (value, expected) {
|
|
8
|
+
it.each([["", ""], ["10", "10"], ["1000", "1K"], ["1000,00", "1K"], ["1200,50", "1.2K"], ["1.200,00", "1.2K"], ["2.240,00", "2.2K"], ["22.240,00", "22.2K"], ["50.000.000,00", "50M"], ["-50.000,00", "-50K"], ["-1.200", "-1.2K"], ["-90.000.000,00", "-90M"]])("should format currency", function (value, expected) {
|
|
9
9
|
expect(formatCurrency(value, ".")).toEqual(expected);
|
|
10
10
|
});
|
|
11
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencyUtils.test.js","names":["formatCurrency","numberWithSeparator","describe","it","each","value","expected","expect","toEqual","test","result","toBe"],"sources":["../../../src/utils/currencyUtils.test.ts"],"sourcesContent":["import { formatCurrency, numberWithSeparator } from \"./currencyUtils\";\n\ndescribe(\"format currency with thousandseparator set to ',' and decimalSeparator to '.'\", () => {\n it.each([\n [\"\", \"\"],\n [\"10\", \"10\"],\n [\"1000\", \"1K\"],\n [\"1000.00\", \"1K\"],\n [\"1200.50\", \"1.2K\"],\n [\"1,200.00\", \"1.2K\"],\n [\"2,240.00\", \"2.2K\"],\n [\"22,240.00\", \"22.2K\"],\n [\"50,000,000.00\", \"50M\"],\n ])(\"should format currency\", (value, expected) => {\n expect(formatCurrency(value, \",\")).toEqual(expected);\n });\n});\n\ndescribe(\"format currency with thousandseparator set to '.' and decimalSeparator to ','\", () => {\n it.each([\n [\"\", \"\"],\n [\"10\", \"10\"],\n [\"1000\", \"1K\"],\n [\"1000,00\", \"1K\"],\n [\"1200,50\", \"1.2K\"],\n [\"1.200,00\", \"1.2K\"],\n [\"2.240,00\", \"2.2K\"],\n [\"22.240,00\", \"22.2K\"],\n [\"50.000.000,00\", \"50M\"],\n ])(\"should format currency\", (value, expected) => {\n expect(formatCurrency(value, \".\")).toEqual(expected);\n });\n});\n\ndescribe(\"numberWithSeparator\", () => {\n test(\"should format number with thousand separator\", () => {\n const result = numberWithSeparator(1000, \",\");\n expect(result).toBe(\"1,000\");\n });\n\n test(\"should format string number with thousand separator\", () => {\n const result = numberWithSeparator(\"1000\", \",\");\n expect(result).toBe(\"1,000\");\n });\n\n test(\"should format decimal number with thousand separator and keep decimal part\", () => {\n const result = numberWithSeparator(12345.67, \",\");\n expect(result).toBe(\"12,345.67\");\n });\n\n test(\"should not format when format is set to false\", () => {\n const result = numberWithSeparator(1000, \",\", false);\n expect(result).toBe(1000);\n });\n\n test(\"should handle zero with thousand separator\", () => {\n const result = numberWithSeparator(0, \",\");\n expect(result).toBe(\"0\");\n });\n\n test(\"should handle negative number with thousand separator\", () => {\n const result = numberWithSeparator(-123456789, \",\");\n expect(result).toBe(\"-123,456,789\");\n });\n\n test(\"should not format\", () => {\n const result = numberWithSeparator(123456789, \",\", false);\n expect(result).toBe(123456789);\n });\n});\n"],"mappings":"AAAA,SAASA,cAAc,EAAEC,mBAAmB,QAAQ,iBAAiB;AAErEC,QAAQ,CAAC,+EAA+E,EAAE,YAAM;EAC9FC,EAAE,CAACC,IAAI,CAAC,CACN,CAAC,EAAE,EAAE,EAAE,CAAC,EACR,CAAC,IAAI,EAAE,IAAI,CAAC,EACZ,CAAC,MAAM,EAAE,IAAI,CAAC,EACd,CAAC,SAAS,EAAE,IAAI,CAAC,EACjB,CAAC,SAAS,EAAE,MAAM,CAAC,EACnB,CAAC,UAAU,EAAE,MAAM,CAAC,EACpB,CAAC,UAAU,EAAE,MAAM,CAAC,EACpB,CAAC,WAAW,EAAE,OAAO,CAAC,EACtB,CAAC,eAAe,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"currencyUtils.test.js","names":["formatCurrency","numberWithSeparator","describe","it","each","value","expected","expect","toEqual","test","result","toBe"],"sources":["../../../src/utils/currencyUtils.test.ts"],"sourcesContent":["import { formatCurrency, numberWithSeparator } from \"./currencyUtils\";\n\ndescribe(\"format currency with thousandseparator set to ',' and decimalSeparator to '.'\", () => {\n it.each([\n [\"\", \"\"],\n [\"10\", \"10\"],\n [\"1000\", \"1K\"],\n [\"1000.00\", \"1K\"],\n [\"1200.50\", \"1.2K\"],\n [\"1,200.00\", \"1.2K\"],\n [\"2,240.00\", \"2.2K\"],\n [\"22,240.00\", \"22.2K\"],\n [\"50,000,000.00\", \"50M\"],\n [\"-50,000.00\", \"-50K\"],\n [\"-1,200\", \"-1.2K\"],\n [\"-90,000,000.00\", \"-90M\"],\n ])(\"should format currency\", (value, expected) => {\n expect(formatCurrency(value, \",\")).toEqual(expected);\n });\n});\n\ndescribe(\"format currency with thousandseparator set to '.' and decimalSeparator to ','\", () => {\n it.each([\n [\"\", \"\"],\n [\"10\", \"10\"],\n [\"1000\", \"1K\"],\n [\"1000,00\", \"1K\"],\n [\"1200,50\", \"1.2K\"],\n [\"1.200,00\", \"1.2K\"],\n [\"2.240,00\", \"2.2K\"],\n [\"22.240,00\", \"22.2K\"],\n [\"50.000.000,00\", \"50M\"],\n [\"-50.000,00\", \"-50K\"],\n [\"-1.200\", \"-1.2K\"],\n [\"-90.000.000,00\", \"-90M\"],\n ])(\"should format currency\", (value, expected) => {\n expect(formatCurrency(value, \".\")).toEqual(expected);\n });\n});\n\ndescribe(\"numberWithSeparator\", () => {\n test(\"should format number with thousand separator\", () => {\n const result = numberWithSeparator(1000, \",\");\n expect(result).toBe(\"1,000\");\n });\n\n test(\"should format string number with thousand separator\", () => {\n const result = numberWithSeparator(\"1000\", \",\");\n expect(result).toBe(\"1,000\");\n });\n\n test(\"should format decimal number with thousand separator and keep decimal part\", () => {\n const result = numberWithSeparator(12345.67, \",\");\n expect(result).toBe(\"12,345.67\");\n });\n\n test(\"should not format when format is set to false\", () => {\n const result = numberWithSeparator(1000, \",\", false);\n expect(result).toBe(1000);\n });\n\n test(\"should handle zero with thousand separator\", () => {\n const result = numberWithSeparator(0, \",\");\n expect(result).toBe(\"0\");\n });\n\n test(\"should handle negative number with thousand separator\", () => {\n const result = numberWithSeparator(-123456789, \",\");\n expect(result).toBe(\"-123,456,789\");\n });\n\n test(\"should not format\", () => {\n const result = numberWithSeparator(123456789, \",\", false);\n expect(result).toBe(123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EFF,IAAI,CAAC,uDAAuD,EAAE,YAAM;IAClE,IAAMC,MAAM,GAAGT,mBAAmB,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC;IACnDM,MAAM,CAACG,MAAM,CAAC,CAACC,IAAI,CAAC,cAAc,CAAC;EACrC,CAAC,CAAC;EAEFF,IAAI,CAAC,mBAAmB,EAAE,YAAM;IAC9B,IAAMC,MAAM,GAAGT,mBAAmB,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC;IACzDM,MAAM,CAACG,MAAM,CAAC,CAACC,IAAI,CAAC,SAAS,CAAC;EAChC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -3,9 +3,9 @@ export var validateStopwatchTime = function validateStopwatchTime(value) {
|
|
|
3
3
|
};
|
|
4
4
|
export var validateTimeInput = function validateTimeInput(value, withLeadingZero) {
|
|
5
5
|
if (withLeadingZero) {
|
|
6
|
-
return /^(([0-9][0-9]?|[1-9][0-9]{2,8})?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]
|
|
6
|
+
return /^(([0-9][0-9]?|[1-9][0-9]{2,8})?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(value);
|
|
7
7
|
} else {
|
|
8
|
-
return /^(([1-9][0-9]*|0)?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]
|
|
8
|
+
return /^(([1-9][0-9]*|0)?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(value);
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","names":["validateStopwatchTime","value","test","validateTimeInput","withLeadingZero"],"sources":["../../../src/utils/validation.ts"],"sourcesContent":["export const validateStopwatchTime = (value: string) => {\n return /^([0-9]{0,2})?(((:([0-5][0-9])?)|(:[0-5]?))|(\\.[0-9]{0,2})|(,[0-9]{0,2}))?$/g.test(\n value\n );\n};\n\nexport const validateTimeInput = (value: string, withLeadingZero: boolean) => {\n if (withLeadingZero) {\n return /^(([0-9][0-9]?|[1-9][0-9]{2,8})?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\\.[0-9]
|
|
1
|
+
{"version":3,"file":"validation.js","names":["validateStopwatchTime","value","test","validateTimeInput","withLeadingZero"],"sources":["../../../src/utils/validation.ts"],"sourcesContent":["export const validateStopwatchTime = (value: string) => {\n return /^([0-9]{0,2})?(((:([0-5][0-9])?)|(:[0-5]?))|(\\.[0-9]{0,2})|(,[0-9]{0,2}))?$/g.test(\n value\n );\n};\n\nexport const validateTimeInput = (value: string, withLeadingZero: boolean) => {\n if (withLeadingZero) {\n return /^(([0-9][0-9]?|[1-9][0-9]{2,8})?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(\n value\n );\n } else {\n return /^(([1-9][0-9]*|0)?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(\n value\n );\n }\n};\n"],"mappings":"AAAA,OAAO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAqB,CAAIC,KAAa,EAAK;EACtD,OAAO,8EAA8E,CAACC,IAAI,CACxFD,KAAK,CACN;AACH,CAAC;AAED,OAAO,IAAME,iBAAiB,GAAG,SAApBA,iBAAiB,CAAIF,KAAa,EAAEG,eAAwB,EAAK;EAC5E,IAAIA,eAAe,EAAE;IACnB,OAAO,oGAAoG,CAACF,IAAI,CAC9GD,KAAK,CACN;EACH,CAAC,MAAM;IACL,OAAO,sFAAsF,CAACC,IAAI,CAChGD,KAAK,CACN;EACH;AACF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -434,9 +434,9 @@
|
|
|
434
434
|
};
|
|
435
435
|
var validateTimeInput = function validateTimeInput(value, withLeadingZero) {
|
|
436
436
|
if (withLeadingZero) {
|
|
437
|
-
return /^(([0-9][0-9]?|[1-9][0-9]{2,8})?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]
|
|
437
|
+
return /^(([0-9][0-9]?|[1-9][0-9]{2,8})?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(value);
|
|
438
438
|
} else {
|
|
439
|
-
return /^(([1-9][0-9]*|0)?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]
|
|
439
|
+
return /^(([1-9][0-9]*|0)?(([:,.][0-5][0-9]?)|([:,.][0-5]?)|(\.[0-9]{1,2})|(,[0-9]{1,2}))?)$/.test(value);
|
|
440
440
|
}
|
|
441
441
|
};
|
|
442
442
|
|
|
@@ -11046,6 +11046,172 @@
|
|
|
11046
11046
|
return height;
|
|
11047
11047
|
};
|
|
11048
11048
|
|
|
11049
|
+
var currencyMultiplier = {
|
|
11050
|
+
k: 1000,
|
|
11051
|
+
m: 1000000,
|
|
11052
|
+
b: 1000000000,
|
|
11053
|
+
t: 1000000000000
|
|
11054
|
+
};
|
|
11055
|
+
var formatCurrency = function formatCurrency(n) {
|
|
11056
|
+
var thousandSeparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ",";
|
|
11057
|
+
var number = parseFloat(String(n).replaceAll(thousandSeparator, ""));
|
|
11058
|
+
if (isNaN(number)) {
|
|
11059
|
+
return "";
|
|
11060
|
+
}
|
|
11061
|
+
var isNegative = number < 0;
|
|
11062
|
+
var absoluteNumber = Math.abs(number);
|
|
11063
|
+
var suffixes = ["", "K", "M", "B", "T"];
|
|
11064
|
+
var scale = 0;
|
|
11065
|
+
while (absoluteNumber >= 1000 && scale < suffixes.length - 1) {
|
|
11066
|
+
absoluteNumber /= 1000;
|
|
11067
|
+
scale++;
|
|
11068
|
+
}
|
|
11069
|
+
var formattedNum = scale === 0 ? absoluteNumber.toFixed(0) : absoluteNumber.toFixed(1);
|
|
11070
|
+
var result = formattedNum.endsWith(".0") ? formattedNum.slice(0, -2) : formattedNum;
|
|
11071
|
+
return isNegative ? "-".concat(result).concat(suffixes[scale]) : "".concat(result).concat(suffixes[scale]);
|
|
11072
|
+
};
|
|
11073
|
+
var numberWithSeparator = function numberWithSeparator(x, thousandSeparator) {
|
|
11074
|
+
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
11075
|
+
if (!format) {
|
|
11076
|
+
return x;
|
|
11077
|
+
}
|
|
11078
|
+
var parts = x.toString().split(".");
|
|
11079
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
|
|
11080
|
+
return parts.join(".");
|
|
11081
|
+
};
|
|
11082
|
+
|
|
11083
|
+
var useInputNumber = function useInputNumber(_ref, ref) {
|
|
11084
|
+
var _ref$decimalSeparator = _ref.decimalSeparator,
|
|
11085
|
+
decimalSeparator = _ref$decimalSeparator === void 0 ? "." : _ref$decimalSeparator,
|
|
11086
|
+
_ref$thousandSeparato = _ref.thousandSeparator,
|
|
11087
|
+
thousandSeparator = _ref$thousandSeparato === void 0 ? "," : _ref$thousandSeparato,
|
|
11088
|
+
disableAbbreviation = _ref.disableAbbreviation,
|
|
11089
|
+
disableMacros = _ref.disableMacros,
|
|
11090
|
+
decimalLength = _ref.decimalLength,
|
|
11091
|
+
value = _ref.value,
|
|
11092
|
+
onValueChange = _ref.onValueChange,
|
|
11093
|
+
onKeyDown = _ref.onKeyDown,
|
|
11094
|
+
onBlur = _ref.onBlur,
|
|
11095
|
+
onFocus = _ref.onFocus,
|
|
11096
|
+
step = _ref.step;
|
|
11097
|
+
var _useState = React.useState(value),
|
|
11098
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11099
|
+
formattedValue = _useState2[0],
|
|
11100
|
+
setFormatted = _useState2[1];
|
|
11101
|
+
var _useState3 = React.useState(value),
|
|
11102
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
11103
|
+
rootValue = _useState4[0],
|
|
11104
|
+
setRootValue = _useState4[1];
|
|
11105
|
+
var _useState5 = React.useState(false),
|
|
11106
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
11107
|
+
focused = _useState6[0],
|
|
11108
|
+
setFocused = _useState6[1];
|
|
11109
|
+
var handleInputBlur = function handleInputBlur() {
|
|
11110
|
+
if (ref && ref.current) {
|
|
11111
|
+
ref.current.blur();
|
|
11112
|
+
}
|
|
11113
|
+
};
|
|
11114
|
+
var handleSelect = function handleSelect() {
|
|
11115
|
+
if (ref && ref.current) {
|
|
11116
|
+
ref.current.select();
|
|
11117
|
+
}
|
|
11118
|
+
};
|
|
11119
|
+
var handleChange = function handleChange(e) {
|
|
11120
|
+
var inputValue = e.target.value;
|
|
11121
|
+
var isValidInput = false;
|
|
11122
|
+
if (inputValue.startsWith("00")) {
|
|
11123
|
+
return;
|
|
11124
|
+
}
|
|
11125
|
+
var numericInput = disableMacros ? inputValue : inputValue.replace(/([0-9.]+)([kmbtKMBT])/, function (_, num, unit) {
|
|
11126
|
+
return (parseFloat(num) * currencyMultiplier[unit.toLowerCase()]).toString();
|
|
11127
|
+
});
|
|
11128
|
+
var regexString = "^(-?\\d{0,9}(?:[".concat(thousandSeparator, "]?\\d{0,3})*(?:\\").concat(decimalSeparator, "\\d{0,").concat(decimalLength, "})?)?$");
|
|
11129
|
+
if (thousandSeparator === ",") {
|
|
11130
|
+
isValidInput = new RegExp(regexString).test(numericInput);
|
|
11131
|
+
}
|
|
11132
|
+
if (thousandSeparator === ".") {
|
|
11133
|
+
isValidInput = new RegExp(regexString).test(numericInput);
|
|
11134
|
+
}
|
|
11135
|
+
if (!isValidInput) {
|
|
11136
|
+
return;
|
|
11137
|
+
}
|
|
11138
|
+
setFormatted(numericInput);
|
|
11139
|
+
onValueChange && onValueChange(numericInput);
|
|
11140
|
+
};
|
|
11141
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
11142
|
+
var key = e.key;
|
|
11143
|
+
var _step = parseFloat(String(step));
|
|
11144
|
+
if (key === "Escape") {
|
|
11145
|
+
handleInputBlur();
|
|
11146
|
+
}
|
|
11147
|
+
if (key === "ArrowUp") {
|
|
11148
|
+
e.preventDefault();
|
|
11149
|
+
updateValue("increment", _step);
|
|
11150
|
+
}
|
|
11151
|
+
if (key === "ArrowDown") {
|
|
11152
|
+
e.preventDefault();
|
|
11153
|
+
updateValue("decrement", _step);
|
|
11154
|
+
}
|
|
11155
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "a") {
|
|
11156
|
+
handleSelect();
|
|
11157
|
+
}
|
|
11158
|
+
if (decimalLength === 0 && e.key === decimalSeparator) {
|
|
11159
|
+
e.preventDefault();
|
|
11160
|
+
}
|
|
11161
|
+
onKeyDown && onKeyDown(e);
|
|
11162
|
+
};
|
|
11163
|
+
var handleBlur = function handleBlur(e) {
|
|
11164
|
+
if (disableAbbreviation) {
|
|
11165
|
+
setFormatted(formattedValue);
|
|
11166
|
+
} else {
|
|
11167
|
+
setFormatted(formatCurrency(formattedValue, thousandSeparator));
|
|
11168
|
+
}
|
|
11169
|
+
setRootValue(formattedValue);
|
|
11170
|
+
setFocused(false);
|
|
11171
|
+
onBlur && onBlur(e);
|
|
11172
|
+
};
|
|
11173
|
+
var handleFocus = function handleFocus(e) {
|
|
11174
|
+
setFormatted(rootValue);
|
|
11175
|
+
setFocused(true);
|
|
11176
|
+
onFocus && onFocus(e);
|
|
11177
|
+
};
|
|
11178
|
+
var updateValue = function updateValue(type, step) {
|
|
11179
|
+
var value = String(formattedValue);
|
|
11180
|
+
var decimalPart = "";
|
|
11181
|
+
var increasedValue = 0;
|
|
11182
|
+
var nonDecimalPart = value.replaceAll(thousandSeparator, "");
|
|
11183
|
+
if (!value) {
|
|
11184
|
+
return;
|
|
11185
|
+
}
|
|
11186
|
+
if (value.includes(decimalSeparator)) {
|
|
11187
|
+
nonDecimalPart = value.slice(0, value.indexOf(decimalSeparator)).replaceAll(thousandSeparator, "");
|
|
11188
|
+
}
|
|
11189
|
+
if (value.includes(decimalSeparator)) {
|
|
11190
|
+
decimalPart = value.slice(value.indexOf(decimalSeparator));
|
|
11191
|
+
}
|
|
11192
|
+
if (type === "increment") {
|
|
11193
|
+
increasedValue = parseFloat(nonDecimalPart) + step;
|
|
11194
|
+
} else {
|
|
11195
|
+
increasedValue = parseFloat(nonDecimalPart) - step;
|
|
11196
|
+
}
|
|
11197
|
+
if (value.includes(decimalSeparator)) {
|
|
11198
|
+
increasedValue = parseFloat(increasedValue.toFixed(decimalLength));
|
|
11199
|
+
}
|
|
11200
|
+
var joinedValue = numberWithSeparator(increasedValue, thousandSeparator, value.includes(thousandSeparator));
|
|
11201
|
+
setFormatted(decimalPart ? joinedValue + decimalPart : joinedValue);
|
|
11202
|
+
};
|
|
11203
|
+
return {
|
|
11204
|
+
focused: focused,
|
|
11205
|
+
formattedValue: formattedValue,
|
|
11206
|
+
rootValue: rootValue,
|
|
11207
|
+
handleChange: handleChange,
|
|
11208
|
+
handleKeyDown: handleKeyDown,
|
|
11209
|
+
handleBlur: handleBlur,
|
|
11210
|
+
handleFocus: handleFocus,
|
|
11211
|
+
onValueChange: onValueChange
|
|
11212
|
+
};
|
|
11213
|
+
};
|
|
11214
|
+
|
|
11049
11215
|
var _excluded$O = ["as", "className", "invert", "style"];
|
|
11050
11216
|
var ScrollElement = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
11051
11217
|
var _ref$as = _ref.as,
|
|
@@ -12766,7 +12932,8 @@
|
|
|
12766
12932
|
onChange: onChange,
|
|
12767
12933
|
onClick: onClick,
|
|
12768
12934
|
onDoubleClick: onDoubleClick,
|
|
12769
|
-
ref: handleRef
|
|
12935
|
+
ref: handleRef,
|
|
12936
|
+
autoComplete: "off"
|
|
12770
12937
|
}));
|
|
12771
12938
|
});
|
|
12772
12939
|
InputHours.displayName = "InputHours";
|
|
@@ -18268,6 +18435,7 @@
|
|
|
18268
18435
|
exports.useForkRef = useForkRef;
|
|
18269
18436
|
exports.useHeight = useHeight;
|
|
18270
18437
|
exports.useInitScrollRef = useInitScrollRef;
|
|
18438
|
+
exports.useInputNumber = useInputNumber;
|
|
18271
18439
|
exports.useLayerContext = useLayerContext;
|
|
18272
18440
|
exports.useMenuContext = useMenuContext;
|
|
18273
18441
|
exports.useResizeObserver = useResizeObserver$1;
|