hi-tm 0.20.1 → 0.20.2
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.
|
@@ -38,7 +38,6 @@ const react_1 = __importStar(require("react"));
|
|
|
38
38
|
const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, currencyUnit, textError, label, autoComplete, autoFocus, inlineCss, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled = false, }, ref) => {
|
|
39
39
|
const [inputValue, setInputValue] = (0, react_1.useState)(value?.toString() || "");
|
|
40
40
|
const internalRef = (0, react_1.useRef)(null);
|
|
41
|
-
// Combine the external ref with the internal ref
|
|
42
41
|
react_1.default.useImperativeHandle(ref, () => internalRef.current);
|
|
43
42
|
(0, react_1.useEffect)(() => {
|
|
44
43
|
if (value !== null && value !== undefined) {
|
|
@@ -54,29 +53,19 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
|
|
|
54
53
|
internalRef.current.selectionEnd = internalRef.current.value.length;
|
|
55
54
|
}
|
|
56
55
|
}, [value]);
|
|
57
|
-
const isErrorVisible = () => {
|
|
58
|
-
return !(textError && textError.trim() !== "");
|
|
59
|
-
};
|
|
60
56
|
const formatWithCommas = (value) => {
|
|
61
|
-
// Remove any non-digit characters except decimal point
|
|
62
57
|
const numericValue = value.replace(/[^\d.]/g, '');
|
|
63
58
|
if (numericValue === '')
|
|
64
59
|
return '';
|
|
65
|
-
// Split the number into integer and decimal parts (for currencies that might have decimals)
|
|
66
60
|
const [integerPart, decimalPart] = numericValue.split('.');
|
|
67
|
-
// Format the integer part with commas
|
|
68
61
|
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
69
|
-
// Return the formatted value with decimal part if it exists
|
|
70
62
|
return decimalPart !== undefined ? `${formattedInteger}.${decimalPart}` : formattedInteger;
|
|
71
63
|
};
|
|
72
64
|
const handleChange = (event) => {
|
|
73
65
|
const newValue = event.target.value;
|
|
74
|
-
// Remove all commas from the input to get the raw numeric value
|
|
75
66
|
const rawValue = newValue.replace(/,/g, '');
|
|
76
|
-
// Validate that the raw value contains only digits and optionally a decimal point
|
|
77
67
|
if (/^\d*\.?\d*$/.test(rawValue)) {
|
|
78
68
|
setInputValue(rawValue);
|
|
79
|
-
// Create a new event with the raw numeric value for the handler
|
|
80
69
|
const syntheticEvent = {
|
|
81
70
|
...event,
|
|
82
71
|
target: {
|
|
@@ -84,23 +73,14 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
|
|
|
84
73
|
value: rawValue
|
|
85
74
|
}
|
|
86
75
|
};
|
|
87
|
-
// Use an if statement instead of a logical expression
|
|
88
76
|
if (onChangeValueHandler) {
|
|
89
77
|
onChangeValueHandler(syntheticEvent);
|
|
90
78
|
}
|
|
91
79
|
}
|
|
92
80
|
};
|
|
93
81
|
const handleKeyDown = (event) => {
|
|
94
|
-
const allowedKeys = [
|
|
95
|
-
"Backspace",
|
|
96
|
-
"ArrowLeft",
|
|
97
|
-
"ArrowRight",
|
|
98
|
-
"Delete",
|
|
99
|
-
"Tab",
|
|
100
|
-
".",
|
|
101
|
-
];
|
|
82
|
+
const allowedKeys = ["Backspace", "ArrowLeft", "ArrowRight", "Delete", "Tab", "."];
|
|
102
83
|
const isNumber = /[0-9]/.test(event.key);
|
|
103
|
-
// Allow decimal point only if it's not already in the value
|
|
104
84
|
if (event.key === '.') {
|
|
105
85
|
const currentValue = event.target.value;
|
|
106
86
|
if (currentValue.includes('.')) {
|
|
@@ -117,8 +97,8 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
|
|
|
117
97
|
react_1.default.createElement("div", { className: "w-full relative", style: inlineCss },
|
|
118
98
|
react_1.default.createElement("div", { className: "w-full flex items-start justify-start gap-1 pb-1" },
|
|
119
99
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium" }, label),
|
|
120
|
-
react_1.default.createElement("span", { className: `text-red-primary ${required ? 'opacity-100' : 'opacity-0'}
|
|
121
|
-
react_1.default.createElement("div", { className: `input-style w-full h-full min-h-[40px] inline-flex relative items-center justify-between gap-x-1.5 text-sm font-semibold text-text-color-primary ${textError ===
|
|
100
|
+
react_1.default.createElement("span", { className: `text-red-primary ${required ? 'opacity-100' : 'opacity-0'}` }, "*")),
|
|
101
|
+
react_1.default.createElement("div", { className: `input-style w-full h-full min-h-[40px] inline-flex relative items-center justify-between gap-x-1.5 text-sm font-semibold text-text-color-primary ${!textError || textError.trim() === ''
|
|
122
102
|
? 'border-[2px] border-solid border-gray-tertiary'
|
|
123
103
|
: 'border-[2.5px] border-solid border-red-primary'}` },
|
|
124
104
|
react_1.default.createElement("input", { ref: internalRef, type: "text", id: label, disabled: disabled, value: formatWithCommas(inputValue), placeholder: placeholder, autoComplete: autoComplete ? "on" : "off", autoFocus: autoFocus, onChange: handleChange, onBlur: onBlurHandler, onFocus: onFocusHandler, onKeyUp: onKeyUpHandler, onKeyDown: handleKeyDown, className: "outline-none bg-inherit w-full h-full pr-2", required: required }),
|