2018-04-24 19:34:03 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-11-14 21:42:03 +00:00
|
|
|
import { StyleSheet, Text, ActivityIndicator } from 'react-native';
|
|
|
|
import { RectButton } from 'react-native-gesture-handler';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2018-11-14 21:42:03 +00:00
|
|
|
import { COLOR_BUTTON_PRIMARY } from '../../constants/colors';
|
|
|
|
import sharedStyles from '../../views/Styles';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
|
|
|
const colors = {
|
2018-08-10 17:26:36 +00:00
|
|
|
background_primary: COLOR_BUTTON_PRIMARY,
|
|
|
|
background_secondary: 'white',
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
text_color_primary: 'white',
|
2018-11-14 21:42:03 +00:00
|
|
|
text_color_secondary: COLOR_BUTTON_PRIMARY
|
2018-04-24 19:34:03 +00:00
|
|
|
};
|
|
|
|
|
2018-08-01 19:35:06 +00:00
|
|
|
/* eslint-disable react-native/no-unused-styles */
|
2018-04-24 19:34:03 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2018-11-14 21:42:03 +00:00
|
|
|
paddingHorizontal: 15,
|
2018-08-10 17:26:36 +00:00
|
|
|
justifyContent: 'center',
|
2018-11-14 21:42:03 +00:00
|
|
|
height: 48,
|
|
|
|
borderRadius: 2,
|
|
|
|
marginBottom: 10
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
|
|
|
text: {
|
2018-11-14 21:42:03 +00:00
|
|
|
fontSize: 18,
|
2018-11-19 18:18:15 +00:00
|
|
|
textAlign: 'center'
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
|
|
|
background_primary: {
|
2018-08-10 17:26:36 +00:00
|
|
|
backgroundColor: colors.background_primary
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
|
|
|
background_secondary: {
|
2018-08-10 17:26:36 +00:00
|
|
|
backgroundColor: colors.background_secondary
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
2018-11-14 21:42:03 +00:00
|
|
|
text_primary: {
|
|
|
|
...sharedStyles.textMedium,
|
2018-08-10 17:26:36 +00:00
|
|
|
color: colors.text_color_primary
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
2018-11-14 21:42:03 +00:00
|
|
|
text_secondary: {
|
|
|
|
...sharedStyles.textBold,
|
2018-08-10 17:26:36 +00:00
|
|
|
color: colors.text_color_secondary
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
|
|
|
disabled: {
|
2018-11-14 21:42:03 +00:00
|
|
|
backgroundColor: '#e1e5e8'
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default class Button extends React.PureComponent {
|
|
|
|
static propTypes = {
|
2018-11-14 21:42:03 +00:00
|
|
|
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
2018-04-24 19:34:03 +00:00
|
|
|
type: PropTypes.string,
|
|
|
|
onPress: PropTypes.func,
|
2018-07-17 19:10:27 +00:00
|
|
|
disabled: PropTypes.bool,
|
2018-08-10 17:26:36 +00:00
|
|
|
backgroundColor: PropTypes.string,
|
2018-11-19 18:18:15 +00:00
|
|
|
loading: PropTypes.bool,
|
|
|
|
style: PropTypes.any
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
title: 'Press me!',
|
|
|
|
type: 'primary',
|
|
|
|
onPress: () => alert('It works!'),
|
2018-08-10 17:26:36 +00:00
|
|
|
disabled: false,
|
|
|
|
loading: false
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2018-11-19 18:18:15 +00:00
|
|
|
title, type, onPress, disabled, backgroundColor, loading, style, ...otherProps
|
2018-04-24 19:34:03 +00:00
|
|
|
} = this.props;
|
|
|
|
return (
|
2018-11-14 21:42:03 +00:00
|
|
|
<RectButton
|
2018-04-24 19:34:03 +00:00
|
|
|
onPress={onPress}
|
2018-11-14 21:42:03 +00:00
|
|
|
enabled={!(disabled || loading)}
|
|
|
|
style={[
|
|
|
|
styles.container,
|
|
|
|
backgroundColor ? { backgroundColor } : styles[`background_${ type }`],
|
2018-11-19 18:18:15 +00:00
|
|
|
disabled && styles.disabled,
|
|
|
|
style
|
2018-11-14 21:42:03 +00:00
|
|
|
]}
|
2018-05-23 13:39:18 +00:00
|
|
|
{...otherProps}
|
2018-04-24 19:34:03 +00:00
|
|
|
>
|
2018-11-14 21:42:03 +00:00
|
|
|
{
|
|
|
|
loading
|
|
|
|
? <ActivityIndicator color={colors[`text_color_${ type }`]} />
|
|
|
|
: <Text style={[styles.text, styles[`text_${ type }`]]}>{title}</Text>
|
|
|
|
}
|
|
|
|
</RectButton>
|
2018-04-24 19:34:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|