BlueWallet/components/SecondButton.tsx

79 lines
1.9 KiB
TypeScript
Raw Normal View History

import React, { forwardRef } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
2024-06-12 18:46:44 +02:00
import { Icon } from '@rneui/themed';
2024-05-20 11:54:13 +02:00
import { useTheme } from './themes';
type IconProps = {
name: string;
type: string;
color: string;
};
type SecondButtonProps = {
backgroundColor?: string;
disabled?: boolean;
icon?: IconProps;
title?: string;
2024-03-22 01:54:40 +01:00
onPress?: () => void;
};
export const SecondButton = forwardRef<TouchableOpacity, SecondButtonProps>((props, ref) => {
const { colors } = useTheme();
let backgroundColor = props.backgroundColor ? props.backgroundColor : colors.buttonGrayBackgroundColor;
let fontColor = colors.secondButtonTextColor;
if (props.disabled === true) {
backgroundColor = colors.buttonDisabledBackgroundColor;
fontColor = colors.buttonDisabledTextColor;
}
2024-03-22 01:54:40 +01:00
const buttonView = (
<View style={styles.view}>
{props.icon && <Icon name={props.icon.name} type={props.icon.type} color={props.icon.color} />}
{props.title && <Text style={[styles.text, { color: fontColor }]}>{props.title}</Text>}
</View>
);
return props.onPress ? (
<TouchableOpacity
disabled={props.disabled}
accessibilityRole="button"
style={[styles.button, { backgroundColor }]}
{...props}
ref={ref}
>
2024-03-22 01:54:40 +01:00
{buttonView}
</TouchableOpacity>
2024-03-22 01:54:40 +01:00
) : (
<View style={[styles.button, { backgroundColor }]}>{buttonView}</View>
);
});
const styles = StyleSheet.create({
button: {
minHeight: 45,
height: 48,
maxHeight: 48,
borderRadius: 7,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 16,
flexGrow: 1,
},
content: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
text: {
marginHorizontal: 8,
fontSize: 16,
fontWeight: '600',
},
view: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
});