@cdek-it/react-native-ui-kit 0.2.3 → 0.2.5
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 +32 -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 +25 -8
- package/dist/components/Input/InputTextBase/useStyles.js +19 -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,26 @@ 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 style={[
|
|
115
|
+
styles.inputFont,
|
|
116
|
+
styles.placeholderTextColor,
|
|
117
|
+
otherProps.placeholderTextColor && {
|
|
118
|
+
color: otherProps.placeholderTextColor,
|
|
119
|
+
},
|
|
120
|
+
value && styles.hidden,
|
|
121
|
+
]} testID={makeTestId(InputTextBaseTestId.placeholder)}>
|
|
122
|
+
{placeholder}
|
|
123
|
+
</Text>
|
|
124
|
+
</View>)}
|
|
107
125
|
|
|
108
126
|
<View style={styles.rightContainer}>
|
|
109
127
|
{loading ? (<Animated.View style={loadingAnimatedStyle} testID={makeTestId(InputTextBaseTestId.loading)}>
|
|
@@ -6,7 +6,7 @@ export declare const useStyles: () => {
|
|
|
6
6
|
borderRadius: number;
|
|
7
7
|
borderColor: string;
|
|
8
8
|
backgroundColor: string;
|
|
9
|
-
|
|
9
|
+
alignItems: "center";
|
|
10
10
|
};
|
|
11
11
|
containerFocused: {
|
|
12
12
|
outlineColor: string;
|
|
@@ -16,6 +16,7 @@ export declare const useStyles: () => {
|
|
|
16
16
|
minHeight: number;
|
|
17
17
|
maxHeight: number;
|
|
18
18
|
height: number;
|
|
19
|
+
alignItems: "stretch";
|
|
19
20
|
};
|
|
20
21
|
danger: {
|
|
21
22
|
borderColor: string;
|
|
@@ -28,20 +29,32 @@ export declare const useStyles: () => {
|
|
|
28
29
|
borderColor: string;
|
|
29
30
|
backgroundColor: string;
|
|
30
31
|
};
|
|
32
|
+
inputContainer: {
|
|
33
|
+
flex: number;
|
|
34
|
+
marginHorizontal: number;
|
|
35
|
+
paddingLeft: number;
|
|
36
|
+
justifyContent: "center";
|
|
37
|
+
};
|
|
31
38
|
input: {
|
|
39
|
+
padding: number;
|
|
40
|
+
position: "absolute";
|
|
41
|
+
left: number;
|
|
42
|
+
right: number;
|
|
43
|
+
};
|
|
44
|
+
floatLabelInput: {
|
|
32
45
|
flex: number;
|
|
33
46
|
paddingHorizontal: number;
|
|
34
|
-
|
|
47
|
+
paddingTop: number;
|
|
48
|
+
paddingBottom: number;
|
|
35
49
|
borderRadius: number;
|
|
36
|
-
color: string;
|
|
37
50
|
overflow: "hidden";
|
|
51
|
+
};
|
|
52
|
+
inputFont: {
|
|
53
|
+
fontSize: number;
|
|
54
|
+
color: string;
|
|
38
55
|
includeFontPadding: false;
|
|
39
|
-
verticalAlign: "middle";
|
|
40
56
|
fontFamily: string;
|
|
41
|
-
|
|
42
|
-
inputFloatLabel: {
|
|
43
|
-
paddingTop: number;
|
|
44
|
-
paddingBottom: number;
|
|
57
|
+
verticalAlign: "middle";
|
|
45
58
|
};
|
|
46
59
|
placeholderTextColor: {
|
|
47
60
|
color: string;
|
|
@@ -67,6 +80,7 @@ export declare const useStyles: () => {
|
|
|
67
80
|
label: {
|
|
68
81
|
position: "absolute";
|
|
69
82
|
left: number;
|
|
83
|
+
right: number;
|
|
70
84
|
top: number;
|
|
71
85
|
paddingVertical: number;
|
|
72
86
|
paddingLeft: number;
|
|
@@ -83,4 +97,7 @@ export declare const useStyles: () => {
|
|
|
83
97
|
top: number;
|
|
84
98
|
fontFamily: string;
|
|
85
99
|
};
|
|
100
|
+
hidden: {
|
|
101
|
+
opacity: number;
|
|
102
|
+
};
|
|
86
103
|
};
|
|
@@ -7,7 +7,7 @@ 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
|
-
|
|
10
|
+
alignItems: 'center',
|
|
11
11
|
},
|
|
12
12
|
containerFocused: {
|
|
13
13
|
outlineColor: theme.General.focusOutlineColor,
|
|
@@ -17,6 +17,7 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
17
17
|
minHeight: theme.Button.Common.buttonHeightXL,
|
|
18
18
|
maxHeight: theme.Button.Common.buttonHeightXL,
|
|
19
19
|
height: theme.Button.Common.buttonHeightXL,
|
|
20
|
+
alignItems: 'stretch',
|
|
20
21
|
},
|
|
21
22
|
danger: { borderColor: theme.Form.InputText.inputErrorBorderColor },
|
|
22
23
|
dangerFocused: { outlineColor: theme.General.focusOutlineErrorColor },
|
|
@@ -25,18 +26,28 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
25
26
|
borderColor: theme.Form.InputText.inputBorderColor,
|
|
26
27
|
backgroundColor: theme.Button.Disabled.disabledButtonBg,
|
|
27
28
|
},
|
|
28
|
-
|
|
29
|
+
inputContainer: {
|
|
30
|
+
flex: 1,
|
|
31
|
+
marginHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
32
|
+
paddingLeft: 2, // отступ для курсора
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
},
|
|
35
|
+
input: { padding: 0, position: 'absolute', left: 0, right: 0 },
|
|
36
|
+
floatLabelInput: {
|
|
29
37
|
flex: 1,
|
|
30
38
|
paddingHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
31
|
-
|
|
39
|
+
paddingTop: 26,
|
|
40
|
+
paddingBottom: 12,
|
|
32
41
|
borderRadius: border.Radius['rounded-xl'],
|
|
33
|
-
color: theme.Form.InputText.inputTextColor,
|
|
34
42
|
overflow: 'hidden',
|
|
43
|
+
},
|
|
44
|
+
inputFont: {
|
|
45
|
+
fontSize: typography.Size['text-base'],
|
|
46
|
+
color: theme.Form.InputText.inputTextColor,
|
|
35
47
|
includeFontPadding: false,
|
|
36
|
-
verticalAlign: 'middle',
|
|
37
48
|
fontFamily: fonts.secondary,
|
|
49
|
+
verticalAlign: 'middle',
|
|
38
50
|
},
|
|
39
|
-
inputFloatLabel: { paddingTop: 26, paddingBottom: 12 },
|
|
40
51
|
placeholderTextColor: {
|
|
41
52
|
color: theme.Form.InputText.inputPlaceholderTextColor,
|
|
42
53
|
},
|
|
@@ -59,6 +70,7 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
59
70
|
label: {
|
|
60
71
|
position: 'absolute',
|
|
61
72
|
left: 7,
|
|
73
|
+
right: 7,
|
|
62
74
|
top: 19,
|
|
63
75
|
paddingVertical: 0,
|
|
64
76
|
paddingLeft: spacing.Padding['p-1'],
|
|
@@ -75,4 +87,5 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
75
87
|
top: 7,
|
|
76
88
|
fontFamily: fonts.primary,
|
|
77
89
|
},
|
|
90
|
+
hidden: { opacity: 0 },
|
|
78
91
|
}));
|
package/package.json
CHANGED