BlueWallet/components/SquareButton.tsx

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-02-29 00:20:29 +01:00
import React, { forwardRef } from 'react';
import { TouchableOpacity, View, Text, StyleProp, ViewStyle, StyleSheet } from 'react-native';
import { useTheme } from './themes';
interface SquareButtonProps {
title: string;
2024-03-22 01:54:40 +01:00
onPress?: () => void;
style?: StyleProp<ViewStyle>;
2024-02-29 00:20:29 +01:00
testID?: string;
}
export const SquareButton = forwardRef<TouchableOpacity, SquareButtonProps>((props, ref) => {
const { title, onPress, style, testID } = props;
const { colors } = useTheme();
const hookStyles = StyleSheet.create({
text: {
color: colors.buttonTextColor,
},
});
2024-03-22 01:54:40 +01:00
const buttonView = (
<View style={styles.contentContainer}>
<Text style={[styles.text, hookStyles.text]}>{title}</Text>
</View>
);
return onPress ? (
2024-02-29 00:20:29 +01:00
<TouchableOpacity ref={ref} style={style} onPress={onPress} testID={testID} accessibilityRole="button">
2024-03-22 01:54:40 +01:00
{buttonView}
2024-02-29 00:20:29 +01:00
</TouchableOpacity>
2024-03-22 01:54:40 +01:00
) : (
<View style={style}>{buttonView}</View>
2024-02-29 00:20:29 +01:00
);
});
const styles = StyleSheet.create({
contentContainer: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
text: {
marginHorizontal: 8,
fontSize: 16,
},
});