hi-tm 0.1.9 → 0.2.0
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.
|
@@ -5,6 +5,8 @@ interface TextInputProps extends TextInputPropsType {
|
|
|
5
5
|
maxLength?: number;
|
|
6
6
|
onlyFaChars?: boolean;
|
|
7
7
|
onlyEnChars?: boolean;
|
|
8
|
+
detectKeyboardLanguage?: boolean;
|
|
9
|
+
onKeyboardLanguageChange?: (language: string) => void;
|
|
8
10
|
}
|
|
9
|
-
declare const TextInput: ({ label, required, value, placeholderText, autoComplete, autoFocus, textError, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled, type, style, startContent, startContentStyle, placeHolderDirection, applyConditionalStyles, maxLength, onlyFaChars, onlyEnChars, }: TextInputProps) => React.JSX.Element;
|
|
11
|
+
declare const TextInput: ({ label, required, value, placeholderText, autoComplete, autoFocus, textError, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled, type, style, startContent, startContentStyle, placeHolderDirection, applyConditionalStyles, maxLength, onlyFaChars, onlyEnChars, detectKeyboardLanguage, onKeyboardLanguageChange, }: TextInputProps) => React.JSX.Element;
|
|
10
12
|
export default TextInput;
|
|
@@ -38,9 +38,35 @@ const react_1 = __importStar(require("react"));
|
|
|
38
38
|
const TextInput = ({ label, required, value, placeholderText, autoComplete, autoFocus, textError, onChangeValueHandler, onBlurHandler, onFocusHandler, onKeyUpHandler, onKeyDownHandler, disabled = false, type = 'text', style = {
|
|
39
39
|
margin: 'mt-[-6px]',
|
|
40
40
|
width: 'w-full',
|
|
41
|
-
}, startContent, startContentStyle, placeHolderDirection = 'ltr', applyConditionalStyles = false, maxLength, onlyFaChars = false, onlyEnChars = false, }) => {
|
|
41
|
+
}, startContent, startContentStyle, placeHolderDirection = 'ltr', applyConditionalStyles = false, maxLength, onlyFaChars = false, onlyEnChars = false, detectKeyboardLanguage = false, onKeyboardLanguageChange, }) => {
|
|
42
42
|
const [inputValue, setInputValue] = (0, react_1.useState)('');
|
|
43
43
|
const inputRef = (0, react_1.useRef)(null);
|
|
44
|
+
// Function to detect keyboard language
|
|
45
|
+
const detectLanguage = (text) => {
|
|
46
|
+
if (!text.trim())
|
|
47
|
+
return 'unknown';
|
|
48
|
+
// Persian/Farsi detection
|
|
49
|
+
const persianRegex = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;
|
|
50
|
+
if (persianRegex.test(text)) {
|
|
51
|
+
return 'fa';
|
|
52
|
+
}
|
|
53
|
+
// English detection
|
|
54
|
+
const englishRegex = /[a-zA-Z]/;
|
|
55
|
+
if (englishRegex.test(text)) {
|
|
56
|
+
return 'en';
|
|
57
|
+
}
|
|
58
|
+
// Arabic detection
|
|
59
|
+
const arabicRegex = /[\u0600-\u06FF\u0750-\u077F]/;
|
|
60
|
+
if (arabicRegex.test(text)) {
|
|
61
|
+
return 'ar';
|
|
62
|
+
}
|
|
63
|
+
// Number detection
|
|
64
|
+
const numberRegex = /[0-9]/;
|
|
65
|
+
if (numberRegex.test(text)) {
|
|
66
|
+
return 'number';
|
|
67
|
+
}
|
|
68
|
+
return 'unknown';
|
|
69
|
+
};
|
|
44
70
|
const handleInputChange = (e) => {
|
|
45
71
|
let newValue = e.target.value;
|
|
46
72
|
// Apply captcha validation if type is 'captcha'
|
|
@@ -67,6 +93,11 @@ const TextInput = ({ label, required, value, placeholderText, autoComplete, auto
|
|
|
67
93
|
}
|
|
68
94
|
setInputValue(newValue);
|
|
69
95
|
onChangeValueHandler(e);
|
|
96
|
+
// Detect keyboard language if enabled
|
|
97
|
+
if (detectKeyboardLanguage && onKeyboardLanguageChange) {
|
|
98
|
+
const detectedLanguage = detectLanguage(newValue);
|
|
99
|
+
onKeyboardLanguageChange(detectedLanguage);
|
|
100
|
+
}
|
|
70
101
|
};
|
|
71
102
|
const handleFocus = (e) => {
|
|
72
103
|
if (onFocusHandler) {
|