2018-08-10 17:26:36 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { View, Text, TouchableWithoutFeedback } from 'react-native';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
|
|
|
import styles from './styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-03-01 16:49:11 +00:00
|
|
|
import DisclosureIndicator from '../../containers/DisclosureIndicator';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
|
|
|
export default class Button extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
subtitle: PropTypes.string,
|
|
|
|
type: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2018-08-10 17:26:36 +00:00
|
|
|
icon: PropTypes.node.isRequired,
|
|
|
|
testID: PropTypes.string.isRequired,
|
|
|
|
onPress: PropTypes.func
|
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
title: 'Press me!',
|
|
|
|
type: 'primary',
|
|
|
|
onPress: () => alert('It works!')
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
active: false
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2019-12-04 16:39:53 +00:00
|
|
|
title, subtitle, type, onPress, icon, testID, theme
|
2018-08-10 17:26:36 +00:00
|
|
|
} = this.props;
|
|
|
|
const { active } = this.state;
|
|
|
|
const activeStyle = active && styles.buttonActive;
|
2019-12-04 16:39:53 +00:00
|
|
|
const isPrimary = (type === 'primary');
|
|
|
|
const buttonContainerStyle = {
|
|
|
|
backgroundColor: isPrimary ? themes[theme].actionTintColor : themes[theme].focusedBackground,
|
|
|
|
borderColor: isPrimary ? themes[theme].actionTintColor : themes[theme].borderColor
|
|
|
|
};
|
2018-08-10 17:26:36 +00:00
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback
|
|
|
|
onPress={onPress}
|
|
|
|
onPressIn={() => this.setState({ active: true })}
|
|
|
|
onPressOut={() => this.setState({ active: false })}
|
|
|
|
testID={testID}
|
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
<View style={[styles.buttonContainer, buttonContainerStyle]}>
|
2018-08-10 17:26:36 +00:00
|
|
|
<View style={styles.buttonIconContainer}>
|
|
|
|
{icon}
|
|
|
|
</View>
|
|
|
|
<View style={styles.buttonCenter}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.buttonTitle, { color: isPrimary ? themes[theme].buttonText : themes[theme].tintColor }, activeStyle]}>{title}</Text>
|
|
|
|
{subtitle ? <Text style={[styles.buttonSubtitle, activeStyle, { color: themes[theme].auxiliaryText }]}>{subtitle}</Text> : null}
|
2018-08-10 17:26:36 +00:00
|
|
|
</View>
|
2019-12-04 16:39:53 +00:00
|
|
|
{type === 'secondary' ? <DisclosureIndicator theme={theme} /> : null}
|
2018-08-10 17:26:36 +00:00
|
|
|
</View>
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|