BlueWallet/components/SquareButton.tsx

49 lines
1.2 KiB
TypeScript
Raw Normal View History

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