hi-tm 0.19.5 → 0.19.7

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.
@@ -54,11 +54,35 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
54
54
  const isErrorVisible = () => {
55
55
  return !(textError && textError.trim() !== "");
56
56
  };
57
+ const formatWithCommas = (value) => {
58
+ // Remove any non-digit characters except decimal point
59
+ const numericValue = value.replace(/[^\d.]/g, '');
60
+ if (numericValue === '')
61
+ return '';
62
+ // Split the number into integer and decimal parts (for currencies that might have decimals)
63
+ const [integerPart, decimalPart] = numericValue.split('.');
64
+ // Format the integer part with commas
65
+ const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
66
+ // Return the formatted value with decimal part if it exists
67
+ return decimalPart !== undefined ? `${formattedInteger}.${decimalPart}` : formattedInteger;
68
+ };
57
69
  const handleChange = (event) => {
58
70
  const newValue = event.target.value;
59
- const validValue = newValue.replace(/[^\d۰-۹]/g, "");
60
- setInputValue(validValue);
61
- onChangeValueHandler(event);
71
+ // Remove all commas from the input to get the raw numeric value
72
+ const rawValue = newValue.replace(/,/g, '');
73
+ // Validate that the raw value contains only digits and optionally a decimal point
74
+ if (/^\d*\.?\d*$/.test(rawValue)) {
75
+ setInputValue(rawValue);
76
+ // Create a new event with the raw numeric value for the handler
77
+ const syntheticEvent = {
78
+ ...event,
79
+ target: {
80
+ ...event.target,
81
+ value: rawValue
82
+ }
83
+ };
84
+ onChangeValueHandler(syntheticEvent);
85
+ }
62
86
  };
63
87
  const handleKeyDown = (event) => {
64
88
  const allowedKeys = [
@@ -67,9 +91,17 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
67
91
  "ArrowRight",
68
92
  "Delete",
69
93
  "Tab",
94
+ ".",
70
95
  ];
71
- const isNumber = /[0-9۰-۹]/.test(event.key);
72
- if (!isNumber && !allowedKeys.includes(event.key)) {
96
+ const isNumber = /[0-9]/.test(event.key);
97
+ // Allow decimal point only if it's not already in the value
98
+ if (event.key === '.') {
99
+ const currentValue = event.target.value;
100
+ if (currentValue.includes('.')) {
101
+ event.preventDefault();
102
+ }
103
+ }
104
+ else if (!isNumber && !allowedKeys.includes(event.key)) {
73
105
  event.preventDefault();
74
106
  }
75
107
  if (onKeyDownHandler)
@@ -77,15 +109,15 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
77
109
  };
78
110
  return (react_1.default.createElement(react_1.default.Fragment, null,
79
111
  react_1.default.createElement("div", { className: "w-full relative", style: inlineCss },
80
- react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
81
- react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
82
- required && react_1.default.createElement("span", { className: "text-red-primary" }, "*")),
83
- react_1.default.createElement("div", { className: `w-full h-9 flex items-center justify-between bg-inherit outline-none border rounded-lg text-sm px-2 ${isErrorVisible()
84
- ? "border-gray-tertiary focus:border-gray-quaternary"
85
- : "border-red-primary"}` },
86
- react_1.default.createElement("input", { ref: internalRef, type: "text", id: label, disabled: disabled, value: Number(inputValue).toLocaleString(), 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", required: required }),
112
+ react_1.default.createElement("div", { className: "w-full flex items-start justify-start gap-1 pb-1" },
113
+ react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium" }, label),
114
+ react_1.default.createElement("span", { className: `text-red-primary ${required ? 'opacity-100' : 'opacity-0'} ` }, "*")),
115
+ react_1.default.createElement("div", { className: `input-style w-full h-full inline-flex relative items-center justify-between gap-x-1.5 text-sm font-semibold text-text-color-primary ${textError === null
116
+ ? 'border-[2px] border-solid border-gray-tertiary'
117
+ : 'border-[2.5px] border-solid border-red-primary'}` },
118
+ 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 }),
87
119
  react_1.default.createElement("p", { className: "text-sm text-text-color-primary border-r border-gray-tertiary px-2" }, currencyUnit)),
88
- !isErrorVisible() && (react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError?.trim())))));
120
+ react_1.default.createElement("span", { className: `${textError && textError.trim() !== '' ? 'opacity-100' : 'opacity-0'} text-sm mr-1 mt-2 text-nowrap font-normal text-red-primary` }, textError && textError.trim() !== '' && textError.trim()))));
89
121
  });
90
122
  InputCurrency.displayName = "InputCurrency";
91
123
  exports.default = InputCurrency;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.19.5",
3
+ "version": "0.19.7",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {