@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.
@@ -1,7 +1,5 @@
1
- import { type ViewStyle } from 'react-native';
2
1
  import type { InputTextBaseProps } from './types';
3
2
  interface PrivateInputTextBaseProps {
4
- inputStyle?: ViewStyle;
5
3
  loading?: boolean;
6
4
  }
7
5
  /**
@@ -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, inputStyle, loading, renderTextInput, clearButtonAccessibilityLabel, floatLabel = false, placeholder, ...otherProps }) => {
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
- placeholder: floatLabel ? '' : placeholder,
67
+ allowFontScaling: floatLabel ? false : otherProps.allowFontScaling,
68
+ placeholder: '',
69
69
  testID: makeTestId(),
70
70
  editable: !disabled,
71
71
  secureTextEntry,
72
- style: [styles.input, floatLabel && styles.inputFloatLabel, inputStyle],
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
- inputStyle,
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 ? (<Animated.Text style={[styles.label, labelAnimatedStyle]} testID={makeTestId(InputTextBaseTestId.floatingPlaceholder)}>
104
- {placeholder}
105
- </Animated.Text>) : null}
106
- {renderTextInput ? (renderTextInput(texInputProps)) : (<TextInput {...texInputProps} ref={inputRef}/>)}
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)}>
@@ -7,5 +7,6 @@ export declare const InputTextBaseTestId: {
7
7
  secureInputButton: string;
8
8
  disabledIcon: string;
9
9
  floatingPlaceholder: string;
10
+ placeholder: string;
10
11
  pressableContainer: string;
11
12
  };
@@ -7,5 +7,6 @@ export const InputTextBaseTestId = {
7
7
  secureInputButton: 'SecureInputButton',
8
8
  disabledIcon: 'DisabledIcon',
9
9
  floatingPlaceholder: 'FloatingPlaceholder',
10
+ placeholder: 'Placeholder',
10
11
  pressableContainer: 'PressableContainer',
11
12
  };
@@ -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
- paddingVertical: number;
35
- fontSize: number;
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
- inputFloatLabel: {
44
- paddingTop: number;
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
- paddingVertical: 0,
32
- fontSize: typography.Size['text-base'],
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdek-it/react-native-ui-kit",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "UI kit на основе Prime Faces, Prime Flex для React Native",
5
5
  "license": "MIT",
6
6
  "homepage": "https://developer.cdek.ru/design-system",