Skip to content

Commit d6f9670

Browse files
authored
Incubator.TextField fixes (#1288)
* Fix issue with FloatingPlaceholderColor ignore default preset * Support passing color object preset to placeholderTextColor * Support floatOnFocus prop * Fix issue with floatingPlaceholder overlappying top validation message * Support passing a function based on field context to fieldStyle
1 parent ded9aa1 commit d6f9670

File tree

15 files changed

+214
-160
lines changed

15 files changed

+214
-160
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/// <reference types="react" />
2-
export declare type ContextType = {
2+
export declare type FieldContextType = {
33
value?: string;
44
isFocused: boolean;
55
hasValue: boolean;
66
isValid: boolean;
77
failingValidatorIndex?: number;
88
disabled: boolean;
99
};
10-
declare const FieldContext: import("react").Context<ContextType>;
10+
declare const FieldContext: import("react").Context<FieldContextType>;
1111
export default FieldContext;

generatedTypes/incubator/TextField/FloatingPlaceholder.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="react" />
22
import { TextStyle, StyleProp } from 'react-native';
3-
import { ColorType } from './types';
3+
import { ColorType, ValidationMessagePosition } from './types';
44
export interface FloatingPlaceholderProps {
55
/**
66
* The placeholder for the field
@@ -14,9 +14,14 @@ export interface FloatingPlaceholderProps {
1414
* Custom style to pass to the floating placeholder
1515
*/
1616
floatingPlaceholderStyle?: StyleProp<TextStyle>;
17+
/**
18+
* Should placeholder float on focus or when start typing
19+
*/
20+
floatOnFocus?: boolean;
21+
validationMessagePosition?: ValidationMessagePosition;
1722
}
1823
declare const FloatingPlaceholder: {
19-
({ placeholder, floatingPlaceholderColor, floatingPlaceholderStyle }: FloatingPlaceholderProps): JSX.Element;
24+
({ placeholder, floatingPlaceholderColor, floatingPlaceholderStyle, floatOnFocus, validationMessagePosition }: FloatingPlaceholderProps): JSX.Element;
2025
displayName: string;
2126
};
2227
export default FloatingPlaceholder;

generatedTypes/incubator/TextField/Input.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { TextInput, TextInputProps } from 'react-native';
33
import { ForwardRefInjectedProps } from '../../commons/new';
44
import { ColorType } from './types';
5-
export interface InputProps extends TextInputProps, React.ComponentPropsWithRef<typeof TextInput> {
5+
export interface InputProps extends Omit<TextInputProps, 'placeholderTextColor'>, Omit<React.ComponentPropsWithRef<typeof TextInput>, 'placeholderTextColor'> {
66
/**
77
* A hint text to display when focusing the field
88
*/
@@ -11,6 +11,10 @@ export interface InputProps extends TextInputProps, React.ComponentPropsWithRef<
1111
* Input color
1212
*/
1313
color?: ColorType;
14+
/**
15+
* placeholder text color
16+
*/
17+
placeholderTextColor?: ColorType;
1418
}
1519
declare const Input: {
1620
({ style, hint, color, forwardedRef, ...props }: InputProps & ForwardRefInjectedProps): JSX.Element;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ContextType } from './FieldContext';
1+
import { FieldContextType } from './FieldContext';
22
import { ColorType, Validator } from './types';
3-
export declare function getColorByState(color: ColorType, context?: ContextType): string;
3+
export declare function getColorByState(color?: ColorType, context?: FieldContextType): string | undefined;
44
export declare function validate(value?: string, validator?: Validator | Validator[]): [boolean, number?];
55
export declare function getRelevantValidationMessage(validationMessage: string | string[] | undefined, failingValidatorIndex: undefined | number): string | undefined;

generatedTypes/incubator/TextField/index.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import { ValidationMessagePosition, Validator } from './types';
1212
import { InputProps } from './Input';
1313
import { ValidationMessageProps } from './ValidationMessage';
1414
import { LabelProps } from './Label';
15+
import { FieldContextType as _FieldContextType } from './FieldContext';
1516
import { FloatingPlaceholderProps } from './FloatingPlaceholder';
1617
import { CharCounterProps } from './CharCounter';
18+
export declare type FieldContextType = _FieldContextType;
1719
export declare type TextFieldProps = MarginModifiers & PaddingModifiers & TypographyModifiers & ColorsModifiers & InputProps & LabelProps & FloatingPlaceholderProps & ValidationMessageProps & Omit<CharCounterProps, 'maxLength'> & {
1820
/**
1921
* Pass to render a leading element
@@ -58,7 +60,7 @@ export declare type TextFieldProps = MarginModifiers & PaddingModifiers & Typogr
5860
/**
5961
* Internal style for the field container
6062
*/
61-
fieldStyle?: ViewStyle;
63+
fieldStyle?: ViewStyle | ((context: FieldContextType) => ViewStyle);
6264
/**
6365
* Container style of the whole component
6466
*/
@@ -116,7 +118,7 @@ declare const _default: React.ComponentClass<(Partial<Record<"margin" | "marginL
116118
/**
117119
* Internal style for the field container
118120
*/
119-
fieldStyle?: ViewStyle | undefined;
121+
fieldStyle?: ViewStyle | ((context: _FieldContextType) => ViewStyle) | undefined;
120122
/**
121123
* Container style of the whole component
122124
*/
@@ -171,7 +173,7 @@ declare const _default: React.ComponentClass<(Partial<Record<"margin" | "marginL
171173
/**
172174
* Internal style for the field container
173175
*/
174-
fieldStyle?: ViewStyle | undefined;
176+
fieldStyle?: ViewStyle | ((context: _FieldContextType) => ViewStyle) | undefined;
175177
/**
176178
* Container style of the whole component
177179
*/
@@ -226,7 +228,7 @@ declare const _default: React.ComponentClass<(Partial<Record<"margin" | "marginL
226228
/**
227229
* Internal style for the field container
228230
*/
229-
fieldStyle?: ViewStyle | undefined;
231+
fieldStyle?: ViewStyle | ((context: _FieldContextType) => ViewStyle) | undefined;
230232
/**
231233
* Container style of the whole component
232234
*/
@@ -281,7 +283,7 @@ declare const _default: React.ComponentClass<(Partial<Record<"margin" | "marginL
281283
/**
282284
* Internal style for the field container
283285
*/
284-
fieldStyle?: ViewStyle | undefined;
286+
fieldStyle?: ViewStyle | ((context: _FieldContextType) => ViewStyle) | undefined;
285287
/**
286288
* Container style of the whole component
287289
*/

generatedTypes/incubator/TextField/useFieldState.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { TextInputProps } from 'react-native';
21
import { Validator } from './types';
3-
export interface FieldStateProps extends TextInputProps {
2+
import { InputProps } from './Input';
3+
export interface FieldStateProps extends InputProps {
44
validateOnStart?: boolean;
55
validateOnChange?: boolean;
66
validateOnBlur?: boolean;

0 commit comments

Comments
 (0)