2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
2022-05-20 16:37:57 +00:00
|
|
|
import { StyleProp, StyleSheet, Text, TextStyle } from 'react-native';
|
|
|
|
import Touchable, { PlatformTouchableProps } from 'react-native-platform-touchable';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-05-20 16:37:57 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
|
|
|
import ActivityIndicator from '../ActivityIndicator';
|
|
|
|
|
2022-05-20 16:37:57 +00:00
|
|
|
interface IButtonProps extends PlatformTouchableProps {
|
2021-09-13 20:41:05 +00:00
|
|
|
title: string;
|
2022-05-20 16:37:57 +00:00
|
|
|
onPress: () => void;
|
|
|
|
type?: string;
|
|
|
|
backgroundColor?: string;
|
|
|
|
loading?: boolean;
|
|
|
|
color?: string;
|
|
|
|
fontSize?: number;
|
|
|
|
styleText?: StyleProp<TextStyle>[];
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
paddingHorizontal: 14,
|
|
|
|
justifyContent: 'center',
|
|
|
|
height: 48,
|
|
|
|
borderRadius: 2,
|
|
|
|
marginBottom: 12
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
...sharedStyles.textMedium,
|
|
|
|
...sharedStyles.textAlignCenter
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
opacity: 0.3
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-20 16:37:57 +00:00
|
|
|
const Button = ({
|
|
|
|
type = 'primary',
|
|
|
|
disabled = false,
|
|
|
|
loading = false,
|
|
|
|
fontSize = 16,
|
|
|
|
title,
|
|
|
|
onPress,
|
|
|
|
backgroundColor,
|
|
|
|
color,
|
|
|
|
style,
|
|
|
|
styleText,
|
|
|
|
...otherProps
|
|
|
|
}: IButtonProps): React.ReactElement => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
const isPrimary = type === 'primary';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-05-20 16:37:57 +00:00
|
|
|
let textColor = isPrimary ? colors.buttonText : colors.bodyText;
|
|
|
|
if (color) {
|
|
|
|
textColor = color;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-05-20 16:37:57 +00:00
|
|
|
return (
|
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
|
|
|
disabled={disabled || loading}
|
|
|
|
style={[
|
|
|
|
styles.container,
|
|
|
|
backgroundColor ? { backgroundColor } : { backgroundColor: isPrimary ? colors.actionTintColor : colors.backgroundColor },
|
|
|
|
disabled && styles.disabled,
|
|
|
|
style
|
|
|
|
]}
|
|
|
|
accessibilityLabel={title}
|
2022-08-08 21:02:08 +00:00
|
|
|
{...otherProps}
|
|
|
|
>
|
2022-05-20 16:37:57 +00:00
|
|
|
{loading ? (
|
|
|
|
<ActivityIndicator color={textColor} />
|
|
|
|
) : (
|
|
|
|
<Text style={[styles.text, { color: textColor, fontSize }, styleText]} accessibilityLabel={title}>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
)}
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
};
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-05-20 16:37:57 +00:00
|
|
|
export default Button;
|