-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move text inputs and buttons into its own components.
- Loading branch information
1 parent
1e7366f
commit f2cb165
Showing
3 changed files
with
112 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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,45 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { TouchableOpacity, Text, StyleSheet } from 'react-native'; | ||
|
||
/** | ||
* A stateless function component which renders a button. | ||
* | ||
* @param {obj} props | ||
*/ | ||
const FormButton = (props) => { | ||
const { children, onPress } = props; | ||
|
||
return ( | ||
<TouchableOpacity style={styles.button} onPress={onPress}> | ||
<Text style={styles.buttonText}>{children}</Text> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
FormButton.propTypes = { | ||
onPress: PropTypes.func, | ||
children: PropTypes.string.isRequired, | ||
}; | ||
|
||
FormButton.defaultProps = { | ||
onPress: f => f, | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
backgroundColor: '#FD6592', | ||
borderRadius: 3, | ||
height: 40, | ||
marginBottom: 15, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
buttonText: { | ||
color: '#FFF', | ||
fontWeight: 'bold', | ||
fontSize: 16, | ||
}, | ||
}); | ||
|
||
export default FormButton; |
This file contains 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,55 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
View, TextInput, Text, StyleSheet, | ||
} from 'react-native'; | ||
|
||
/** | ||
* A component which renders a TextInput with a label above it. | ||
* Note: This component can easily be written as a stateless function | ||
* since it only includes the `render()` function and nothing else | ||
* (see FormButton component as an example). | ||
*/ | ||
class FormTextInput extends React.Component { | ||
render() { | ||
const { labelText, ...inputProps } = this.props; | ||
|
||
return ( | ||
<View style={styles.inputWrapper}> | ||
{labelText && <Text style={styles.label}>{labelText}</Text>} | ||
<TextInput style={styles.textInput} {...inputProps} /> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
FormTextInput.propTypes = { | ||
labelText: PropTypes.string, | ||
}; | ||
|
||
FormTextInput.defaultProps = { | ||
labelText: null, | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
inputWrapper: { | ||
marginBottom: 15, | ||
flexDirection: 'column', | ||
}, | ||
textInput: { | ||
height: 40, | ||
borderColor: '#FFF', | ||
borderWidth: 1, | ||
borderRadius: 3, | ||
backgroundColor: '#FFF', | ||
paddingHorizontal: 10, | ||
fontSize: 18, | ||
color: '#3F4EA5', | ||
}, | ||
label: { | ||
color: '#FFF', | ||
marginBottom: 5, | ||
}, | ||
}); | ||
|
||
export default FormTextInput; |