@cdek-it/react-native-ui-kit 1.0.0-beta.8 → 1.0.0
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,14 +1,25 @@
|
|
|
1
|
-
import { memo, useCallback, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
1
|
+
import { memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
2
2
|
import { Pressable, View, TextInput, } from 'react-native';
|
|
3
3
|
import { StyleSheet } from 'react-native-unistyles';
|
|
4
4
|
import { InputOtpItem } from './InputOtpItem';
|
|
5
|
-
export const InputOtp = memo(({ length, onChange, disabled = false, error = false, testOnly_pressed, inputRef: propsInputRef, testID, value = '', onFocus, onBlur, ...rest }) => {
|
|
5
|
+
export const InputOtp = memo(({ length, onChange, disabled = false, error = false, testOnly_pressed, inputRef: propsInputRef, testID, value = '', onFocus, onBlur, editable, ...rest }) => {
|
|
6
6
|
const [isFocused, setIsFocused] = useState(false);
|
|
7
7
|
const inputRef = useRef(null);
|
|
8
|
+
const isInputEditable = !disabled && editable !== false;
|
|
8
9
|
useImperativeHandle(propsInputRef, () => inputRef.current);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!isInputEditable) {
|
|
12
|
+
setIsFocused(false);
|
|
13
|
+
if (inputRef.current?.isFocused()) {
|
|
14
|
+
inputRef.current.blur();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}, [isInputEditable]);
|
|
9
18
|
const handlePress = useCallback(() => {
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
if (isInputEditable) {
|
|
20
|
+
inputRef.current?.focus();
|
|
21
|
+
}
|
|
22
|
+
}, [isInputEditable]);
|
|
12
23
|
const handleChange = useCallback((text) => {
|
|
13
24
|
const sanitizedText = text.replace(/[^0-9]/g, '');
|
|
14
25
|
onChange(sanitizedText);
|
|
@@ -28,7 +39,7 @@ export const InputOtp = memo(({ length, onChange, disabled = false, error = fals
|
|
|
28
39
|
<View style={styles.content}>
|
|
29
40
|
{renderArray.map((key, index) => (<InputOtpItem disabled={disabled} error={error} focused={isFocused ? index === activeIndex : false} key={key} pressed={pressed} testID={`${testID}Item`} value={value[index]}/>))}
|
|
30
41
|
</View>
|
|
31
|
-
<TextInput keyboardType='number-pad' maxLength={length} ref={inputRef} style={styles.input} testID={`${testID}HiddenInput`} value={value} onBlur={handleBlur} onChangeText={handleChange} onFocus={handleFocus} {...rest}/>
|
|
42
|
+
<TextInput editable={isInputEditable} keyboardType='number-pad' maxLength={length} ref={inputRef} style={styles.input} testID={`${testID}HiddenInput`} value={value} onBlur={handleBlur} onChangeText={handleChange} onFocus={handleFocus} {...rest}/>
|
|
32
43
|
</>)}
|
|
33
44
|
</Pressable>);
|
|
34
45
|
});
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
import { memo
|
|
1
|
+
import { memo } from 'react';
|
|
2
2
|
import { View, Text } from 'react-native';
|
|
3
|
-
import Animated
|
|
3
|
+
import Animated from 'react-native-reanimated';
|
|
4
4
|
import { StyleSheet } from 'react-native-unistyles';
|
|
5
5
|
const CURSOR_ANIMATION_DURATION = 500;
|
|
6
|
+
const cursorAnimationStyle = {
|
|
7
|
+
animationName: { from: { opacity: 1 }, to: { opacity: 0.2 } },
|
|
8
|
+
animationDuration: CURSOR_ANIMATION_DURATION,
|
|
9
|
+
animationDirection: 'alternate',
|
|
10
|
+
animationIterationCount: 'infinite',
|
|
11
|
+
animationTimingFunction: 'ease',
|
|
12
|
+
};
|
|
6
13
|
export const InputOtpItem = memo(({ value, error, pressed, disabled, focused, testID }) => {
|
|
7
|
-
const opacity = useSharedValue(1);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (focused) {
|
|
10
|
-
opacity.value = withRepeat(withTiming(0.2, {
|
|
11
|
-
duration: CURSOR_ANIMATION_DURATION,
|
|
12
|
-
easing: Easing.ease,
|
|
13
|
-
}), -1, true);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
opacity.value = 1;
|
|
17
|
-
}
|
|
18
|
-
}, [focused, opacity]);
|
|
19
|
-
const cursorBlinking = useAnimatedStyle(() => ({ opacity: opacity.value }));
|
|
20
14
|
return (<View style={[
|
|
21
15
|
styles.container,
|
|
22
16
|
error && styles.error,
|
|
23
17
|
pressed && styles.pressed,
|
|
24
18
|
disabled && styles.disabled,
|
|
25
19
|
]}>
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
{focused ? (<View style={styles.textRow} testID={`${testID}CursorRow`}>
|
|
21
|
+
<Text style={styles.text} testID={testID}>
|
|
22
|
+
{value}
|
|
23
|
+
</Text>
|
|
24
|
+
<Animated.Text style={[styles.text, styles.cursor, cursorAnimationStyle]} testID={`${testID}Cursor`}>
|
|
29
25
|
|
|
|
30
|
-
</Animated.Text>
|
|
31
|
-
|
|
26
|
+
</Animated.Text>
|
|
27
|
+
</View>) : (<Text style={styles.text} testID={testID}>
|
|
28
|
+
{value}
|
|
29
|
+
</Text>)}
|
|
32
30
|
</View>);
|
|
33
31
|
});
|
|
34
32
|
const styles = StyleSheet.create(({ theme, border, fonts, typography }) => ({
|
|
@@ -42,14 +40,16 @@ const styles = StyleSheet.create(({ theme, border, fonts, typography }) => ({
|
|
|
42
40
|
alignItems: 'center',
|
|
43
41
|
justifyContent: 'center',
|
|
44
42
|
},
|
|
43
|
+
textRow: { flexDirection: 'row', alignItems: 'center' },
|
|
45
44
|
text: {
|
|
46
45
|
fontSize: typography.Size['text-2xl'],
|
|
47
46
|
fontFamily: fonts.primary,
|
|
48
47
|
fontWeight: '400',
|
|
49
48
|
color: theme.Form.InputText.inputTextColor,
|
|
49
|
+
includeFontPadding: false,
|
|
50
50
|
},
|
|
51
51
|
pressed: { borderColor: theme.Form.InputText.inputHoverBorderColor },
|
|
52
52
|
error: { borderColor: theme.Form.InputText.inputErrorBorderColor },
|
|
53
53
|
disabled: { mixBlendMode: 'luminosity', opacity: 0.6 },
|
|
54
|
-
cursor: { color: theme.Form.InputText.inputTextColor },
|
|
54
|
+
cursor: { color: theme.Form.InputText.inputTextColor, marginBottom: 3 },
|
|
55
55
|
}));
|
package/package.json
CHANGED