@cdek-it/react-native-ui-kit 0.2.4 → 0.2.6
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/dist/components/Input/InputTextBase/InputTextBase.d.ts +0 -2
- package/dist/components/Input/InputTextBase/InputTextBase.js +33 -14
- package/dist/components/Input/InputTextBase/testIds.d.ts +1 -0
- package/dist/components/Input/InputTextBase/testIds.js +1 -0
- package/dist/components/Input/InputTextBase/useStyles.d.ts +27 -8
- package/dist/components/Input/InputTextBase/useStyles.js +26 -6
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IconEye, IconEyeOff, IconLoader2, IconLock, IconX, } from '@tabler/icons-react-native';
|
|
2
2
|
import { memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
|
-
import { TextInput, View, TouchableOpacity, Pressable, } from 'react-native';
|
|
3
|
+
import { TextInput, View, Text, TouchableOpacity, Pressable, } from 'react-native';
|
|
4
4
|
import Animated, { interpolate, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated';
|
|
5
5
|
import { useLoadingRotationAnimation } from '../../../hooks/useLoadingRotationAnimation';
|
|
6
6
|
import { useMakeTestId } from '../../../hooks/useMakeTestId';
|
|
@@ -13,7 +13,7 @@ import { useStyles } from './useStyles';
|
|
|
13
13
|
*/
|
|
14
14
|
export const InputTextBase = memo(
|
|
15
15
|
// eslint-disable-next-line max-lines-per-function
|
|
16
|
-
({ state, clearable = true, secureTextEntry: secureTextEntryProp = false, inputRef: propsInputRef, disabled, containerStyle,
|
|
16
|
+
({ state, clearable = true, secureTextEntry: secureTextEntryProp = false, inputRef: propsInputRef, disabled, containerStyle, loading, renderTextInput, clearButtonAccessibilityLabel, floatLabel = false, placeholder, ...otherProps }) => {
|
|
17
17
|
const styles = useStyles();
|
|
18
18
|
const inputRef = useRef(null);
|
|
19
19
|
const [valueState, setValueState] = useState('');
|
|
@@ -63,34 +63,36 @@ export const InputTextBase = memo(
|
|
|
63
63
|
: secureTextEntryProp, [secureTextEntryProp, userDefinedSecureTextEntry]);
|
|
64
64
|
const toggleUserDefinedSecureTextEntry = useCallback(() => setUserDefinedSecureTextEntry((old) => !old), []);
|
|
65
65
|
const texInputProps = useMemo(() => ({
|
|
66
|
-
placeholderTextColor: styles.placeholderTextColor.color,
|
|
67
66
|
...otherProps,
|
|
68
|
-
|
|
67
|
+
allowFontScaling: floatLabel ? false : otherProps.allowFontScaling,
|
|
68
|
+
placeholder: '',
|
|
69
69
|
testID: makeTestId(),
|
|
70
70
|
editable: !disabled,
|
|
71
71
|
secureTextEntry,
|
|
72
|
-
style: [
|
|
72
|
+
style: [
|
|
73
|
+
styles.inputFont,
|
|
74
|
+
floatLabel ? styles.floatLabelInput : styles.input,
|
|
75
|
+
],
|
|
73
76
|
inputRef,
|
|
74
77
|
value,
|
|
75
78
|
onBlur,
|
|
76
79
|
onChangeText,
|
|
77
80
|
onFocus,
|
|
78
81
|
}), [
|
|
79
|
-
styles.placeholderTextColor.color,
|
|
80
|
-
styles.input,
|
|
81
|
-
styles.inputFloatLabel,
|
|
82
82
|
otherProps,
|
|
83
83
|
floatLabel,
|
|
84
|
-
placeholder,
|
|
85
84
|
makeTestId,
|
|
86
85
|
disabled,
|
|
87
86
|
secureTextEntry,
|
|
88
|
-
|
|
87
|
+
styles.floatLabelInput,
|
|
88
|
+
styles.inputFont,
|
|
89
|
+
styles.input,
|
|
89
90
|
value,
|
|
90
91
|
onBlur,
|
|
91
92
|
onChangeText,
|
|
92
93
|
onFocus,
|
|
93
94
|
]);
|
|
95
|
+
const input = useMemo(() => renderTextInput ? (renderTextInput(texInputProps)) : (<TextInput {...texInputProps} ref={inputRef}/>), [renderTextInput, texInputProps]);
|
|
94
96
|
return (<Pressable accessible={false} disabled={disabled} style={[
|
|
95
97
|
styles.container,
|
|
96
98
|
floatLabel && styles.containerFloatLabel,
|
|
@@ -100,10 +102,27 @@ export const InputTextBase = memo(
|
|
|
100
102
|
state === 'danger' && isFocused && styles.dangerFocused,
|
|
101
103
|
disabled && styles.disabled,
|
|
102
104
|
]} testID={makeTestId(InputTextBaseTestId.pressableContainer)} onPress={onContainerPress}>
|
|
103
|
-
{floatLabel ? (
|
|
104
|
-
{
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
{floatLabel ? (<>
|
|
106
|
+
<Animated.Text allowFontScaling={false} numberOfLines={1} style={[styles.label, labelAnimatedStyle]} testID={makeTestId(InputTextBaseTestId.floatingPlaceholder)}>
|
|
107
|
+
{placeholder}
|
|
108
|
+
</Animated.Text>
|
|
109
|
+
|
|
110
|
+
{input}
|
|
111
|
+
</>) : (<View style={styles.inputContainer}>
|
|
112
|
+
{input}
|
|
113
|
+
|
|
114
|
+
<Text pointerEvents='none' style={[
|
|
115
|
+
styles.inputFont,
|
|
116
|
+
styles.placeholder,
|
|
117
|
+
styles.placeholderTextColor,
|
|
118
|
+
otherProps.placeholderTextColor && {
|
|
119
|
+
color: otherProps.placeholderTextColor,
|
|
120
|
+
},
|
|
121
|
+
value && styles.hidden,
|
|
122
|
+
]} testID={makeTestId(InputTextBaseTestId.placeholder)}>
|
|
123
|
+
{placeholder}
|
|
124
|
+
</Text>
|
|
125
|
+
</View>)}
|
|
107
126
|
|
|
108
127
|
<View style={styles.rightContainer}>
|
|
109
128
|
{loading ? (<Animated.View style={loadingAnimatedStyle} testID={makeTestId(InputTextBaseTestId.loading)}>
|
|
@@ -6,7 +6,6 @@ export declare const useStyles: () => {
|
|
|
6
6
|
borderRadius: number;
|
|
7
7
|
borderColor: string;
|
|
8
8
|
backgroundColor: string;
|
|
9
|
-
justifyContent: "center";
|
|
10
9
|
};
|
|
11
10
|
containerFocused: {
|
|
12
11
|
outlineColor: string;
|
|
@@ -28,21 +27,37 @@ export declare const useStyles: () => {
|
|
|
28
27
|
borderColor: string;
|
|
29
28
|
backgroundColor: string;
|
|
30
29
|
};
|
|
30
|
+
inputContainer: {
|
|
31
|
+
flex: number;
|
|
32
|
+
paddingLeft: number;
|
|
33
|
+
justifyContent: "center";
|
|
34
|
+
};
|
|
31
35
|
input: {
|
|
36
|
+
padding: number;
|
|
37
|
+
paddingHorizontal: number;
|
|
38
|
+
position: "absolute";
|
|
39
|
+
left: number;
|
|
40
|
+
right: number;
|
|
41
|
+
top: number;
|
|
42
|
+
bottom: number;
|
|
43
|
+
};
|
|
44
|
+
floatLabelInput: {
|
|
32
45
|
flex: number;
|
|
33
46
|
paddingHorizontal: number;
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
paddingTop: number;
|
|
48
|
+
paddingBottom: number;
|
|
36
49
|
borderRadius: number;
|
|
37
|
-
color: string;
|
|
38
50
|
overflow: "hidden";
|
|
51
|
+
};
|
|
52
|
+
inputFont: {
|
|
53
|
+
fontSize: number;
|
|
54
|
+
color: string;
|
|
39
55
|
includeFontPadding: false;
|
|
40
|
-
verticalAlign: "middle";
|
|
41
56
|
fontFamily: string;
|
|
57
|
+
verticalAlign: "middle";
|
|
42
58
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
paddingBottom: number;
|
|
59
|
+
placeholder: {
|
|
60
|
+
paddingHorizontal: number;
|
|
46
61
|
};
|
|
47
62
|
placeholderTextColor: {
|
|
48
63
|
color: string;
|
|
@@ -68,6 +83,7 @@ export declare const useStyles: () => {
|
|
|
68
83
|
label: {
|
|
69
84
|
position: "absolute";
|
|
70
85
|
left: number;
|
|
86
|
+
right: number;
|
|
71
87
|
top: number;
|
|
72
88
|
paddingVertical: number;
|
|
73
89
|
paddingLeft: number;
|
|
@@ -84,4 +100,7 @@ export declare const useStyles: () => {
|
|
|
84
100
|
top: number;
|
|
85
101
|
fontFamily: string;
|
|
86
102
|
};
|
|
103
|
+
hidden: {
|
|
104
|
+
opacity: number;
|
|
105
|
+
};
|
|
87
106
|
};
|
|
@@ -7,7 +7,6 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
7
7
|
borderRadius: border.Radius['rounded-xl'],
|
|
8
8
|
borderColor: theme.Form.InputText.inputBorderColor,
|
|
9
9
|
backgroundColor: theme.Form.InputText.inputBg,
|
|
10
|
-
justifyContent: 'center',
|
|
11
10
|
},
|
|
12
11
|
containerFocused: {
|
|
13
12
|
outlineColor: theme.General.focusOutlineColor,
|
|
@@ -25,19 +24,38 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
25
24
|
borderColor: theme.Form.InputText.inputBorderColor,
|
|
26
25
|
backgroundColor: theme.Button.Disabled.disabledButtonBg,
|
|
27
26
|
},
|
|
27
|
+
inputContainer: {
|
|
28
|
+
flex: 1,
|
|
29
|
+
paddingLeft: 2, // отступ для курсора
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
},
|
|
28
32
|
input: {
|
|
33
|
+
padding: 0,
|
|
34
|
+
paddingHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
35
|
+
position: 'absolute',
|
|
36
|
+
left: 0,
|
|
37
|
+
right: 0,
|
|
38
|
+
top: 0,
|
|
39
|
+
bottom: 0,
|
|
40
|
+
},
|
|
41
|
+
floatLabelInput: {
|
|
29
42
|
flex: 1,
|
|
30
43
|
paddingHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
paddingTop: 26,
|
|
45
|
+
paddingBottom: 12,
|
|
33
46
|
borderRadius: border.Radius['rounded-xl'],
|
|
34
|
-
color: theme.Form.InputText.inputTextColor,
|
|
35
47
|
overflow: 'hidden',
|
|
48
|
+
},
|
|
49
|
+
inputFont: {
|
|
50
|
+
fontSize: typography.Size['text-base'],
|
|
51
|
+
color: theme.Form.InputText.inputTextColor,
|
|
36
52
|
includeFontPadding: false,
|
|
37
|
-
verticalAlign: 'middle',
|
|
38
53
|
fontFamily: fonts.secondary,
|
|
54
|
+
verticalAlign: 'middle',
|
|
55
|
+
},
|
|
56
|
+
placeholder: {
|
|
57
|
+
paddingHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
39
58
|
},
|
|
40
|
-
inputFloatLabel: { paddingTop: 26, paddingBottom: 12 },
|
|
41
59
|
placeholderTextColor: {
|
|
42
60
|
color: theme.Form.InputText.inputPlaceholderTextColor,
|
|
43
61
|
},
|
|
@@ -60,6 +78,7 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
60
78
|
label: {
|
|
61
79
|
position: 'absolute',
|
|
62
80
|
left: 7,
|
|
81
|
+
right: 7,
|
|
63
82
|
top: 19,
|
|
64
83
|
paddingVertical: 0,
|
|
65
84
|
paddingLeft: spacing.Padding['p-1'],
|
|
@@ -76,4 +95,5 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
76
95
|
top: 7,
|
|
77
96
|
fontFamily: fonts.primary,
|
|
78
97
|
},
|
|
98
|
+
hidden: { opacity: 0 },
|
|
79
99
|
}));
|
package/package.json
CHANGED