hi-tm 0.13.6 → 0.13.8
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,7 +1,25 @@
|
|
|
1
1
|
import { InputCurrencyPropsType } from "../../types/Inputs/InputCurrencyType";
|
|
2
2
|
import React from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* InputCurrency Component
|
|
5
|
+
* A controlled input field for currency values, supporting Persian and English numerals,
|
|
6
|
+
* and providing validation, error handling, and additional handlers for customization.
|
|
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;
|
|
7
25
|
export default InputCurrency;
|
|
@@ -35,20 +35,40 @@ 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
|
-
|
|
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, }) => {
|
|
39
60
|
const [inputValue, setInputValue] = (0, react_1.useState)(value?.toString() || "");
|
|
40
|
-
const
|
|
41
|
-
// Combine the external ref with the internal ref
|
|
42
|
-
react_1.default.useImperativeHandle(ref, () => internalRef.current);
|
|
61
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
43
62
|
(0, react_1.useEffect)(() => {
|
|
44
63
|
if (value !== null) {
|
|
45
64
|
setInputValue(value?.toString());
|
|
46
65
|
}
|
|
47
66
|
}, [value]);
|
|
67
|
+
// Cursor display direction
|
|
48
68
|
(0, react_1.useEffect)(() => {
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
if (inputRef.current && value !== null) {
|
|
70
|
+
inputRef.current.selectionStart = inputRef.current.value.length;
|
|
71
|
+
inputRef.current.selectionEnd = inputRef.current.value.length;
|
|
52
72
|
}
|
|
53
73
|
}, [value]);
|
|
54
74
|
const isErrorVisible = () => {
|
|
@@ -56,6 +76,7 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
|
|
|
56
76
|
};
|
|
57
77
|
const handleChange = (event) => {
|
|
58
78
|
const newValue = event.target.value;
|
|
79
|
+
// Being allowed to enter Persian numbers
|
|
59
80
|
const validValue = newValue.replace(/[^\d۰-۹]/g, "");
|
|
60
81
|
setInputValue(validValue);
|
|
61
82
|
onChangeValueHandler(event);
|
|
@@ -79,13 +100,12 @@ const InputCurrency = (0, react_1.forwardRef)(({ placeholder, value, required, c
|
|
|
79
100
|
react_1.default.createElement("div", { className: "w-full relative", style: inlineCss },
|
|
80
101
|
react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
|
|
81
102
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
|
|
82
|
-
|
|
103
|
+
react_1.default.createElement("span", { className: `text-red-primary ${required ? "opacity-100" : "opacity-0"} ` }, "*")),
|
|
83
104
|
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
105
|
? "border-gray-tertiary focus:border-gray-quaternary"
|
|
85
106
|
: "border-red-primary"}` },
|
|
86
|
-
react_1.default.createElement("input", { ref:
|
|
107
|
+
react_1.default.createElement("input", { ref: inputRef, 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 }),
|
|
87
108
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary border-r border-gray-tertiary px-2" }, currencyUnit)),
|
|
88
109
|
!isErrorVisible() && (react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError?.trim())))));
|
|
89
|
-
}
|
|
90
|
-
InputCurrency.displayName = "InputCurrency";
|
|
110
|
+
};
|
|
91
111
|
exports.default = InputCurrency;
|