Skip to content

Commit 94cbbcd

Browse files
authored
Support custom passing children as custom input in Incubator.TextField (#1518)
1 parent e30ee05 commit 94cbbcd

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

generatedTypes/src/incubator/TextField/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 3. Passing typography preset that includes lineHeight usually cause alignment issues with
66
* other elements (leading/trailing accessories). It usually best to set lineHeight with undefined
77
*/
8-
import React, { ReactElement } from 'react';
8+
import React, { PropsWithChildren, ReactElement } from 'react';
99
import { ViewStyle, TextStyle } from 'react-native';
1010
import { ForwardRefInjectedProps, BaseComponentInjectedProps, MarginModifiers, PaddingModifiers, TypographyModifiers, ColorsModifiers } from '../../commons/new';
1111
import { ValidationMessagePosition, Validator } from './types';
@@ -70,7 +70,7 @@ export declare type TextFieldProps = MarginModifiers & PaddingModifiers & Typogr
7070
*/
7171
preset?: 'default' | null;
7272
};
73-
export declare type InternalTextFieldProps = TextFieldProps & BaseComponentInjectedProps & ForwardRefInjectedProps;
73+
export declare type InternalTextFieldProps = PropsWithChildren<TextFieldProps & BaseComponentInjectedProps & ForwardRefInjectedProps>;
7474
interface StaticMembers {
7575
validationMessagePositions: typeof ValidationMessagePosition;
7676
}

generatedTypes/src/incubator/TextField/usePreset.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default function usePreset({ preset, ...props }: InternalTextFieldProps):
162162
containerStyle?: import("react-native").ViewStyle | undefined;
163163
modifiers: import("../../commons/modifiers").ExtractedStyle;
164164
forwardedRef: any;
165+
children?: import("react").ReactNode;
165166
} | {
166167
margin?: boolean | undefined;
167168
marginL?: boolean | undefined;
@@ -494,6 +495,7 @@ export default function usePreset({ preset, ...props }: InternalTextFieldProps):
494495
containerStyle?: import("react-native").ViewStyle | undefined;
495496
modifiers: import("../../commons/modifiers").ExtractedStyle;
496497
forwardedRef: any;
498+
children?: import("react").ReactNode;
497499
} | {
498500
margin?: boolean | undefined;
499501
marginL?: boolean | undefined;
@@ -1062,4 +1064,5 @@ export default function usePreset({ preset, ...props }: InternalTextFieldProps):
10621064
containerStyle?: import("react-native").ViewStyle | undefined;
10631065
modifiers: import("../../commons/modifiers").ExtractedStyle;
10641066
forwardedRef: any;
1067+
children?: import("react").ReactNode;
10651068
};

src/incubator/TextField/index.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 3. Passing typography preset that includes lineHeight usually cause alignment issues with
66
* other elements (leading/trailing accessories). It usually best to set lineHeight with undefined
77
*/
8-
import React, {ReactElement, useMemo} from 'react';
8+
import React, {PropsWithChildren, ReactElement, useMemo} from 'react';
99
import {ViewStyle, TextStyle} from 'react-native';
1010
import {omit, isFunction} from 'lodash';
1111
import {
@@ -95,10 +95,12 @@ export type TextFieldProps = MarginModifiers &
9595
preset?: 'default' | null;
9696
};
9797

98-
export type InternalTextFieldProps = TextFieldProps &
99-
// Omit<FieldStateInjectedProps, keyof InputProps> &
100-
BaseComponentInjectedProps &
101-
ForwardRefInjectedProps;
98+
export type InternalTextFieldProps = PropsWithChildren<
99+
TextFieldProps &
100+
// Omit<FieldStateInjectedProps, keyof InputProps> &
101+
BaseComponentInjectedProps &
102+
ForwardRefInjectedProps
103+
>;
102104

103105
interface StaticMembers {
104106
validationMessagePositions: typeof ValidationMessagePosition;
@@ -140,6 +142,7 @@ const TextField = (props: InternalTextFieldProps) => {
140142
charCounterStyle,
141143
// Input
142144
placeholder,
145+
children,
143146
...others
144147
} = usePreset(props);
145148
const {onFocus, onBlur, onChangeText, fieldState, validateField} = useFieldState(others);
@@ -186,16 +189,18 @@ const TextField = (props: InternalTextFieldProps) => {
186189
validationMessagePosition={validationMessagePosition}
187190
/>
188191
)}
189-
<Input
190-
placeholderTextColor={floatingPlaceholder ? 'transparent' : undefined}
191-
{...others}
192-
style={[typographyStyle, colorStyle, others.style]}
193-
onFocus={onFocus}
194-
onBlur={onBlur}
195-
onChangeText={onChangeText}
196-
placeholder={placeholder}
197-
hint={hint}
198-
/>
192+
{children || (
193+
<Input
194+
placeholderTextColor={floatingPlaceholder ? 'transparent' : undefined}
195+
{...others}
196+
style={[typographyStyle, colorStyle, others.style]}
197+
onFocus={onFocus}
198+
onBlur={onBlur}
199+
onChangeText={onChangeText}
200+
placeholder={placeholder}
201+
hint={hint}
202+
/>
203+
)}
199204
</View>
200205
{trailingAccessory}
201206
</View>

0 commit comments

Comments
 (0)