@janiscommerce/ui-native 1.13.0 → 1.13.1
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.
|
@@ -17,18 +17,11 @@ var InputType;
|
|
|
17
17
|
InputType["amountTotal"] = "numeric";
|
|
18
18
|
InputType["numeric"] = "numeric";
|
|
19
19
|
})(InputType || (InputType = {}));
|
|
20
|
-
const setRef = (ref, value) => {
|
|
21
|
-
if (typeof ref === 'function') {
|
|
22
|
-
ref(value);
|
|
23
|
-
}
|
|
24
|
-
else if (ref && 'current' in ref) {
|
|
25
|
-
ref.current = value;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
20
|
const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChangeText, ...props }, ref) => {
|
|
29
21
|
const [value, setValue] = useState('');
|
|
30
22
|
const isAmountTotalVariant = variant === 'amountTotal';
|
|
31
|
-
const
|
|
23
|
+
const internalRef = useRef(null);
|
|
24
|
+
const inputRef = ref ?? internalRef;
|
|
32
25
|
if (isAmountTotalVariant && typeof totalValue !== 'number') {
|
|
33
26
|
return null;
|
|
34
27
|
}
|
|
@@ -52,10 +45,16 @@ const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChan
|
|
|
52
45
|
color: palette.primary.main,
|
|
53
46
|
},
|
|
54
47
|
});
|
|
55
|
-
const changeTextCb = (text) =>
|
|
48
|
+
const changeTextCb = (text) => {
|
|
49
|
+
const transformedText = handleChangeText(text, variant);
|
|
50
|
+
setValue(transformedText);
|
|
51
|
+
if (onChangeText) {
|
|
52
|
+
onChangeText(transformedText);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
56
55
|
const handlePress = () => {
|
|
57
56
|
// istanbul ignore next
|
|
58
|
-
if (inputRef.current) {
|
|
57
|
+
if (inputRef && 'current' in inputRef && inputRef.current) {
|
|
59
58
|
Keyboard.dismiss();
|
|
60
59
|
inputRef.current.focus();
|
|
61
60
|
}
|
|
@@ -71,10 +70,7 @@ const Input = forwardRef(({ style, type, variant = 'default', totalValue, onChan
|
|
|
71
70
|
})();
|
|
72
71
|
return (<TouchableWithoutFeedback onPress={handlePress}>
|
|
73
72
|
<View style={styles.container}>
|
|
74
|
-
<BaseInput style={[styles.input, style]} ref={
|
|
75
|
-
setRef(inputRef, instance);
|
|
76
|
-
setRef(ref, instance);
|
|
77
|
-
}} value={value} keyboardType={resolvedKeyboardType} onChangeText={changeTextCb} {...props}/>
|
|
73
|
+
<BaseInput style={[styles.input, style]} ref={inputRef} value={value} keyboardType={resolvedKeyboardType} onChangeText={changeTextCb} {...props}/>
|
|
78
74
|
{isAmountTotalVariant && (<Typography style={styles.totalValue} type="display" size="medium">
|
|
79
75
|
{`/${totalValue?.toString()}`}
|
|
80
76
|
</Typography>)}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { InputVariant } from '../../../Input';
|
|
2
|
-
|
|
3
|
-
declare const handleChangeText: (text: string, setValue: Dispatch<SetStateAction<string>>, variant: InputVariant, onChangeText?: ((text: string) => void) | undefined) => void;
|
|
2
|
+
declare const handleChangeText: (text: string, variant: InputVariant) => string;
|
|
4
3
|
export default handleChangeText;
|
|
@@ -9,11 +9,8 @@ const transformText = (text, variant) => {
|
|
|
9
9
|
const transform = variantLogicMapper[variant] || variantLogicMapper.default;
|
|
10
10
|
return transform(text);
|
|
11
11
|
};
|
|
12
|
-
const handleChangeText = (text,
|
|
12
|
+
const handleChangeText = (text, variant) => {
|
|
13
13
|
const transformedText = transformText(text, variant);
|
|
14
|
-
|
|
15
|
-
if (onChangeText) {
|
|
16
|
-
onChangeText(transformedText);
|
|
17
|
-
}
|
|
14
|
+
return transformedText;
|
|
18
15
|
};
|
|
19
16
|
export default handleChangeText;
|