ikualo-ui-kit-mobile 2.1.12 → 2.1.15
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.
- package/app.json +1 -1
- package/assets/styles/elements/buttons.ts +3 -1
- package/package.json +1 -1
- package/src/elements/inputs/Input.tsx +63 -19
package/app.json
CHANGED
|
@@ -30,15 +30,17 @@ const getStylesButtonContained = (theme: ITheme) =>
|
|
|
30
30
|
'btn-contained--sm': {
|
|
31
31
|
padding: 0,
|
|
32
32
|
width: 'auto',
|
|
33
|
-
minWidth:
|
|
33
|
+
minWidth: 150,
|
|
34
34
|
},
|
|
35
35
|
'btn-contained--md': {
|
|
36
36
|
paddingVertical: 3,
|
|
37
37
|
paddingHorizontal: 32,
|
|
38
|
+
minWidth: 150,
|
|
38
39
|
},
|
|
39
40
|
'btn-contained--xl': {
|
|
40
41
|
paddingVertical: 3,
|
|
41
42
|
width: 'auto',
|
|
43
|
+
minWidth: 150,
|
|
42
44
|
},
|
|
43
45
|
});
|
|
44
46
|
const getStylesButtonOutlined = (theme: ITheme) =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HelperText, TextInput, Text } from 'react-native-paper';
|
|
2
2
|
import { getStyleInput } from '../../../assets/styles/elements/inputs';
|
|
3
|
-
import { useState } from 'react';
|
|
3
|
+
import { useState, useCallback, useEffect, useRef } from 'react';
|
|
4
4
|
import { View } from 'react-native';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import useStore from '../../store';
|
|
@@ -43,25 +43,64 @@ export const Input = (props: IInputText) => {
|
|
|
43
43
|
const patternNumber = /^[0-9]*$/;
|
|
44
44
|
const patternAlphanumeric = /^[a-zA-Z0-9]*$/;
|
|
45
45
|
const patternLettersWithAccentsAndSpaces = /^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]*$/;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
|
|
47
|
+
// Normalizar el valor para asegurar que siempre sea una cadena
|
|
48
|
+
const normalizedValue = value ?? '';
|
|
49
|
+
const stringValue = typeof normalizedValue === 'string' ? normalizedValue : String(normalizedValue);
|
|
50
|
+
|
|
51
|
+
// Estado local para controlar el valor del input
|
|
52
|
+
const [localValue, setLocalValue] = useState<string>(stringValue);
|
|
53
|
+
const isUserTypingRef = useRef<boolean>(false);
|
|
54
|
+
const lastPropValueRef = useRef<string>(stringValue);
|
|
55
|
+
|
|
56
|
+
// Sincronizar el estado local con el prop value cuando cambia desde fuera
|
|
57
|
+
// Solo si el usuario no está escribiendo
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!isUserTypingRef.current && stringValue !== lastPropValueRef.current) {
|
|
60
|
+
lastPropValueRef.current = stringValue;
|
|
61
|
+
setLocalValue(stringValue);
|
|
57
62
|
}
|
|
58
|
-
};
|
|
63
|
+
}, [stringValue]);
|
|
64
|
+
|
|
65
|
+
const onChangeText = useCallback(
|
|
66
|
+
(text: string) => {
|
|
67
|
+
// Asegurar que el texto sea una cadena
|
|
68
|
+
const cleanText = typeof text === 'string' ? text : String(text);
|
|
69
|
+
|
|
70
|
+
// Marcar que el usuario está escribiendo
|
|
71
|
+
isUserTypingRef.current = true;
|
|
72
|
+
|
|
73
|
+
// Actualizar el estado local inmediatamente
|
|
74
|
+
setLocalValue(cleanText);
|
|
75
|
+
lastPropValueRef.current = cleanText;
|
|
76
|
+
|
|
77
|
+
// Pasar el texto directamente al onChange
|
|
78
|
+
onChange(cleanText);
|
|
79
|
+
|
|
80
|
+
// Resetear el flag después de un breve delay
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
isUserTypingRef.current = false;
|
|
83
|
+
}, 50);
|
|
84
|
+
|
|
85
|
+
setErrorRequired(false);
|
|
86
|
+
if (type === 'number' && !patternNumber.test(cleanText)) {
|
|
87
|
+
onInvalid && onInvalid();
|
|
88
|
+
} else if (type === 'alphanumeric' && !patternAlphanumeric.test(cleanText)) {
|
|
89
|
+
onInvalid && onInvalid();
|
|
90
|
+
} else if (type === 'text' && !patternLettersWithAccentsAndSpaces.test(cleanText)) {
|
|
91
|
+
onInvalid && onInvalid();
|
|
92
|
+
} else if (pattern && !pattern.test(cleanText)) {
|
|
93
|
+
onInvalid && onInvalid();
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
[onChange, type, pattern, onInvalid]
|
|
97
|
+
);
|
|
59
98
|
return (
|
|
60
99
|
<View>
|
|
61
100
|
<TextInput
|
|
62
|
-
label={!isFocus && placeholder && value
|
|
101
|
+
label={!isFocus && placeholder && (!value || value.trim() === '') ? placeholder : label}
|
|
63
102
|
mode={mode ?? 'flat'}
|
|
64
|
-
value={
|
|
103
|
+
value={localValue}
|
|
65
104
|
onChangeText={onChangeText}
|
|
66
105
|
maxLength={maxLength}
|
|
67
106
|
selectionColor={
|
|
@@ -95,7 +134,7 @@ export const Input = (props: IInputText) => {
|
|
|
95
134
|
isFocus && isValid && !errorRequired && { backgroundColor: 'transparent' },
|
|
96
135
|
style ?? [],
|
|
97
136
|
]}
|
|
98
|
-
contentStyle={[styleInput['input-txt'], contentStyle ??
|
|
137
|
+
contentStyle={[styleInput['input-txt'], contentStyle ?? []]}
|
|
99
138
|
underlineColor={
|
|
100
139
|
underlineColor
|
|
101
140
|
? underlineColor
|
|
@@ -106,7 +145,7 @@ export const Input = (props: IInputText) => {
|
|
|
106
145
|
activeUnderlineColor={
|
|
107
146
|
activeUnderlineColor
|
|
108
147
|
? activeUnderlineColor
|
|
109
|
-
: !isValid && value
|
|
148
|
+
: !isValid && value && value.trim() !== ''
|
|
110
149
|
? styleInput['input-text--activeUnderline'].color
|
|
111
150
|
: errorRequired
|
|
112
151
|
? styleInput['input-txt-error'].color
|
|
@@ -114,9 +153,14 @@ export const Input = (props: IInputText) => {
|
|
|
114
153
|
}
|
|
115
154
|
underlineStyle={{ height: isFocus ? 1.5 : 2 }}
|
|
116
155
|
keyboardType={type === 'number' ? 'numeric' : 'default'}
|
|
156
|
+
autoCorrect={false}
|
|
157
|
+
autoCapitalize="none"
|
|
158
|
+
autoComplete="off"
|
|
159
|
+
textContentType="none"
|
|
160
|
+
spellCheck={false}
|
|
117
161
|
right={icon && <TextInput.Icon color={theme.colors.icon} icon={icon ?? ''} />}
|
|
118
|
-
|
|
119
|
-
|
|
162
|
+
disabled={isDisabled}
|
|
163
|
+
readOnly={readonly}
|
|
120
164
|
/>
|
|
121
165
|
{!isDisabled && (
|
|
122
166
|
<>
|