@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.
@@ -1,8 +1,10 @@
1
- import { type TextInputProps, type PressableProps } from 'react-native';
2
- export interface InputOtpProps extends Omit<TextInputProps, 'value' | 'onChangeText' | 'onFocus' | 'onBlur' | 'ref' | 'keyboardType' | 'style'>, Pick<PressableProps, 'testOnly_pressed'> {
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
- onComplete?: (value: string) => void;
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, onComplete, disabled = false, error = false, testOnly_pressed, testID, ...rest }) => {
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
- setValue(sanitizedText);
16
- if (sanitizedText.length === length) {
17
- onComplete?.(sanitizedText);
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
- const handleBlur = useCallback(() => {
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: !disabled,
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' | 'editable' | 'secureTextEntry'> {
4
+ export interface InputTextBaseProps extends Omit<TextInputProps, 'style' | 'secureTextEntry'> {
5
5
  /**
6
6
  * Управление отображения иконки очистки поля
7
7
  * @default true
@@ -70,6 +70,7 @@ export declare const useStyles: () => {
70
70
  paddingHorizontal: number;
71
71
  gap: number;
72
72
  overflow: "hidden";
73
+ alignItems: "center";
73
74
  };
74
75
  rightButtonContainer: {
75
76
  justifyContent: "center";
@@ -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 },
@@ -3,3 +3,4 @@ export { InputText } from './InputText';
3
3
  export { FloatLabel } from './FloatLabel';
4
4
  export { InputSwitch } from './InputSwitch';
5
5
  export type { InputTextBaseProps } from './InputTextBase/types';
6
+ export { InputOtp } from './InputOtp/InputOtp';
@@ -2,3 +2,4 @@ export { InputGroup } from './InputGroup';
2
2
  export { InputText } from './InputText';
3
3
  export { FloatLabel } from './FloatLabel';
4
4
  export { InputSwitch } from './InputSwitch';
5
+ export { InputOtp } from './InputOtp/InputOtp';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdek-it/react-native-ui-kit",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "UI kit на основе Prime Faces, Prime Flex для React Native",
5
5
  "license": "MIT",
6
6
  "homepage": "https://developer.cdek.ru/design-system",