hi-tm 0.2.3 → 0.2.4
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,5 +1,5 @@
|
|
|
1
|
-
import { InputCurrencyPropsType } from
|
|
2
|
-
import React from
|
|
1
|
+
import { InputCurrencyPropsType } from "../../types/Inputs/InputCurrencyType";
|
|
2
|
+
import React from "react";
|
|
3
3
|
/**
|
|
4
4
|
* InputCurrency Component
|
|
5
5
|
* A controlled input field for currency values, supporting Persian and English numerals,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
"use client";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -57,7 +57,7 @@ const react_1 = __importStar(require("react"));
|
|
|
57
57
|
* @returns React.JSX.Element
|
|
58
58
|
*/
|
|
59
59
|
const InputCurrency = ({ placeholder, value, required, currencyUnit, textError, label, autoComplete, autoFocus, inlineCss, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled = false, }) => {
|
|
60
|
-
const [inputValue, setInputValue] = (0, react_1.useState)(value?.toString() ||
|
|
60
|
+
const [inputValue, setInputValue] = (0, react_1.useState)(value?.toString() || "");
|
|
61
61
|
const inputRef = (0, react_1.useRef)(null);
|
|
62
62
|
(0, react_1.useEffect)(() => {
|
|
63
63
|
if (value !== null) {
|
|
@@ -72,17 +72,23 @@ const InputCurrency = ({ placeholder, value, required, currencyUnit, textError,
|
|
|
72
72
|
}
|
|
73
73
|
}, [value]);
|
|
74
74
|
const isErrorVisible = () => {
|
|
75
|
-
return !(textError && textError.trim() !==
|
|
75
|
+
return !(textError && textError.trim() !== "");
|
|
76
76
|
};
|
|
77
77
|
const handleChange = (event) => {
|
|
78
78
|
const newValue = event.target.value;
|
|
79
79
|
// Being allowed to enter Persian numbers
|
|
80
|
-
const validValue = newValue.replace(/[^\d۰-۹]/g,
|
|
80
|
+
const validValue = newValue.replace(/[^\d۰-۹]/g, "");
|
|
81
81
|
setInputValue(validValue);
|
|
82
82
|
onChangeValueHandler(event);
|
|
83
83
|
};
|
|
84
84
|
const handleKeyDown = (event) => {
|
|
85
|
-
const allowedKeys = [
|
|
85
|
+
const allowedKeys = [
|
|
86
|
+
"Backspace",
|
|
87
|
+
"ArrowLeft",
|
|
88
|
+
"ArrowRight",
|
|
89
|
+
"Delete",
|
|
90
|
+
"Tab",
|
|
91
|
+
];
|
|
86
92
|
const isNumber = /[0-9۰-۹]/.test(event.key);
|
|
87
93
|
if (!isNumber && !allowedKeys.includes(event.key)) {
|
|
88
94
|
event.preventDefault();
|
|
@@ -94,12 +100,12 @@ const InputCurrency = ({ placeholder, value, required, currencyUnit, textError,
|
|
|
94
100
|
react_1.default.createElement("div", { className: "w-full relative", style: inlineCss },
|
|
95
101
|
react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
|
|
96
102
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
|
|
97
|
-
react_1.default.createElement("span", { className: `text-red-primary ${required ?
|
|
103
|
+
react_1.default.createElement("span", { className: `text-red-primary ${required ? "opacity-100" : "opacity-0"} ` }, "*")),
|
|
98
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()
|
|
99
|
-
?
|
|
100
|
-
:
|
|
101
|
-
react_1.default.createElement("input", { ref: inputRef, type: "text", id: label, disabled: disabled, value: Number(inputValue).toLocaleString(), placeholder: placeholder, autoComplete: autoComplete ?
|
|
105
|
+
? "border-gray-tertiary focus:border-gray-quaternary"
|
|
106
|
+
: "border-red-primary"}` },
|
|
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 }),
|
|
102
108
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary border-r border-gray-tertiary px-2" }, currencyUnit)),
|
|
103
|
-
!isErrorVisible() && react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError?.trim()))));
|
|
109
|
+
!isErrorVisible() && (react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError?.trim())))));
|
|
104
110
|
};
|
|
105
111
|
exports.default = InputCurrency;
|
|
@@ -21,10 +21,10 @@ export interface DropDownPropsType {
|
|
|
21
21
|
content?: string;
|
|
22
22
|
value?: string;
|
|
23
23
|
} | null;
|
|
24
|
-
type:
|
|
24
|
+
type: "courier" | "item" | "person" | "simple" | "geography";
|
|
25
25
|
placeholder?: string;
|
|
26
26
|
modalOpenHandler?: (value: boolean) => void;
|
|
27
27
|
disable?: boolean;
|
|
28
|
-
inlineStyle?: object;
|
|
28
|
+
inlineStyle?: object | React.CSSProperties;
|
|
29
29
|
preSelectedItemById?: number;
|
|
30
30
|
}
|