BlueWallet/components/StyledButton.tsx

87 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-04-09 22:47:13 +02:00
import React, { FC } from 'react';
2021-09-09 13:00:11 +02:00
import { TouchableOpacity, View, Text, StyleSheet } from 'react-native';
2023-10-24 03:28:44 +02:00
import { useTheme } from './themes';
2021-09-09 13:00:11 +02:00
2024-04-09 22:47:13 +02:00
export const StyledButtonType: Record<string, string> = { default: 'default', destroy: 'destroy', grey: 'grey' };
interface StyledButtonProps {
onPress: () => void;
text: string;
disabled?: boolean;
buttonStyle?: keyof typeof StyledButtonType;
}
const StyledButton: FC<StyledButtonProps> = ({ onPress, text, disabled = false, buttonStyle = StyledButtonType.default }) => {
2021-09-09 13:00:11 +02:00
const { colors } = useTheme();
const stylesHook = StyleSheet.create({
buttonGrey: {
backgroundColor: colors.lightButton,
},
textGray: {
color: colors.buttonTextColor,
},
2024-04-09 22:47:13 +02:00
container: {
opacity: disabled ? 0.5 : 1.0,
},
2021-09-09 13:00:11 +02:00
});
const textStyles = () => {
2023-11-15 09:40:22 +01:00
if (buttonStyle === StyledButtonType.grey) {
2021-09-09 13:00:11 +02:00
return stylesHook.textGray;
2023-11-15 09:40:22 +01:00
} else if (buttonStyle === StyledButtonType.destroy) {
2021-09-09 13:00:11 +02:00
return styles.textDestroy;
} else {
return styles.textDefault;
}
};
const buttonStyles = () => {
2023-11-15 09:40:22 +01:00
if (buttonStyle === StyledButtonType.grey) {
2021-09-09 13:00:11 +02:00
return stylesHook.buttonGrey;
2023-11-15 09:40:22 +01:00
} else if (buttonStyle === StyledButtonType.destroy) {
2021-09-09 13:00:11 +02:00
return styles.buttonDestroy;
} else {
return styles.buttonDefault;
}
};
return (
2024-04-09 22:47:13 +02:00
<TouchableOpacity accessibilityRole="button" onPress={onPress} disabled={disabled} style={stylesHook.container}>
2021-09-09 13:00:11 +02:00
<View style={[styles.buttonContainer, buttonStyles()]}>
<Text style={[styles.text, textStyles()]}>{text}</Text>
</View>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
buttonContainer: {
borderRadius: 9,
minHeight: 49,
paddingHorizontal: 8,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
alignSelf: 'auto',
flexGrow: 1,
marginHorizontal: 4,
},
buttonDefault: {
backgroundColor: '#EBF2FB',
},
buttonDestroy: {
backgroundColor: '#FFF5F5',
},
text: {
fontWeight: '600',
fontSize: 15,
},
textDefault: {
color: '#1961B9',
},
textDestroy: {
color: '#D0021B',
},
});
2023-11-15 09:40:22 +01:00
export default StyledButton;