@cdek-it/react-native-ui-kit 0.2.7 → 0.2.9

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,23 @@ 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
62
+ ? Object.assign(inputRef.current, { clear })
63
+ : null), [inputRef, clear]);
59
64
  const { makeTestId } = useMakeTestId(otherProps.testID || InputTextBaseTestId.default);
60
65
  const [userDefinedSecureTextEntry, setUserDefinedSecureTextEntry] = useState(true);
61
66
  const secureTextEntry = useMemo(() => secureTextEntryProp === 'toggleable'
62
67
  ? userDefinedSecureTextEntry
63
68
  : secureTextEntryProp, [secureTextEntryProp, userDefinedSecureTextEntry]);
64
69
  const toggleUserDefinedSecureTextEntry = useCallback(() => setUserDefinedSecureTextEntry((old) => !old), []);
70
+ const showSecureToggle = secureTextEntryProp === 'toggleable';
71
+ const hasRightContent = loading || showClearButton || showSecureToggle || disabled;
72
+ const rightButtonHitSlop = useMemo(() => ({
73
+ top: 0,
74
+ bottom: 0,
75
+ left: styles.rightContainer.gap / 2,
76
+ right: styles.rightContainer.gap / 2,
77
+ }), [styles.rightContainer.gap]);
65
78
  const texInputProps = useMemo(() => ({
66
79
  ...otherProps,
67
80
  allowFontScaling: floatLabel ? false : otherProps.allowFontScaling,
@@ -72,6 +85,7 @@ export const InputTextBase = memo(
72
85
  style: [
73
86
  styles.inputFont,
74
87
  floatLabel ? styles.floatLabelInput : styles.input,
88
+ hasRightContent && styles.inputWithRightContent,
75
89
  ],
76
90
  inputRef,
77
91
  value,
@@ -84,9 +98,11 @@ export const InputTextBase = memo(
84
98
  makeTestId,
85
99
  disabled,
86
100
  secureTextEntry,
87
- styles.floatLabelInput,
88
101
  styles.inputFont,
102
+ styles.floatLabelInput,
89
103
  styles.input,
104
+ styles.inputWithRightContent,
105
+ hasRightContent,
90
106
  value,
91
107
  onBlur,
92
108
  onChangeText,
@@ -124,20 +140,20 @@ export const InputTextBase = memo(
124
140
  {input}
125
141
  </View>)}
126
142
 
127
- <View style={styles.rightContainer}>
128
- {loading ? (<Animated.View style={loadingAnimatedStyle} testID={makeTestId(InputTextBaseTestId.loading)}>
129
- <IconLoader2 color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>
130
- </Animated.View>) : null}
143
+ {hasRightContent ? (<View style={styles.rightContainer}>
144
+ {loading ? (<Animated.View style={[styles.rightButtonContainer, loadingAnimatedStyle]} testID={makeTestId(InputTextBaseTestId.loading)}>
145
+ <IconLoader2 color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>
146
+ </Animated.View>) : null}
131
147
 
132
- {showClearButton && !disabled ? (<TouchableOpacity accessibilityLabel={clearButtonAccessibilityLabel} testID={makeTestId(InputTextBaseTestId.clearButton)} onPress={clear}>
133
- <IconX color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>
134
- </TouchableOpacity>) : null}
148
+ {showClearButton ? (<TouchableOpacity accessibilityLabel={clearButtonAccessibilityLabel} hitSlop={rightButtonHitSlop} style={styles.rightButtonContainer} testID={makeTestId(InputTextBaseTestId.clearButton)} onPress={clear}>
149
+ <IconX color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>
150
+ </TouchableOpacity>) : null}
135
151
 
136
- {secureTextEntryProp === 'toggleable' ? (<TouchableOpacity testID={makeTestId(InputTextBaseTestId.secureInputButton)} onPress={toggleUserDefinedSecureTextEntry}>
137
- {userDefinedSecureTextEntry ? (<IconEye color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>) : (<IconEyeOff color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>)}
138
- </TouchableOpacity>) : null}
152
+ {showSecureToggle ? (<TouchableOpacity hitSlop={rightButtonHitSlop} style={styles.rightButtonContainer} testID={makeTestId(InputTextBaseTestId.secureInputButton)} onPress={toggleUserDefinedSecureTextEntry}>
153
+ {userDefinedSecureTextEntry ? (<IconEye color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>) : (<IconEyeOff color={styles.rightIcon.color} height={iconSize.height} width={iconSize.width}/>)}
154
+ </TouchableOpacity>) : null}
139
155
 
140
- {disabled ? (<IconLock color={styles.rightIcon.color} height={iconSize.height} testID={makeTestId(InputTextBaseTestId.disabledIcon)} width={iconSize.width}/>) : null}
141
- </View>
156
+ {disabled ? (<IconLock color={styles.rightIcon.color} height={iconSize.height} testID={makeTestId(InputTextBaseTestId.disabledIcon)} width={iconSize.width}/>) : null}
157
+ </View>) : null}
142
158
  </Pressable>);
143
159
  });
@@ -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
- alignItems: "center";
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
- alignItems: 'center',
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdek-it/react-native-ui-kit",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "UI kit на основе Prime Faces, Prime Flex для React Native",
5
5
  "license": "MIT",
6
6
  "homepage": "https://developer.cdek.ru/design-system",