@cdek-it/react-native-ui-kit 0.4.0 → 0.4.2
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/InputOtp/InputOtp.d.ts +5 -3
- package/dist/components/Input/InputOtp/InputOtp.js +11 -13
- package/dist/components/Input/InputTextBase/InputTextBase.js +3 -2
- package/dist/components/Input/InputTextBase/types.d.ts +1 -1
- package/dist/components/Input/InputTextBase/useStyles.d.ts +1 -0
- package/dist/components/Input/InputTextBase/useStyles.js +1 -0
- package/dist/components/Input/index.d.ts +1 -0
- package/dist/components/Input/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
1
|
+
import { type Ref } from 'react';
|
|
2
|
+
import { TextInput, type TextInputProps, type PressableProps } from 'react-native';
|
|
3
|
+
export interface InputOtpProps extends Omit<TextInputProps, 'onChangeText' | 'onChange' | 'ref' | 'keyboardType' | 'style'>, Pick<PressableProps, 'testOnly_pressed'> {
|
|
3
4
|
length: number;
|
|
4
|
-
|
|
5
|
+
onChange: (value: string) => void;
|
|
5
6
|
disabled?: boolean;
|
|
6
7
|
error?: boolean;
|
|
8
|
+
inputRef?: Ref<TextInput | null>;
|
|
7
9
|
}
|
|
8
10
|
export declare const InputOtp: import("react").NamedExoticComponent<InputOtpProps>;
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
1
|
+
import { memo, useCallback, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
2
2
|
import { Pressable, View, TextInput, } from 'react-native';
|
|
3
3
|
import { makeStyles } from '../../../utils/makeStyles';
|
|
4
4
|
import { InputOtpItem } from './InputOtpItem';
|
|
5
|
-
export const InputOtp = memo(({ length,
|
|
5
|
+
export const InputOtp = memo(({ length, onChange, disabled = false, error = false, testOnly_pressed, inputRef: propsInputRef, testID, value = '', onFocus, onBlur, ...rest }) => {
|
|
6
6
|
const styles = useStyles();
|
|
7
|
-
const [value, setValue] = useState('');
|
|
8
7
|
const [isFocused, setIsFocused] = useState(false);
|
|
9
8
|
const inputRef = useRef(null);
|
|
9
|
+
useImperativeHandle(propsInputRef, () => inputRef.current);
|
|
10
10
|
const handlePress = useCallback(() => {
|
|
11
11
|
inputRef.current?.focus();
|
|
12
12
|
}, []);
|
|
13
13
|
const handleChange = useCallback((text) => {
|
|
14
14
|
const sanitizedText = text.replace(/[^0-9]/g, '');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
inputRef.current?.blur();
|
|
19
|
-
}
|
|
20
|
-
}, [length, onComplete]);
|
|
21
|
-
const handleFocus = useCallback(() => {
|
|
15
|
+
onChange(sanitizedText);
|
|
16
|
+
}, [onChange]);
|
|
17
|
+
const handleFocus = useCallback((e) => {
|
|
22
18
|
setIsFocused(true);
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
onFocus?.(e);
|
|
20
|
+
}, [onFocus]);
|
|
21
|
+
const handleBlur = useCallback((e) => {
|
|
25
22
|
setIsFocused(false);
|
|
26
|
-
|
|
23
|
+
onBlur?.(e);
|
|
24
|
+
}, [onBlur]);
|
|
27
25
|
const activeIndex = useMemo(() => Math.min(value.length, length - 1), [value.length, length]);
|
|
28
26
|
const renderArray = useMemo(() => Array.from({ length }).fill(null), [length]);
|
|
29
27
|
return (<Pressable disabled={disabled} style={styles.container} testID={testID} testOnly_pressed={testOnly_pressed} onPress={handlePress}>
|
|
@@ -14,7 +14,7 @@ import { useStyles } from './useStyles';
|
|
|
14
14
|
*/
|
|
15
15
|
export const InputTextBase = memo(
|
|
16
16
|
// eslint-disable-next-line max-lines-per-function
|
|
17
|
-
({ 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, editable = true, ...otherProps
|
|
18
18
|
// TODO: разделить float label и обычный инпут -> добавить во float label поддержку font scale
|
|
19
19
|
// eslint-disable-next-line complexity
|
|
20
20
|
}) => {
|
|
@@ -80,7 +80,7 @@ export const InputTextBase = memo(
|
|
|
80
80
|
allowFontScaling: floatLabel ? false : otherProps.allowFontScaling,
|
|
81
81
|
placeholder: '',
|
|
82
82
|
testID: makeTestId(),
|
|
83
|
-
editable:
|
|
83
|
+
editable: disabled ? false : editable,
|
|
84
84
|
secureTextEntry,
|
|
85
85
|
style: [
|
|
86
86
|
styles.inputFont,
|
|
@@ -97,6 +97,7 @@ export const InputTextBase = memo(
|
|
|
97
97
|
floatLabel,
|
|
98
98
|
makeTestId,
|
|
99
99
|
disabled,
|
|
100
|
+
editable,
|
|
100
101
|
secureTextEntry,
|
|
101
102
|
styles.inputFont,
|
|
102
103
|
styles.floatLabelInput,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Ref, ReactNode } from 'react';
|
|
2
2
|
import type { TextInputProps, ViewStyle, TextInput } from 'react-native';
|
|
3
3
|
/** @see TextInputProps */
|
|
4
|
-
export interface InputTextBaseProps extends Omit<TextInputProps, 'style' | '
|
|
4
|
+
export interface InputTextBaseProps extends Omit<TextInputProps, 'style' | 'secureTextEntry'> {
|
|
5
5
|
/**
|
|
6
6
|
* Управление отображения иконки очистки поля
|
|
7
7
|
* @default true
|
|
@@ -65,6 +65,7 @@ export const useStyles = makeStyles(({ theme, border, typography, spacing, fonts
|
|
|
65
65
|
paddingHorizontal: theme.Form.InputText.inputPaddingLeftRight,
|
|
66
66
|
gap: theme.Form.InputText.inputPaddingLeftRight,
|
|
67
67
|
overflow: 'hidden',
|
|
68
|
+
alignItems: 'center',
|
|
68
69
|
},
|
|
69
70
|
rightButtonContainer: { justifyContent: 'center' },
|
|
70
71
|
rightIcon: { color: theme.Form.InputText.inputIconColor },
|
package/package.json
CHANGED