UNPKG

5.86 kBTypeScriptView Raw
1import * as React from 'react';
2import { StyleProp, TextInput as NativeTextInput, TextStyle, ViewStyle } from 'react-native';
3import { Props as TextInputAffixProps } from './Adornment/TextInputAffix';
4import { Props as TextInputIconProps } from './Adornment/TextInputIcon';
5import type { RenderProps, TextInputLabelProp } from './types';
6import type { ThemeProp } from '../../types';
7export type Props = React.ComponentPropsWithRef<typeof NativeTextInput> & {
8 /**
9 * Mode of the TextInput.
10 * - `flat` - flat input with an underline.
11 * - `outlined` - input with an outline.
12 *
13 * In `outlined` mode, the background color of the label is derived from `colors?.background` in theme or the `backgroundColor` style.
14 * This component render TextInputOutlined or TextInputFlat based on that props
15 */
16 mode?: 'flat' | 'outlined';
17 left?: React.ReactNode;
18 right?: React.ReactNode;
19 /**
20 * If true, user won't be able to interact with the component.
21 */
22 disabled?: boolean;
23 /**
24 * The text or component to use for the floating label.
25 */
26 label?: TextInputLabelProp;
27 /**
28 * Placeholder for the input.
29 */
30 placeholder?: string;
31 /**
32 * Whether to style the TextInput with error style.
33 */
34 error?: boolean;
35 /**
36 * Callback that is called when the text input's text changes. Changed text is passed as an argument to the callback handler.
37 */
38 onChangeText?: Function;
39 /**
40 * Selection color of the input. On iOS, it sets both the selection color and cursor color.
41 * On Android, it sets only the selection color.
42 */
43 selectionColor?: string;
44 /**
45 * @platform Android only
46 * Cursor (or "caret") color of the input on Android.
47 * This property has no effect on iOS.
48 */
49 cursorColor?: string;
50 /**
51 * Inactive underline color of the input.
52 */
53 underlineColor?: string;
54 /**
55 * Active underline color of the input.
56 */
57 activeUnderlineColor?: string;
58 /**
59 * Inactive outline color of the input.
60 */
61 outlineColor?: string;
62 /**
63 * Active outline color of the input.
64 */
65 activeOutlineColor?: string;
66 /**
67 * Color of the text in the input.
68 */
69 textColor?: string;
70 /**
71 * Sets min height with densed layout. For `TextInput` in `flat` mode
72 * height is `64dp` or in dense layout - `52dp` with label or `40dp` without label.
73 * For `TextInput` in `outlined` mode
74 * height is `56dp` or in dense layout - `40dp` regardless of label.
75 * When you apply `height` prop in style the `dense` prop affects only `paddingVertical` inside `TextInput`
76 */
77 dense?: boolean;
78 /**
79 * Whether the input can have multiple lines.
80 */
81 multiline?: boolean;
82 /**
83 * @platform Android only
84 * The number of lines to show in the input (Android only).
85 */
86 numberOfLines?: number;
87 /**
88 * Callback that is called when the text input is focused.
89 */
90 onFocus?: (args: any) => void;
91 /**
92 * Callback that is called when the text input is blurred.
93 */
94 onBlur?: (args: any) => void;
95 /**
96 *
97 * Callback to render a custom input component such as `react-native-text-input-mask`
98 * instead of the default `TextInput` component from `react-native`.
99 *
100 * Example:
101 * ```js
102 * <TextInput
103 * label="Phone number"
104 * render={props =>
105 * <TextInputMask
106 * {...props}
107 * mask="+[00] [000] [000] [000]"
108 * />
109 * }
110 * />
111 * ```
112 */
113 render?: (props: RenderProps) => React.ReactNode;
114 /**
115 * Value of the text input.
116 */
117 value?: string;
118 /**
119 * Pass `fontSize` prop to modify the font size inside `TextInput`.
120 * Pass `height` prop to set `TextInput` height. When `height` is passed,
121 * `dense` prop will affect only input's `paddingVertical`.
122 * Pass `paddingHorizontal` to modify horizontal padding.
123 * This can be used to get MD Guidelines v1 TextInput look.
124 */
125 style?: StyleProp<TextStyle>;
126 /**
127 * @optional
128 */
129 theme?: ThemeProp;
130 /**
131 * testID to be used on tests.
132 */
133 testID?: string;
134 /**
135 * Pass custom style directly to the input itself.
136 * Overrides input style
137 * Example: `paddingLeft`, `backgroundColor`
138 */
139 contentStyle?: StyleProp<TextStyle>;
140 /**
141 * Pass style to override the default style of outlined wrapper.
142 * Overrides style when mode is set to `outlined`
143 * Example: `borderRadius`, `borderColor`
144 */
145 outlineStyle?: StyleProp<ViewStyle>;
146 /**
147 * Pass style to override the default style of underlined wrapper.
148 * Overrides style when mode is set to `flat`
149 * Example: `borderRadius`, `borderColor`
150 */
151 underlineStyle?: StyleProp<ViewStyle>;
152};
153interface CompoundedComponent extends React.ForwardRefExoticComponent<Props & React.RefAttributes<TextInputHandles>> {
154 Icon: React.FunctionComponent<TextInputIconProps>;
155 Affix: React.FunctionComponent<Partial<TextInputAffixProps>>;
156}
157type TextInputHandles = Pick<NativeTextInput, 'focus' | 'clear' | 'blur' | 'isFocused' | 'setNativeProps'>;
158/**
159 * A component to allow users to input text.
160 *
161 * ## Usage
162 * ```js
163 * import * as React from 'react';
164 * import { TextInput } from 'react-native-paper';
165 *
166 * const MyComponent = () => {
167 * const [text, setText] = React.useState("");
168 *
169 * return (
170 * <TextInput
171 * label="Email"
172 * value={text}
173 * onChangeText={text => setText(text)}
174 * />
175 * );
176 * };
177 *
178 * export default MyComponent;
179 * ```
180 *
181 * @extends TextInput props https://reactnative.dev/docs/textinput#props
182 */
183declare const TextInput: CompoundedComponent;
184export default TextInput;
185//# sourceMappingURL=TextInput.d.ts.map
\No newline at end of file