-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: TextInput component #4909
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
+5,243
−7,312
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
daea379
feat: text field component
wonderlul 72ba9d5
chore: interface to type
wonderlul 5446df6
feat: remove override props
wonderlul 50fc4d9
chore: pointer events declared in styles
wonderlul 32ed62f
chore: isweb to inline check
wonderlul 77049d0
chore: remove unnecessary spyon in jest
wonderlul 6a7f01e
chore: remove unnecessary comments
wonderlul 492964a
feat: use locale instead of i18n manager
wonderlul d839884
feat: accessories as function not components
wonderlul dbb91ff
feat: introduce separate disable props
wonderlul b03311e
feat: render prop
wonderlul aa19edf
chore: text field icon props
wonderlul 617becb
chore: ts style declarations
wonderlul 996d92c
feat: a11y
wonderlul b83c03c
chore: dimensions round
wonderlul 7adba7d
chore: style adjustment
wonderlul 8322405
chore: refactor
wonderlul 8effa88
feat: uncontrolled variant
wonderlul 2dbd99d
chore: docs
wonderlul 0f534fd
chore: refactor
wonderlul 635c092
chore: uncontrolled variant state management
wonderlul 0d114b2
chore: event-driven animations
wonderlul f5d6605
chore: implementation details
wonderlul 3ecda7e
feat: text input migration
wonderlul c425f48
fix: docs building
wonderlul 60bd209
chore: docs migration guide
wonderlul 2c87935
chore: merge from main
wonderlul 314e09b
chore: docs update
wonderlul 44f1490
chore: removed memoization
wonderlul 8e11926
feat: sync float to value edge case
wonderlul 92bda6b
feat: placeholder material web design complience
wonderlul 72dcdd5
feat: guard to imperative focus
wonderlul 929aa14
Merge branch 'main' into feat/TextField-v6
wonderlul 6950b5b
chore: tests
wonderlul 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,244 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| StyleSheet, | ||
| TextInput, | ||
| View, | ||
| type TextStyle, | ||
| type ViewStyle, | ||
| } from 'react-native'; | ||
|
|
||
| import { | ||
| Divider, | ||
| List, | ||
| Switch, | ||
| Text, | ||
| TextField, | ||
| TouchableRipple, | ||
| type TextFieldAccessoryProps, | ||
| type TextFieldVariant, | ||
| } from 'react-native-paper'; | ||
|
|
||
| import { useExampleTheme } from '../hooks/useExampleTheme'; | ||
| import ScreenWrapper from '../ScreenWrapper'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Types | ||
| // --------------------------------------------------------------------------- | ||
|
wonderlul marked this conversation as resolved.
Outdated
|
||
|
|
||
| type DemoControls = { | ||
| error: boolean; | ||
| disabled: boolean; | ||
| leadingIcon: boolean; | ||
| trailingIcon: boolean; | ||
| counter: boolean; | ||
| showPrefix: boolean; | ||
| showSuffix: boolean; | ||
| multiline: boolean; | ||
| }; | ||
|
|
||
| type DemoModifiers = { | ||
| label: string; | ||
| helperText: string; | ||
| placeholder: string; | ||
| prefix: string; | ||
| suffix: string; | ||
| }; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // TextFieldDemo | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| type TextFieldDemoProps = { | ||
| variant: TextFieldVariant; | ||
| }; | ||
|
|
||
| const TextFieldDemo = ({ variant }: TextFieldDemoProps) => { | ||
| const theme = useExampleTheme(); | ||
|
|
||
| const [value, setValue] = React.useState(''); | ||
|
|
||
| const [controls, setControls] = React.useState<DemoControls>({ | ||
| error: false, | ||
| disabled: false, | ||
| leadingIcon: false, | ||
| trailingIcon: false, | ||
| counter: false, | ||
| showPrefix: false, | ||
| showSuffix: false, | ||
| multiline: false, | ||
| }); | ||
|
|
||
| const [modifiers, setModifiers] = React.useState<DemoModifiers>({ | ||
| label: 'Label', | ||
| helperText: 'Supporting text', | ||
| placeholder: 'Placeholder', | ||
| prefix: '$', | ||
| suffix: '/100', | ||
| }); | ||
|
|
||
| const toggleControl = (key: keyof DemoControls) => | ||
| setControls((prev) => ({ ...prev, [key]: !prev[key] })); | ||
|
|
||
| const setModifier = (key: keyof DemoModifiers, text: string) => | ||
| setModifiers((prev) => ({ ...prev, [key]: text })); | ||
|
|
||
| const LeadingIcon = React.useCallback( | ||
| (props: TextFieldAccessoryProps) => ( | ||
| <TextField.Icon {...props} icon="magnify" /> | ||
| ), | ||
| [] | ||
| ); | ||
|
|
||
| const TrailingIcon = React.useCallback( | ||
| (props: TextFieldAccessoryProps) => ( | ||
| <TextField.Icon {...props} icon="close" onPress={() => setValue('')} /> | ||
| ), | ||
| [] | ||
| ); | ||
|
|
||
| const inputColor = theme.colors.onSurfaceVariant; | ||
| const borderColor = theme.colors.outlineVariant; | ||
|
|
||
| const modifierInputStyle: TextStyle = { | ||
| flex: 1, | ||
| color: inputColor, | ||
| fontSize: 14, | ||
| paddingVertical: 4, | ||
| borderBottomWidth: StyleSheet.hairlineWidth, | ||
| borderBottomColor: borderColor, | ||
| }; | ||
|
|
||
| const SWITCH_CONTROLS: { label: string; key: keyof DemoControls }[] = [ | ||
| { label: 'Error', key: 'error' }, | ||
| { label: 'Disabled', key: 'disabled' }, | ||
| { label: 'Leading icon', key: 'leadingIcon' }, | ||
| { label: 'Trailing icon', key: 'trailingIcon' }, | ||
| { label: 'Counter', key: 'counter' }, | ||
| { label: 'Prefix', key: 'showPrefix' }, | ||
| { label: 'Suffix', key: 'showSuffix' }, | ||
| { label: 'Multiline', key: 'multiline' }, | ||
| ]; | ||
|
|
||
| const MODIFIER_FIELDS: { label: string; key: keyof DemoModifiers }[] = [ | ||
| { label: 'Label', key: 'label' }, | ||
| { label: 'Helper', key: 'helperText' }, | ||
| { label: 'Placeholder', key: 'placeholder' }, | ||
| { label: 'Prefix', key: 'prefix' }, | ||
| { label: 'Suffix', key: 'suffix' }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <View style={styles.demoContainer}> | ||
| {/* Live TextField */} | ||
| <TextField | ||
| variant={variant} | ||
| label={modifiers.label || undefined} | ||
| placeholder={modifiers.placeholder || undefined} | ||
| supportingText={modifiers.helperText || undefined} | ||
| error={controls.error} | ||
| editable={!controls.disabled} | ||
| value={value} | ||
| onChangeText={setValue} | ||
| multiline={controls.multiline} | ||
| counter={controls.counter} | ||
| maxLength={controls.counter ? 100 : undefined} | ||
| prefix={controls.showPrefix ? modifiers.prefix : undefined} | ||
| suffix={controls.showSuffix ? modifiers.suffix : undefined} | ||
| StartAccessory={controls.leadingIcon ? LeadingIcon : undefined} | ||
| EndAccessory={controls.trailingIcon ? TrailingIcon : undefined} | ||
| /> | ||
|
|
||
| <Divider style={styles.divider} /> | ||
|
|
||
| {/* Controls */} | ||
| <List.Subheader style={styles.subheader}>Controls</List.Subheader> | ||
| {SWITCH_CONTROLS.map(({ label, key }) => ( | ||
| <TouchableRipple key={key} onPress={() => toggleControl(key)}> | ||
| <View style={styles.switchRow}> | ||
| <Text variant="bodyMedium">{label}</Text> | ||
| <View pointerEvents="none"> | ||
| <Switch value={controls[key]} /> | ||
| </View> | ||
| </View> | ||
| </TouchableRipple> | ||
| ))} | ||
|
|
||
| <Divider style={styles.divider} /> | ||
|
|
||
| {/* Modifiers */} | ||
| <List.Subheader style={styles.subheader}>Modifiers</List.Subheader> | ||
| {MODIFIER_FIELDS.map(({ label, key }) => ( | ||
| <View key={key} style={styles.modifierRow}> | ||
| <Text variant="bodyMedium" style={styles.modifierLabel}> | ||
| {label} | ||
| </Text> | ||
| <TextInput | ||
| value={modifiers[key]} | ||
| onChangeText={(text) => setModifier(key, text)} | ||
| style={modifierInputStyle} | ||
| placeholderTextColor={theme.colors.outline} | ||
| placeholder={`Enter ${label.toLowerCase()}…`} | ||
| /> | ||
| </View> | ||
| ))} | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // TextFieldExample | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| const TextFieldExample = () => { | ||
| return ( | ||
| <ScreenWrapper contentContainerStyle={styles.container}> | ||
| <List.Section title="Filled"> | ||
| <TextFieldDemo variant="filled" /> | ||
| </List.Section> | ||
| <List.Section title="Outlined"> | ||
| <TextFieldDemo variant="outlined" /> | ||
| </List.Section> | ||
| </ScreenWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| TextFieldExample.title = 'TextField'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Styles | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| paddingHorizontal: 16, | ||
| paddingVertical: 8, | ||
| } satisfies ViewStyle, | ||
| demoContainer: { | ||
| gap: 4, | ||
| } satisfies ViewStyle, | ||
| divider: { | ||
| marginVertical: 8, | ||
| } satisfies ViewStyle, | ||
| subheader: { | ||
| paddingHorizontal: 0, | ||
| } satisfies TextStyle, | ||
| switchRow: { | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| paddingVertical: 8, | ||
| paddingHorizontal: 8, | ||
| } satisfies ViewStyle, | ||
| modifierRow: { | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| gap: 12, | ||
| paddingVertical: 8, | ||
| paddingHorizontal: 8, | ||
| } satisfies ViewStyle, | ||
| modifierLabel: { | ||
| width: 80, | ||
| } satisfies TextStyle, | ||
| }); | ||
|
|
||
| export default TextFieldExample; | ||
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
Oops, something went wrong.
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.