Skip to content

Commit 9ab1a99

Browse files
chore(text fields): used shared props interface
1 parent 3488a48 commit 9ab1a99

File tree

4 files changed

+37
-75
lines changed

4 files changed

+37
-75
lines changed

src/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export {SuggestionChip, type SuggestionChipProps} from './chips/suggestion-chip/
1616
export {PrimaryTabs, type PrimaryTabsProps} from './navigation/tabs/primary-tabs/PrimaryTabs.component';
1717
export {SecondaryTabs, type SecondaryTabsProps} from './navigation/tabs/secondary-tabs/SecondaryTabs.component';
1818

19-
export {FilledTextInput, type FilledTextInputProps} from './text-inputs/filled-text-input/FilledTextInput.component';
20-
export {OutlinedTextInput, type OutlinedTextInputProps} from './text-inputs/outlined-text-input/OutlinedTextInput.component';
19+
export {type TextInputProps} from './text-inputs/text-input.type';
20+
export {FilledTextInput} from './text-inputs/filled-text-input/FilledTextInput.component';
21+
export {OutlinedTextInput} from './text-inputs/outlined-text-input/OutlinedTextInput.component';
2122

2223
export {
2324
CenterAlignedTopAppBar,

src/text-inputs/filled-text-input/FilledTextInput.component.tsx

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
1-
import React, {forwardRef, useRef, type ReactNode} from 'react';
1+
import React, {forwardRef, useRef} from 'react';
2+
import {Text, View, TextInput, TouchableWithoutFeedback} from 'react-native';
23
import Animated, {useAnimatedStyle, interpolateColor, interpolate} from 'react-native-reanimated';
3-
import {
4-
Text,
5-
View,
6-
TextInput,
7-
TouchableWithoutFeedback,
8-
type StyleProp,
9-
type ViewStyle,
10-
type TextStyle,
11-
type TextInputProps,
12-
type LayoutChangeEvent,
13-
} from 'react-native';
144

155
import {ErrorIcon} from '../../icons';
166
import {styles} from './filled-text-input.styles';
177
import {type IconProps} from '../../icons/icon-props';
8+
import type {TextInputProps} from '../text-input.type';
189
import {useTextInputColors} from '../use-text-input-colors.hook';
1910
import {useTextInputFocus} from '../use-text-input-focus-anim.hook';
2011
import {useTypography} from '../../typography/useTypography.component';
2112

22-
export interface FilledTextInputProps<T> extends TextInputProps {
23-
label: string;
24-
25-
disabled?: boolean;
26-
errorText?: string;
27-
suportingText?: string;
28-
29-
leadingIconProps?: T;
30-
trailingIconProps?: T;
31-
trailingIcon?: React.FC<T>;
32-
leadingIcon?: React.FC<T>;
33-
34-
leadingComponent?: ReactNode;
35-
trailingComponent?: ReactNode;
36-
37-
labelStyle?: StyleProp<ViewStyle>;
38-
supportingTextStyle?: StyleProp<TextStyle>;
39-
innerContainerStyle?: StyleProp<ViewStyle>;
40-
outerContainerStyle?: StyleProp<ViewStyle>;
41-
activeIndicatorStyle?: StyleProp<ViewStyle>;
42-
43-
onOuterContainerLayout?: (e: LayoutChangeEvent) => void;
44-
}
45-
4613
const UNFOCUSED_LABEL_TOP_PLACEMENT = 8;
4714
const DEFAULT_LABEL_SMALL_FONT_SIZE = 12;
4815
const DEFAULT_LABEL_LARGE_FONT_SIZE = 16;
@@ -78,7 +45,7 @@ export const FilledTextInput = forwardRef(
7845
onBlur,
7946
onOuterContainerLayout,
8047
...props
81-
}: FilledTextInputProps<T>,
48+
}: TextInputProps<T>,
8249
ref: React.Ref<TextInput>
8350
) => {
8451
const {bodyLarge, bodySmall} = useTypography();

src/text-inputs/outlined-text-input/OutlinedTextInput.component.tsx

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,16 @@
1-
import React, {forwardRef, useCallback, useRef, useState, type ReactNode} from 'react';
1+
import React, {forwardRef, useCallback, useRef, useState} from 'react';
22
import Animated, {useAnimatedStyle, interpolateColor, interpolate} from 'react-native-reanimated';
3-
import {
4-
Text,
5-
View,
6-
TextInput,
7-
TouchableWithoutFeedback,
8-
type StyleProp,
9-
type ViewStyle,
10-
type TextStyle,
11-
type TextInputProps,
12-
type LayoutChangeEvent,
13-
} from 'react-native';
3+
import {Text, View, TextInput, TouchableWithoutFeedback, type LayoutChangeEvent} from 'react-native';
144

155
import {ErrorIcon} from '../../icons';
166
import {useTheme} from '../../theme/useTheme.hook';
177
import {type IconProps} from '../../icons/icon-props';
8+
import {type TextInputProps} from '../text-input.type';
189
import {useTextInputColors} from '../use-text-input-colors.hook';
1910
import {useTextInputFocus} from '../use-text-input-focus-anim.hook';
2011
import {useTypography} from '../../typography/useTypography.component';
2112
import {OUTLINED_TEXT_INPUT_CONTAINER_PADDING_VERTICAL, OUTLINED_TEXT_INPUT_CONTAINER_PADDING_HORIZONTAL, styles} from './outlined-text-input.styles';
2213

23-
export interface OutlinedTextInputProps<T> extends TextInputProps {
24-
label: string;
25-
26-
disabled?: boolean;
27-
errorText?: string;
28-
suportingText?: string;
29-
30-
leadingIconProps?: T;
31-
trailingIconProps?: T;
32-
trailingIcon?: React.FC<T>;
33-
leadingIcon?: React.FC<T>;
34-
35-
leadingComponent?: ReactNode;
36-
trailingComponent?: ReactNode;
37-
38-
labelStyle?: StyleProp<ViewStyle>;
39-
supportingTextStyle?: StyleProp<TextStyle>;
40-
innerContainerStyle?: StyleProp<ViewStyle>;
41-
outerContainerStyle?: StyleProp<ViewStyle>;
42-
43-
onOuterContainerLayout?: (e: LayoutChangeEvent) => void;
44-
}
45-
4614
const BORDER_FOCUSED_WIDTH = 3;
4715
const BORDER_UNFOCUSED_WIDTH = 1;
4816
const UNFOCUSED_LABEL_TOP_PLACEMENT = 8;
@@ -79,7 +47,7 @@ export const OutlinedTextInput = forwardRef(
7947
onBlur,
8048
onOuterContainerLayout,
8149
...props
82-
}: OutlinedTextInputProps<T>,
50+
}: Omit<TextInputProps<T>, 'activeIndicatorStyle'>,
8351
ref: React.Ref<TextInput>
8452
) => {
8553
const [labelWidth, setLabeWidth] = useState(0);

src/text-inputs/text-input.type.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {type ReactNode} from 'react';
2+
import {type TextInputProps as RNTextInputProps, type StyleProp, type ViewStyle, type TextStyle, type LayoutChangeEvent} from 'react-native';
3+
4+
export interface TextInputProps<T> extends RNTextInputProps {
5+
label: string;
6+
7+
disabled?: boolean;
8+
errorText?: string;
9+
suportingText?: string;
10+
11+
leadingIconProps?: T;
12+
trailingIconProps?: T;
13+
trailingIcon?: React.FC<T>;
14+
leadingIcon?: React.FC<T>;
15+
16+
leadingComponent?: ReactNode;
17+
trailingComponent?: ReactNode;
18+
19+
labelStyle?: StyleProp<ViewStyle>;
20+
supportingTextStyle?: StyleProp<TextStyle>;
21+
innerContainerStyle?: StyleProp<ViewStyle>;
22+
outerContainerStyle?: StyleProp<ViewStyle>;
23+
activeIndicatorStyle?: StyleProp<ViewStyle>;
24+
25+
onOuterContainerLayout?: (e: LayoutChangeEvent) => void;
26+
}

0 commit comments

Comments
 (0)