@cdek-it/react-native-ui-kit 0.2.7 → 0.2.8
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,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
1
2
|
import { IconEye, IconEyeOff, IconLoader2, IconLock, IconX, } from '@tabler/icons-react-native';
|
|
2
3
|
import { memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
4
|
import { TextInput, View, Text, TouchableOpacity, Pressable, } from 'react-native';
|
|
@@ -13,7 +14,10 @@ import { useStyles } from './useStyles';
|
|
|
13
14
|
*/
|
|
14
15
|
export const InputTextBase = memo(
|
|
15
16
|
// eslint-disable-next-line max-lines-per-function
|
|
16
|
-
({ state, clearable = true, secureTextEntry: secureTextEntryProp = false, inputRef: propsInputRef, disabled, containerStyle, loading, renderTextInput, clearButtonAccessibilityLabel, floatLabel = false, placeholder, ...otherProps
|
|
17
|
+
({ state, clearable = true, secureTextEntry: secureTextEntryProp = false, inputRef: propsInputRef, disabled, containerStyle, loading, renderTextInput, clearButtonAccessibilityLabel, floatLabel = false, placeholder, ...otherProps
|
|
18
|
+
// TODO: разделить float label и обычный инпут -> добавить во float label поддержку font scale
|
|
19
|
+
// eslint-disable-next-line complexity
|
|
20
|
+
}) => {
|
|
17
21
|
const styles = useStyles();
|
|
18
22
|
const inputRef = useRef(null);
|
|
19
23
|
const [valueState, setValueState] = useState('');
|
|
@@ -32,11 +36,10 @@ export const InputTextBase = memo(
|
|
|
32
36
|
setValueState(nextValue);
|
|
33
37
|
}, [otherProps]);
|
|
34
38
|
const clear = useCallback(() => {
|
|
35
|
-
inputRef.current?.clear();
|
|
36
39
|
onChangeText('');
|
|
37
40
|
}, [onChangeText]);
|
|
38
41
|
const value = useMemo(() => otherProps.value ?? valueState, [otherProps.value, valueState]);
|
|
39
|
-
const showClearButton = useMemo(() => clearable && !!value.length, [clearable, value.length]);
|
|
42
|
+
const showClearButton = useMemo(() => clearable && !!value.length && !disabled, [clearable, disabled, value.length]);
|
|
40
43
|
const onContainerPress = useCallback(() => {
|
|
41
44
|
inputRef.current?.focus();
|
|
42
45
|
}, []);
|
|
@@ -55,13 +58,21 @@ export const InputTextBase = memo(
|
|
|
55
58
|
});
|
|
56
59
|
}, [isFocused, labelAnimation, value]);
|
|
57
60
|
const iconSize = useMemo(() => (floatLabel ? styles.iconSizeFloatLabel : styles.iconSize), [floatLabel, styles.iconSize, styles.iconSizeFloatLabel]);
|
|
58
|
-
useImperativeHandle(propsInputRef, () => (inputRef.current ? inputRef.current : null), [inputRef]);
|
|
61
|
+
useImperativeHandle(propsInputRef, () => (inputRef.current ? { ...inputRef.current, clear } : null), [inputRef, clear]);
|
|
59
62
|
const { makeTestId } = useMakeTestId(otherProps.testID || InputTextBaseTestId.default);
|
|
60
63
|
const [userDefinedSecureTextEntry, setUserDefinedSecureTextEntry] = useState(true);
|
|
61
64
|
const secureTextEntry = useMemo(() => secureTextEntryProp === 'toggleable'
|
|
62
65
|
? userDefinedSecureTextEntry
|
|
63
66
|
: secureTextEntryProp, [secureTextEntryProp, userDefinedSecureTextEntry]);
|
|
64
67
|
const toggleUserDefinedSecureTextEntry = useCallback(() => setUserDefinedSecureTextEntry((old) => !old), []);
|
|
68
|
+
const showSecureToggle = secureTextEntryProp === 'toggleable';
|
|
69
|
+
const hasRightContent = loading || showClearButton || showSecureToggle || disabled;
|
|
70
|
+
const rightButtonHitSlop = useMemo(() => ({
|
|
71
|
+
top: 0,
|
|
72
|
+
bottom: 0,
|
|
73
|
+
left: styles.rightContainer.gap / 2,
|
|
74
|
+
right: styles.rightContainer.gap / 2,
|
|
75
|
+
}), [styles.rightContainer.gap]);
|
|
65
76
|
const texInputProps = useMemo(() => ({
|
|
66
77
|
...otherProps,
|
|
67
78
|
allowFontScaling: floatLabel ? false : otherProps.allowFontScaling,
|
|
@@ -72,6 +83,7 @@ export const InputTextBase = memo(
|
|
|
72
83
|
style: [
|
|
73
84
|
styles.inputFont,
|
|
74
85
|
floatLabel ? styles.floatLabelInput : styles.input,
|
|
86
|
+
hasRightContent && styles.inputWithRightContent,
|
|
75
87
|
],
|
|
76
88
|
inputRef,
|
|
77
89
|
value,
|
|
@@ -84,9 +96,11 @@ export const InputTextBase = memo(
|
|
|
84
96
|
makeTestId,
|
|
85
97
|
disabled,
|
|
86
98
|
secureTextEntry,
|
|
87
|
-
styles.floatLabelInput,
|
|
88
99
|
styles.inputFont,
|
|
100
|
+
styles.floatLabelInput,
|
|
89
101
|
styles.input,
|
|
102
|
+
styles.inputWithRightContent,
|
|
103
|
+
hasRightContent,
|
|
90
104
|
value,
|
|
91
105
|
onBlur,
|
|
92
106
|
onChangeText,
|
|
@@ -124,20 +138,20 @@ export const InputTextBase = memo(
|
|
|
124
138
|
{input}
|
|
125
139
|
</View>)}
|
|
126
140
|
|
|
127
|
-
<View style={styles.rightContainer}>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
{hasRightContent ? (<View style={styles.rightContainer}>
|
|
142
|
+
{loading ? (<Animated.View style={[styles.rightButtonContainer, loadingAnimatedStyle]} testID={makeTestId(InputTextBaseTestId.loading)}>
|
|
143
|
+
<IconLoader2 color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>
|
|
144
|
+
</Animated.View>) : null}
|
|
131
145
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
146
|
+
{showClearButton ? (<TouchableOpacity accessibilityLabel={clearButtonAccessibilityLabel} hitSlop={rightButtonHitSlop} style={styles.rightButtonContainer} testID={makeTestId(InputTextBaseTestId.clearButton)} onPress={clear}>
|
|
147
|
+
<IconX color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>
|
|
148
|
+
</TouchableOpacity>) : null}
|
|
135
149
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
150
|
+
{showSecureToggle ? (<TouchableOpacity hitSlop={rightButtonHitSlop} style={styles.rightButtonContainer} testID={makeTestId(InputTextBaseTestId.secureInputButton)} onPress={toggleUserDefinedSecureTextEntry}>
|
|
151
|
+
{userDefinedSecureTextEntry ? (<IconEye color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>) : (<IconEyeOff color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>)}
|
|
152
|
+
</TouchableOpacity>) : null}
|
|
139
153
|
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
{disabled ? (<IconLock color={styles.rightIcon.color} height={iconSize.height} testID={makeTestId(InputTextBaseTestId.disabledIcon)} width={iconSize.width}/>) : null}
|
|
155
|
+
</View>) : null}
|
|
142
156
|
</Pressable>);
|
|
143
157
|
});
|
|
@@ -41,6 +41,9 @@ export declare const useStyles: () => {
|
|
|
41
41
|
top: number;
|
|
42
42
|
bottom: number;
|
|
43
43
|
};
|
|
44
|
+
inputWithRightContent: {
|
|
45
|
+
paddingRight: number;
|
|
46
|
+
};
|
|
44
47
|
floatLabelInput: {
|
|
45
48
|
flex: number;
|
|
46
49
|
paddingHorizontal: number;
|
|
@@ -64,11 +67,13 @@ export declare const useStyles: () => {
|
|
|
64
67
|
};
|
|
65
68
|
rightContainer: {
|
|
66
69
|
flexDirection: "row";
|
|
67
|
-
|
|
68
|
-
paddingRight: number;
|
|
70
|
+
paddingHorizontal: number;
|
|
69
71
|
gap: number;
|
|
70
72
|
overflow: "hidden";
|
|
71
73
|
};
|
|
74
|
+
rightButtonContainer: {
|
|
75
|
+
justifyContent: "center";
|
|
76
|
+
};
|
|
72
77
|
rightIcon: {
|
|
73
78
|
color: string;
|
|
74
79
|
};
|
|
@@ -38,6 +38,7 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
38
38
|
top: 0,
|
|
39
39
|
bottom: 0,
|
|
40
40
|
},
|
|
41
|
+
inputWithRightContent: { paddingRight: 0 },
|
|
41
42
|
floatLabelInput: {
|
|
42
43
|
flex: 1,
|
|
43
44
|
paddingHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
@@ -61,11 +62,11 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
61
62
|
},
|
|
62
63
|
rightContainer: {
|
|
63
64
|
flexDirection: 'row',
|
|
64
|
-
|
|
65
|
-
paddingRight: theme.Form.InputText.inputPaddingLeftRight,
|
|
65
|
+
paddingHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
66
66
|
gap: theme.Form.InputText.inputPaddingLeftRight,
|
|
67
67
|
overflow: 'hidden',
|
|
68
68
|
},
|
|
69
|
+
rightButtonContainer: { justifyContent: 'center' },
|
|
69
70
|
rightIcon: { color: theme.Form.InputText.inputIconColor },
|
|
70
71
|
iconSize: {
|
|
71
72
|
width: typography.Size['text-base'],
|
package/package.json
CHANGED