-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: TextField component #4904
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
Open
wonderlul
wants to merge
7
commits into
callstack:@adrcotfas/feat/dynamic_theme
Choose a base branch
from
wonderlul:feat/TextField
base: @adrcotfas/feat/dynamic_theme
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d0cffca
feat: text field component introduction
wonderlul 89c0638
fix: rtl handling
wonderlul e04a56f
fix: md3 colors and opacity
wonderlul 0355821
chore: introduced component specific alpha layers
wonderlul 3de6eaf
fix: outline error styles
wonderlul 85fddb6
feat: placeholder with animation in progress
wonderlul f4b61fd
chore: placeholder with animation
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,213 @@ | ||
| import * as React from 'react'; | ||
| import { Pressable, StyleSheet, View } from 'react-native'; | ||
|
|
||
| import { | ||
| Icon, | ||
| List, | ||
| TextField, | ||
| type TextFieldAccessoryProps, | ||
| } from 'react-native-paper'; | ||
|
|
||
| import { useExampleTheme } from '../hooks/useExampleTheme'; | ||
| import ScreenWrapper from '../ScreenWrapper'; | ||
|
|
||
| const TextFieldExample = () => { | ||
| const { colors } = useExampleTheme(); | ||
| const iconMuted = colors.onSurfaceVariant; | ||
| const [searchQuery, setSearchQuery] = React.useState(''); | ||
| const [email, setEmail] = React.useState(''); | ||
| const [filledPassword, setFilledPassword] = React.useState(''); | ||
| const [filledNotes, setFilledNotes] = React.useState(''); | ||
| const [outlinedSearchQuery, setOutlinedSearchQuery] = React.useState(''); | ||
| const [outlinedText, setOutlinedText] = React.useState(''); | ||
| const [outlinedPassword, setOutlinedPassword] = React.useState(''); | ||
| const [outlinedNotes, setOutlinedNotes] = React.useState(''); | ||
| const [errorField, setErrorField] = React.useState('invalid@'); | ||
|
|
||
| const ClearFilledSearchAccessory = ({ | ||
| style, | ||
| editable, | ||
| }: TextFieldAccessoryProps) => { | ||
| return ( | ||
| <Pressable | ||
| style={style} | ||
| disabled={!editable} | ||
| onPress={() => setSearchQuery('')} | ||
| accessibilityRole="button" | ||
| accessibilityLabel="Clear text" | ||
| > | ||
| <Icon source="close" size={24} color={iconMuted} /> | ||
| </Pressable> | ||
| ); | ||
| }; | ||
|
|
||
| const ClearOutlinedSearchAccessory = ({ | ||
| style, | ||
| editable, | ||
| }: TextFieldAccessoryProps) => { | ||
| return ( | ||
| <Pressable | ||
| style={style} | ||
| disabled={!editable} | ||
| onPress={() => setOutlinedSearchQuery('')} | ||
| accessibilityRole="button" | ||
| accessibilityLabel="Clear text" | ||
| > | ||
| <Icon source="close" size={24} color={iconMuted} /> | ||
| </Pressable> | ||
| ); | ||
| }; | ||
|
|
||
| const SearchLeadingAccessory = ({ style }: TextFieldAccessoryProps) => { | ||
| return ( | ||
| <View style={style}> | ||
| <Icon source="magnify" size={24} color={iconMuted} /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <ScreenWrapper contentContainerStyle={styles.container}> | ||
| <List.Section title="Filled" style={styles.section}> | ||
| <TextField | ||
| variant="filled" | ||
| label="With accessories" | ||
| value={searchQuery} | ||
| onChangeText={setSearchQuery} | ||
| LeftAccessory={SearchLeadingAccessory} | ||
| RightAccessory={ClearFilledSearchAccessory} | ||
| pressableStyle={styles.field} | ||
| placeholder="Search" | ||
| /> | ||
| <TextField | ||
| variant="filled" | ||
| label="Without accessories" | ||
| value={email} | ||
| onChangeText={setEmail} | ||
| keyboardType="email-address" | ||
| autoCapitalize="none" | ||
| autoCorrect={false} | ||
| pressableStyle={styles.field} | ||
| placeholder="Email" | ||
| /> | ||
| <TextField | ||
| variant="filled" | ||
| label="Email (error)" | ||
| helper="Enter a valid email address." | ||
| placeholder="name@example.com" | ||
| status="error" | ||
| value={errorField} | ||
| onChangeText={setErrorField} | ||
| keyboardType="email-address" | ||
| autoCapitalize="none" | ||
| pressableStyle={styles.field} | ||
| /> | ||
| <TextField | ||
| variant="filled" | ||
| label="Account (disabled)" | ||
| helper="Contact support to make changes." | ||
| value="read-only@example.com" | ||
| editable={false} | ||
| pressableStyle={styles.field} | ||
| /> | ||
| <TextField | ||
| variant="filled" | ||
| label="Notes (multiline)" | ||
| helper="Optional details for your request." | ||
| placeholder="Add a note…" | ||
| value={filledNotes} | ||
| onChangeText={setFilledNotes} | ||
| multiline | ||
| pressableStyle={styles.field} | ||
| /> | ||
| <TextField | ||
| variant="filled" | ||
| label="Password" | ||
| helper="At least 8 characters." | ||
| placeholder="••••••••" | ||
| value={filledPassword} | ||
| onChangeText={setFilledPassword} | ||
| secureTextEntry | ||
| textContentType="password" | ||
| pressableStyle={styles.field} | ||
| /> | ||
| </List.Section> | ||
|
|
||
| <List.Section title="Outlined" style={styles.section}> | ||
| <TextField | ||
| variant="outlined" | ||
| label="With accessories" | ||
| value={outlinedSearchQuery} | ||
| onChangeText={setOutlinedSearchQuery} | ||
| LeftAccessory={SearchLeadingAccessory} | ||
| RightAccessory={ClearOutlinedSearchAccessory} | ||
| pressableStyle={styles.field} | ||
| placeholder="Search" | ||
| /> | ||
| <TextField | ||
| variant="outlined" | ||
| label="Without accessories" | ||
| value={outlinedText} | ||
| onChangeText={setOutlinedText} | ||
| pressableStyle={styles.field} | ||
| /> | ||
| <TextField | ||
| variant="outlined" | ||
| label="Email (error)" | ||
| helper="Enter a valid email address." | ||
| placeholder="name@example.com" | ||
| status="error" | ||
| value={errorField} | ||
| onChangeText={setErrorField} | ||
| keyboardType="email-address" | ||
| autoCapitalize="none" | ||
| pressableStyle={styles.field} | ||
| /> | ||
| <TextField | ||
| variant="outlined" | ||
| label="Disabled via status" | ||
| helper="This field cannot be edited." | ||
| value="Disabled" | ||
| status="disabled" | ||
| pressableStyle={styles.field} | ||
| /> | ||
| <TextField | ||
| variant="outlined" | ||
| label="Notes (multiline)" | ||
| helper="Optional details for your request." | ||
| placeholder="Add a note…" | ||
| value={outlinedNotes} | ||
| onChangeText={setOutlinedNotes} | ||
| multiline | ||
| pressableStyle={styles.field} | ||
| /> | ||
| <TextField | ||
| variant="outlined" | ||
| label="Password" | ||
| helper="At least 8 characters." | ||
| placeholder="••••••••" | ||
| value={outlinedPassword} | ||
| onChangeText={setOutlinedPassword} | ||
| secureTextEntry | ||
| textContentType="password" | ||
| pressableStyle={styles.field} | ||
| /> | ||
| </List.Section> | ||
| </ScreenWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| TextFieldExample.title = 'TextField'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| paddingHorizontal: 16, | ||
| paddingVertical: 8, | ||
| }, | ||
| field: {}, | ||
| section: { | ||
| gap: 16, | ||
| }, | ||
| }); | ||
|
|
||
| export default TextFieldExample; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No outline is visible here.