hi-tm 0.14.1 → 0.14.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.
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
import { InputCurrencyPropsType } from "../../types/Inputs/InputCurrencyType";
|
|
2
2
|
import React from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @param placeholder - The placeholder text for the input field.
|
|
9
|
-
* @param value - The initial value of the input field => (Just Number whit number type OR Null).
|
|
10
|
-
* @param required - Indicates if the input field is required. Displays a red asterisk (*) if true. => (boolean)
|
|
11
|
-
* @param currencyUnit - The currency unit to be displayed. => (string)
|
|
12
|
-
* @param textError - (optional) The error message to display when validation fails. => {string or null}
|
|
13
|
-
* @param label - The label for the input field. => (string)
|
|
14
|
-
* @param autoComplete - Enables or disables autocomplete => (boolean).
|
|
15
|
-
* @param autoFocus - Automatically focuses the input field when true. => (boolean)
|
|
16
|
-
* @param onChangeValueHandler - A callback function triggered when the input value changes.
|
|
17
|
-
* @param onBlurHandler - (optional) A callback function triggered when the input field loses focus. => If not received, the input will not be blurred.
|
|
18
|
-
* @param onFocusHandler - (optional) A callback function triggered when the input field gains focus. => If not received, the input will not be focused.
|
|
19
|
-
* @param onKeyUpHandler - (optional) A callback function triggered on key release events.
|
|
20
|
-
* @param onKeyDownHandler - (optional) A callback function triggered on key press events.
|
|
21
|
-
*
|
|
22
|
-
* @returns React.JSX.Element
|
|
23
|
-
*/
|
|
24
|
-
declare const InputCurrency: ({ placeholder, value, required, currencyUnit, textError, label, autoComplete, autoFocus, inlineCss, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled, }: InputCurrencyPropsType) => React.JSX.Element;
|
|
3
|
+
interface InputCurrencyWithRefProps extends InputCurrencyPropsType {
|
|
4
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
5
|
+
}
|
|
6
|
+
declare const InputCurrency: React.ForwardRefExoticComponent<InputCurrencyWithRefProps & React.RefAttributes<HTMLInputElement>>;
|
|
25
7
|
export default InputCurrency;
|
|
@@ -35,40 +35,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
const react_1 = __importStar(require("react"));
|
|
38
|
-
|
|
39
|
-
* InputCurrency Component
|
|
40
|
-
* A controlled input field for currency values, supporting Persian and English numerals,
|
|
41
|
-
* and providing validation, error handling, and additional handlers for customization.
|
|
42
|
-
*
|
|
43
|
-
* @param placeholder - The placeholder text for the input field.
|
|
44
|
-
* @param value - The initial value of the input field => (Just Number whit number type OR Null).
|
|
45
|
-
* @param required - Indicates if the input field is required. Displays a red asterisk (*) if true. => (boolean)
|
|
46
|
-
* @param currencyUnit - The currency unit to be displayed. => (string)
|
|
47
|
-
* @param textError - (optional) The error message to display when validation fails. => {string or null}
|
|
48
|
-
* @param label - The label for the input field. => (string)
|
|
49
|
-
* @param autoComplete - Enables or disables autocomplete => (boolean).
|
|
50
|
-
* @param autoFocus - Automatically focuses the input field when true. => (boolean)
|
|
51
|
-
* @param onChangeValueHandler - A callback function triggered when the input value changes.
|
|
52
|
-
* @param onBlurHandler - (optional) A callback function triggered when the input field loses focus. => If not received, the input will not be blurred.
|
|
53
|
-
* @param onFocusHandler - (optional) A callback function triggered when the input field gains focus. => If not received, the input will not be focused.
|
|
54
|
-
* @param onKeyUpHandler - (optional) A callback function triggered on key release events.
|
|
55
|
-
* @param onKeyDownHandler - (optional) A callback function triggered on key press events.
|
|
56
|
-
*
|
|
57
|
-
* @returns React.JSX.Element
|
|
58
|
-
*/
|
|
59
|
-
const InputCurrency = ({ placeholder, value, required, currencyUnit, textError, label, autoComplete, autoFocus, inlineCss, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled = false, }) => {
|
|
38
|
+
const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, currencyUnit, textError, label, autoComplete, autoFocus, inlineCss, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled = false, }, ref) => {
|
|
60
39
|
const [inputValue, setInputValue] = (0, react_1.useState)(value?.toString() || "");
|
|
61
|
-
const
|
|
40
|
+
const internalRef = (0, react_1.useRef)(null);
|
|
41
|
+
// Combine the external ref with the internal ref
|
|
42
|
+
react_1.default.useImperativeHandle(ref, () => internalRef.current);
|
|
62
43
|
(0, react_1.useEffect)(() => {
|
|
63
44
|
if (value !== null) {
|
|
64
45
|
setInputValue(value?.toString());
|
|
65
46
|
}
|
|
66
47
|
}, [value]);
|
|
67
|
-
// Cursor display direction
|
|
68
48
|
(0, react_1.useEffect)(() => {
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
49
|
+
if (internalRef.current && value !== null) {
|
|
50
|
+
internalRef.current.selectionStart = internalRef.current.value.length;
|
|
51
|
+
internalRef.current.selectionEnd = internalRef.current.value.length;
|
|
72
52
|
}
|
|
73
53
|
}, [value]);
|
|
74
54
|
const isErrorVisible = () => {
|
|
@@ -76,7 +56,6 @@ const InputCurrency = ({ placeholder, value, required, currencyUnit, textError,
|
|
|
76
56
|
};
|
|
77
57
|
const handleChange = (event) => {
|
|
78
58
|
const newValue = event.target.value;
|
|
79
|
-
// Being allowed to enter Persian numbers
|
|
80
59
|
const validValue = newValue.replace(/[^\d۰-۹]/g, "");
|
|
81
60
|
setInputValue(validValue);
|
|
82
61
|
onChangeValueHandler(event);
|
|
@@ -100,12 +79,13 @@ const InputCurrency = ({ placeholder, value, required, currencyUnit, textError,
|
|
|
100
79
|
react_1.default.createElement("div", { className: "w-full relative", style: inlineCss },
|
|
101
80
|
react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
|
|
102
81
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
|
|
103
|
-
react_1.default.createElement("span", { className:
|
|
82
|
+
required && react_1.default.createElement("span", { className: "text-red-primary" }, "*")),
|
|
104
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()
|
|
105
84
|
? "border-gray-tertiary focus:border-gray-quaternary"
|
|
106
85
|
: "border-red-primary"}` },
|
|
107
|
-
react_1.default.createElement("input", { ref:
|
|
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 }),
|
|
108
87
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary border-r border-gray-tertiary px-2" }, currencyUnit)),
|
|
109
|
-
!isErrorVisible() && (react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError
|
|
110
|
-
};
|
|
88
|
+
!isErrorVisible() && (react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError?.trim())))));
|
|
89
|
+
});
|
|
90
|
+
InputCurrency.displayName = "InputCurrency";
|
|
111
91
|
exports.default = InputCurrency;
|