-
Notifications
You must be signed in to change notification settings - Fork 734
The new TextField (Incubator) #854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
e360aa0
initial creation of the new TextField under incubator
ethanshar 64399b4
Support label color by state
ethanshar 10e9ce3
remove warning
ethanshar 3953c91
Forward ref to input
ethanshar ee6f4ea
Allow styling Field Label
ethanshar 9a131dd
Add Field state for keeping focus state and valid state
ethanshar aaec67d
add validation events (blur, change, start)
ethanshar c3ef3f2
Add basic support to FloatingPlaceholder
ethanshar 501dfbf
Merge branch 'master' into feat/NewTextField
ethanshar 6d920af
Revert PlaygroundScreen changes
ethanshar 489e9e1
Create a dedicated example screen for the New TextField
ethanshar 0034739
Fix issue with floating placeholder behavior
ethanshar 6f4eee0
normalize android input spacings
ethanshar f5dd2ad
add calculation for the floating placeholder animation
ethanshar e256010
Render ValidationMessage only when needed and set its color
ethanshar 7bbc5b4
Merge branch 'master' into feat/NewTextField
ethanshar 7048488
Allow passing style to floatingPlaceholder
ethanshar f41f753
Support styling validationMessageError
ethanshar 165eb87
pass field state as an object
ethanshar e36a188
Support showing char counter
ethanshar e0d3fdc
Minor refactor related to Label
ethanshar a4c7321
Merge branch 'master' into feat/NewTextField
ethanshar 66cbcd3
Support multiline
ethanshar 5534fe0
Merge branch 'master' into feat/NewTextField
ethanshar af0da01
Support validation messge position and hints
ethanshar 0c86548
add example with connected value
ethanshar 37509d3
Support color by state for floating placeholder
ethanshar 9ce3dd8
update example screen
ethanshar 290879a
Fix TS errors
ethanshar 20efe64
Merge branch 'master' into feat/NewTextField
ethanshar 8767167
Fix more TS errors
ethanshar 96e31ce
Fix how we forward ref and add theme props support
ethanshar 38b46e8
Set displayName
ethanshar aea23d3
Merge branch 'master' into feat/NewTextField
ethanshar c9cb556
Fix ref warning
ethanshar 827e830
Set value to another example
ethanshar 6b2c80d
Replace leading/trailin icon with button for press functionality
ethanshar 84b889a
add accessibilityState to TextField Input
ethanshar ffa3e5d
Merge branch 'master' into feat/NewTextField
ethanshar ba191af
Fix TextField Color by state behavior - add missing error state and f…
ethanshar 5dc229e
Fix RTL issues
ethanshar ee1f682
Merge branch 'master' into feat/NewTextField
ethanshar a0ad3f6
Move logic out of CharCounter
ethanshar 7dd7472
Fix default color in getColorByState
ethanshar 8ed3c83
update maxLength to a smaller number in TextField example screen
ethanshar 55c5fc6
Fixed disabled accessibility state
ethanshar 1b6dc0f
make maxLength optional to fit with TextInput types and some logic in…
ethanshar 3ffbcf6
Update typings
ethanshar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
demo/src/screens/componentScreens/IncubatorTextFieldScreen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import _ from 'lodash'; | ||
import React, {Component} from 'react'; | ||
import {TextInput, StyleSheet, ScrollView} from 'react-native'; | ||
import { | ||
Assets, | ||
Colors, | ||
Spacings, | ||
Typography, | ||
View, | ||
Text, | ||
Button, | ||
Incubator | ||
} from 'react-native-ui-lib'; //eslint-disable-line | ||
const {TextField} = Incubator; | ||
|
||
export default class TextFieldScreen extends Component { | ||
input = React.createRef<TextInput>(); | ||
input2 = React.createRef<TextInput>(); | ||
state = { | ||
errorPosition: TextField.validationMessagePositions.TOP, | ||
shouldDisable: false, | ||
value: 'Initial Value' | ||
}; | ||
|
||
componentDidMount() { | ||
this.input.current?.focus(); | ||
} | ||
|
||
resetFieldValue = () => { | ||
this.input2.current?.clear(); | ||
} | ||
|
||
render() { | ||
const {errorPosition, shouldDisable} = this.state; | ||
return ( | ||
<ScrollView keyboardShouldPersistTaps="always"> | ||
<View flex padding-page> | ||
<Text h1>TextField</Text> | ||
<Text h3 blue50 marginV-s4> | ||
Default | ||
</Text> | ||
<TextField | ||
ref={this.input} | ||
label="Name" | ||
placeholder="Enter first and last name" | ||
/> | ||
|
||
<Text h3 blue50 marginV-s4> | ||
Static vs Floating Placeholder | ||
</Text> | ||
<View row bottom> | ||
<TextField | ||
placeholder="Floating placeholder" | ||
floatingPlaceholder | ||
floatingPlaceholderColor={{ | ||
focus: Colors.grey10, | ||
default: Colors.grey30 | ||
}} | ||
// floatingPlaceholderStyle={Typography.text60} | ||
// style={Typography.text60} | ||
containerStyle={{flex: 1}} | ||
fieldStyle={styles.withUnderline} | ||
/> | ||
<TextField | ||
placeholder="Placeholder" | ||
containerStyle={{flex: 1, marginLeft: Spacings.s4}} | ||
fieldStyle={styles.withUnderline} | ||
/> | ||
</View> | ||
<Text h3 blue50 marginV-s4> | ||
Leading/Trailing Button | ||
</Text> | ||
|
||
<TextField | ||
ref={this.input2} | ||
placeholder="Enter text..." | ||
leadingButton={{iconSource: Assets.icons.demo.search}} | ||
trailingButton={{iconSource: Assets.icons.demo.refresh, onPress: this.resetFieldValue}} | ||
fieldStyle={styles.withUnderline} | ||
/> | ||
|
||
<View row marginV-s4 spread> | ||
<Text h3 blue50> | ||
Validation | ||
</Text> | ||
<Button | ||
size={Button.sizes.xSmall} | ||
label={`Error Position: ${_.upperCase(errorPosition)}`} | ||
onPress={() => | ||
this.setState({ | ||
errorPosition: | ||
errorPosition === TextField.validationMessagePositions.TOP | ||
? TextField.validationMessagePositions.BOTTOM | ||
: TextField.validationMessagePositions.TOP | ||
}) | ||
} | ||
/> | ||
</View> | ||
|
||
<TextField | ||
value={this.state.value} | ||
onChangeText={(value) => this.setState({value})} | ||
label="Email" | ||
placeholder="Enter email" | ||
enableErrors | ||
validationMessage="Email is invalid" | ||
validationMessageStyle={Typography.text90R} | ||
validationMessagePosition={errorPosition} | ||
validate={'email'} | ||
validateOnChange | ||
// validateOnStart | ||
// validateOnBlur | ||
fieldStyle={styles.withUnderline} | ||
/> | ||
|
||
<View row centerV spread> | ||
<Text h3 blue50 marginV-s4> | ||
Colors By State | ||
</Text> | ||
<Button | ||
label={shouldDisable ? 'Enable' : 'Disable'} | ||
onPress={() => this.setState({shouldDisable: !shouldDisable})} | ||
size={Button.sizes.xSmall} | ||
/> | ||
</View> | ||
|
||
<TextField | ||
label="Email" | ||
labelColor={{default: Colors.grey10, focus: Colors.blue20, error: Colors.red30, disabled: Colors.grey40}} | ||
placeholder="Enter valid email" | ||
validationMessage="Email is invalid" | ||
validate={'email'} | ||
validateOnChange | ||
fieldStyle={styles.withFrame} | ||
editable={!shouldDisable} | ||
/> | ||
|
||
<Text h3 blue50 marginV-s4> | ||
Char Counter | ||
</Text> | ||
|
||
<TextField | ||
label="Description" | ||
placeholder="Enter text..." | ||
multiline | ||
showCharCounter | ||
charCounterStyle={{color: Colors.blue30}} | ||
maxLength={20} | ||
fieldStyle={styles.withFrame} | ||
/> | ||
<Text h3 blue50 marginV-s4> | ||
Hint | ||
</Text> | ||
<TextField | ||
placeholder="Enter password" | ||
hint="1-6 chars including numeric chars" | ||
fieldStyle={styles.withUnderline} | ||
/> | ||
</View> | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: {}, | ||
withUnderline: { | ||
borderBottomWidth: 1, | ||
borderColor: Colors.grey40, | ||
paddingBottom: 4 | ||
}, | ||
withFrame: { | ||
borderWidth: 1, | ||
borderColor: Colors.grey40, | ||
padding: 4, | ||
borderRadius: 2 | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// <reference types="react" /> | ||
import { ButtonPropTypes } from '../../components/button'; | ||
declare const _default: (props: ButtonPropTypes) => JSX.Element; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference types="react" /> | ||
import { TextStyle } from 'react-native'; | ||
export interface CharCounterProps { | ||
showCharCounter?: boolean; | ||
maxLength?: number; | ||
charCounterStyle?: TextStyle; | ||
} | ||
declare const _default: ({ maxLength, charCounterStyle }: CharCounterProps) => JSX.Element | null; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference types="react" /> | ||
export declare type ContextType = { | ||
value?: string; | ||
isFocused: boolean; | ||
hasValue: boolean; | ||
isValid: boolean; | ||
disabled: boolean; | ||
}; | ||
declare const FieldContext: import("react").Context<ContextType>; | ||
export default FieldContext; |
10 changes: 10 additions & 0 deletions
10
generatedTypes/incubator/TextField/FloatingPlaceholder.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference types="react" /> | ||
import { TextStyle } from 'react-native'; | ||
import { ColorType } from './types'; | ||
export interface FloatingPlaceholderProps { | ||
placeholder?: string; | ||
floatingPlaceholderColor?: ColorType; | ||
floatingPlaceholderStyle?: TextStyle; | ||
} | ||
declare const _default: ({ placeholder, floatingPlaceholderColor, floatingPlaceholderStyle }: FloatingPlaceholderProps) => JSX.Element; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// <reference types="react" /> | ||
import { ImageProps } from '../../components/image'; | ||
declare const _default: (props: ImageProps) => JSX.Element; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { TextInput, TextInputProps } from 'react-native'; | ||
import { ForwardRefInjectedProps } from '../../commons/new'; | ||
export interface InputProps extends TextInputProps, React.ComponentPropsWithRef<typeof TextInput> { | ||
hint?: string; | ||
} | ||
declare const Input: ({ style, hint, forwardedRef, ...props }: InputProps & ForwardRefInjectedProps) => JSX.Element; | ||
export default Input; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// <reference types="react" /> | ||
import { TextStyle } from 'react-native'; | ||
import { TextPropTypes } from '../../components/text'; | ||
import { ColorType, ValidationMessagePosition } from './types'; | ||
export interface LabelProps { | ||
label?: string; | ||
labelColor?: ColorType; | ||
labelStyle?: TextStyle; | ||
labelProps?: TextPropTypes; | ||
validationMessagePosition?: ValidationMessagePosition; | ||
} | ||
declare const _default: ({ label, labelColor, labelStyle, labelProps, validationMessagePosition }: LabelProps) => JSX.Element | null; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ContextType } from './FieldContext'; | ||
import { ColorType } from './types'; | ||
export declare function getColorByState(color: ColorType, context?: ContextType): string | undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference types="react" /> | ||
import { TextStyle } from 'react-native'; | ||
export interface ValidationMessageProps { | ||
enableErrors?: boolean; | ||
validationMessage?: string; | ||
validationMessageStyle?: TextStyle; | ||
retainSpace?: boolean; | ||
} | ||
declare const _default: ({ validationMessage, enableErrors, validationMessageStyle, retainSpace }: ValidationMessageProps) => JSX.Element | null; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { ViewStyle, TextStyle } from 'react-native'; | ||
import { ButtonPropTypes } from '../../components/button'; | ||
import { ValidationMessagePosition } from './types'; | ||
import { InputProps } from './Input'; | ||
import { ValidationMessageProps } from './ValidationMessage'; | ||
import { LabelProps } from './Label'; | ||
import { FieldStateProps } from './withFieldState'; | ||
import { FloatingPlaceholderProps } from './FloatingPlaceholder'; | ||
import { CharCounterProps } from './CharCounter'; | ||
interface TextFieldProps extends InputProps, LabelProps, FloatingPlaceholderProps, FieldStateProps, ValidationMessageProps, Omit<CharCounterProps, 'maxLength'> { | ||
leadingButton?: ButtonPropTypes; | ||
trailingButton?: ButtonPropTypes; | ||
floatingPlaceholder?: boolean; | ||
floatingPlaceholderStyle?: TextStyle; | ||
validationMessagePosition?: ValidationMessagePosition; | ||
fieldStyle?: ViewStyle; | ||
containerStyle?: ViewStyle; | ||
} | ||
interface StaticMembers { | ||
validationMessagePositions: typeof ValidationMessagePosition; | ||
} | ||
declare const _default: React.ComponentClass<TextFieldProps & { | ||
useCustomTheme?: boolean | undefined; | ||
}, any> & StaticMembers; | ||
export default _default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export declare type ColorType = string | { | ||
default?: string; | ||
focus?: string; | ||
error?: string; | ||
disabled?: string; | ||
}; | ||
export declare enum ValidationMessagePosition { | ||
TOP = "top", | ||
BOTTOM = "bottom" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
declare const validators: { | ||
required: (value: string) => boolean; | ||
email: (value: string) => boolean; | ||
url: (value: string) => boolean; | ||
number: (value: string) => boolean; | ||
price: (value: string) => boolean; | ||
}; | ||
export default validators; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { TextInputProps } from 'react-native'; | ||
import validators from './validators'; | ||
export declare type Validator = Function | keyof typeof validators; | ||
interface FieldState { | ||
value?: string; | ||
isFocused: boolean; | ||
isValid: boolean; | ||
hasValue: boolean; | ||
} | ||
export interface FieldStateInjectedProps { | ||
fieldState: FieldState; | ||
onFocus: Function; | ||
onBlur: Function; | ||
ref?: any; | ||
} | ||
export interface FieldStateProps extends TextInputProps { | ||
validateOnStart?: boolean; | ||
validateOnChange?: boolean; | ||
validateOnBlur?: boolean; | ||
validate?: Validator | Validator[]; | ||
} | ||
declare function withFieldState(WrappedComponent: React.ComponentType<FieldStateInjectedProps & TextInputProps>): { | ||
({ validate, validateOnBlur, validateOnChange, validateOnStart, ...props }: FieldStateProps): JSX.Element; | ||
displayName: string | undefined; | ||
}; | ||
export default withFieldState; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as TabController } from './TabController'; | ||
export { default as TextField } from './TextField'; | ||
export { default as TouchableOpacity } from './TouchableOpacity'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import Button, {ButtonPropTypes} from '../../components/button'; | ||
|
||
export default (props: ButtonPropTypes) => { | ||
return ( | ||
<Button link grey10 activeOpacity={props.onPress ? 0.6 : 1} {...props} /> | ||
Inbal-Tish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, {useContext} from 'react'; | ||
import {TextStyle, StyleSheet} from 'react-native'; | ||
import _ from 'lodash'; | ||
import Text from '../../components/text'; | ||
import FieldContext from './FieldContext'; | ||
|
||
export interface CharCounterProps { | ||
showCharCounter?: boolean; | ||
Inbal-Tish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
maxLength?: number; | ||
Inbal-Tish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
charCounterStyle?: TextStyle; | ||
} | ||
|
||
export default ({maxLength, charCounterStyle}: CharCounterProps) => { | ||
const {value} = useContext(FieldContext); | ||
|
||
if (_.isUndefined(maxLength)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Text grey30 style={[styles.container, charCounterStyle]}> | ||
{`${_.size(value)}/${maxLength}`} | ||
</Text> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
textAlign: 'right' | ||
} | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.