@cdek-it/react-native-ui-kit 0.2.6 → 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.
package/README.md CHANGED
@@ -4,9 +4,34 @@
4
4
 
5
5
  ## Installation
6
6
 
7
+ **Yarn**
8
+
9
+ ```shell
10
+ yarn add \
11
+ react \
12
+ react-native \
13
+ @tabler/icons-react-native \
14
+ react-native-svg \
15
+ react-native-reanimated
16
+ ```
17
+
18
+ ```shell
19
+ yarn add @cdek-it/react-native-ui-kit
20
+ ```
21
+
22
+ **npm**
23
+
7
24
  ```shell
8
- yarn add --save-exact @cdek-it/react-native-ui-kit
9
- yarn add react react-native @tabler/icons-react-native react-native-svg react-native-reanimated
25
+ npm i \
26
+ react \
27
+ react-native \
28
+ @tabler/icons-react-native \
29
+ react-native-svg \
30
+ react-native-reanimated
31
+ ```
32
+
33
+ ```shell
34
+ npm i @cdek-it/react-native-ui-kit
10
35
  ```
11
36
 
12
37
  ## Шрифты
@@ -137,15 +162,3 @@ UI kit использует следующие виды шрифтов.
137
162
  - @tabler/icons-react-native - начиная с 3 major версии(от 3.0.0)
138
163
  - react-native-svg - начиная с 15 major версии(от 15.0.0)
139
164
  - react-native-reanimated - начиная с 3 major версии(от 3.0.0)
140
-
141
- ## Development
142
-
143
- `yarn install` - установка зависимостей `yarn start` - запуск Metro Bundler для
144
- Storybook `yarn ios` - запуск Storybook на iOS `yarn android` - запуск Storybook
145
- на Android
146
-
147
- Storybook проект создан с помощью Expo
148
-
149
- ### Макеты
150
-
151
- [https://developer.cdek.ru/design-system](https://developer.cdek.ru/design-system)
@@ -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,
@@ -109,8 +123,6 @@ export const InputTextBase = memo(
109
123
 
110
124
  {input}
111
125
  </>) : (<View style={styles.inputContainer}>
112
- {input}
113
-
114
126
  <Text pointerEvents='none' style={[
115
127
  styles.inputFont,
116
128
  styles.placeholder,
@@ -122,22 +134,24 @@ export const InputTextBase = memo(
122
134
  ]} testID={makeTestId(InputTextBaseTestId.placeholder)}>
123
135
  {placeholder}
124
136
  </Text>
137
+
138
+ {input}
125
139
  </View>)}
126
140
 
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}
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
- {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}
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
- {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}
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
- {disabled ? (<IconLock color={styles.rightIcon.color} height={iconSize.height} testID={makeTestId(InputTextBaseTestId.disabledIcon)} width={iconSize.width}/>) : null}
141
- </View>
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
- 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.6",
3
+ "version": "0.2.8",
4
4
  "description": "UI kit на основе Prime Faces, Prime Flex для React Native",
5
5
  "license": "MIT",
6
6
  "homepage": "https://developer.cdek.ru/design-system",