hi-tm 0.14.0 → 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;
|
|
@@ -226,7 +226,7 @@ const HeaderLayout = ({ appVersion, branchName, userFirstName, sidebarHandler, u
|
|
|
226
226
|
} }))),
|
|
227
227
|
react_1.default.createElement("div", { ref: modalCloseRefuserBranchesPC, className: `relative bg-inherit ${branchNameSelected?.id === 0 ? "hidden" : "flex"}` },
|
|
228
228
|
react_1.default.createElement("div", { onClick: handleModalShowBranches, className: "select-none-custom flex flex-row items-center justify-center gap-3" },
|
|
229
|
-
react_1.default.createElement(image_1.default, { src: branchNameSelected?.logoName
|
|
229
|
+
react_1.default.createElement(image_1.default, { src: branchNameSelected?.logoName
|
|
230
230
|
? `${baseUrlCDN}/${branchName}/${branchNameSelected.logoName}`
|
|
231
231
|
: imageDefaultSRC, alt: "logo.svg", width: 24, height: 24, className: `rounded-md ${userBranchesData !== undefined && userBranchesData.length === 1
|
|
232
232
|
? "cursor-default"
|
|
@@ -244,7 +244,7 @@ const HeaderLayout = ({ appVersion, branchName, userFirstName, sidebarHandler, u
|
|
|
244
244
|
: "scale-y-0 opacity-0"} origin-top` },
|
|
245
245
|
react_1.default.createElement("ul", { className: "flex h-auto w-full flex-col items-start justify-center gap-3 bg-inherit p-3" }, userBranchesData &&
|
|
246
246
|
userBranchesData.map((item) => (react_1.default.createElement("li", { onClick: () => selectItemBranchHandler(item), key: item?.id, className: "customTransition flex w-full flex-row items-center justify-end gap-2 rounded-tiny px-5 py-2 text-text-color-primary hover:bg-gray-primary" },
|
|
247
|
-
react_1.default.createElement(image_1.default, { src: item?.logoName
|
|
247
|
+
react_1.default.createElement(image_1.default, { src: item?.logoName
|
|
248
248
|
? `${baseUrlCDN}/${branchName}/${item?.logoName}`
|
|
249
249
|
: "", alt: "logo.svg", width: 16, height: 16, className: "rounded-xl" }),
|
|
250
250
|
react_1.default.createElement("p", { className: "select-none-custom cursor-pointer text-nowrap text-sm font-normal text-text-color-primary" }, item.name))))))),
|
|
@@ -292,7 +292,7 @@ const HeaderLayout = ({ appVersion, branchName, userFirstName, sidebarHandler, u
|
|
|
292
292
|
react_1.default.createElement(image_1.default, { src: iconsSRC.menuIconSRC, alt: "menu.svg", width: 20, height: 20, className: "h-full w-full" })),
|
|
293
293
|
react_1.default.createElement("div", { ref: modalCloseRefuserBranchesMobile, className: `relative bg-inherit ${branchNameSelected?.id === 0 ? "hidden" : "flex"}` },
|
|
294
294
|
react_1.default.createElement("div", { onClick: handleModalShowBranches, className: "select-none-custom flex flex-row items-center justify-center gap-3" },
|
|
295
|
-
react_1.default.createElement(image_1.default, { src: branchNameSelected.logoName
|
|
295
|
+
react_1.default.createElement(image_1.default, { src: branchNameSelected.logoName
|
|
296
296
|
? `${baseUrlCDN}/${branchName}/${branchNameSelected.logoName}`
|
|
297
297
|
: imageDefaultSRC, alt: "logo.svg", width: 24, height: 24, className: `rounded-md ${userBranchesData !== undefined && userBranchesData.length === 1
|
|
298
298
|
? "cursor-default"
|
|
@@ -308,7 +308,7 @@ const HeaderLayout = ({ appVersion, branchName, userFirstName, sidebarHandler, u
|
|
|
308
308
|
: "scale-y-0 opacity-0"} origin-top` },
|
|
309
309
|
react_1.default.createElement("ul", { className: "flex h-auto w-full flex-col items-start justify-center gap-3 bg-inherit p-3" }, userBranchesData &&
|
|
310
310
|
userBranchesData.map((item) => (react_1.default.createElement("li", { onClick: () => selectItemBranchHandler(item), key: item?.id, className: "customTransition flex w-full flex-row items-center justify-end gap-2 rounded-tiny px-5 py-2 text-text-color-primary hover:bg-gray-primary" },
|
|
311
|
-
react_1.default.createElement(image_1.default, { src: item.logoName
|
|
311
|
+
react_1.default.createElement(image_1.default, { src: item.logoName
|
|
312
312
|
? `${baseUrlCDN}/${item.urlName || branchName}/${item.logoName}`
|
|
313
313
|
: imageDefaultSRC, alt: "logo.svg", width: 16, height: 16, className: "rounded-xl" }),
|
|
314
314
|
react_1.default.createElement("p", { className: "select-none-custom cursor-pointer text-nowrap text-sm font-normal text-text-color-primary" }, item.name))))))),
|