Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Last active April 30, 2020 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllGistsEqual/9e1bba8469828a9c5674de2ecd6099fd to your computer and use it in GitHub Desktop.
Save AllGistsEqual/9e1bba8469828a9c5674de2ecd6099fd to your computer and use it in GitHub Desktop.
import React from 'react'
import PropTypes from 'prop-types'
import {
StyleSheet,
Text,
View,
TouchableOpacity,
} from 'react-native'
const TextButton = ({
title,
onPress,
type,
}) => (
<TouchableOpacity onPress={() => onPress()}>
<View style={{ ...styles.baseButton, ...styles[`${type}Button`] }}>
<Text style={{ ...styles.baseText, ...styles[`${type}Text`] }}>
{title}
</Text>
</View>
</TouchableOpacity>
)
const styles = StyleSheet.create({
baseButton: {
borderWidth: 3,
borderRadius: 8,
padding: 12,
overflow: 'hidden',
},
baseText: {
fontSize: 18,
textAlign: 'center',
fontWeight: 'bold',
},
defaultButton: {
backgroundColor: '#ccc',
borderColor: '#666',
},
defaultText: {
color: '#000',
},
primaryButton: {
backgroundColor: '#ff7100',
borderColor: '#ad5f00',
},
primaryText: {
color: '#fff',
},
secondaryButton: {
backgroundColor: '#1cb7ff',
borderColor: '#157fff',
},
secondaryText: {
color: '#fff',
},
successButton: {
backgroundColor: 'green',
borderColor: 'darkgreen',
},
successText: {
color: '#fff',
},
warningButton: {
backgroundColor: 'red',
borderColor: 'darkred',
},
warningText: {
color: '#fff',
},
})
TextButton.defaultProps = {
onPress: undefined,
type: 'default',
}
TextButton.propTypes = {
title: PropTypes.string.isRequired,
onPress: PropTypes.func,
type: PropTypes.oneOf([
'default',
'primary',
'secondary',
'success',
'warning',
]),
}
export default TextButton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment