62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
/*
|
|
* File: Button.tsx
|
|
* Description: A reusable button component with optional loading state.
|
|
* Design & Developed by Tech4Biz Solutions
|
|
* Copyright (c) Spurrin Innovations. All rights reserved.
|
|
*/
|
|
|
|
import React from 'react';
|
|
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native'; // Import ActivityIndicator
|
|
import { Colors, Spacing, Typography, BorderRadius } from '../../theme';
|
|
|
|
interface ButtonProps {
|
|
title: string;
|
|
onPress: () => void;
|
|
style?: object;
|
|
textStyle?: object;
|
|
disabled?: boolean;
|
|
loading?: boolean; // Add loading prop
|
|
}
|
|
|
|
const Button: React.FC<ButtonProps> = ({
|
|
title,
|
|
onPress,
|
|
style,
|
|
textStyle,
|
|
disabled,
|
|
loading, // Destructure loading prop
|
|
}) => {
|
|
return (
|
|
<TouchableOpacity
|
|
style={[styles.button, style, (disabled || loading) && styles.disabled]}
|
|
onPress={onPress}
|
|
disabled={disabled || loading}>
|
|
{loading ? (
|
|
<ActivityIndicator color={Colors.background} />
|
|
) : (
|
|
<Text style={[styles.text, textStyle]}>{title}</Text>
|
|
)}
|
|
</TouchableOpacity>
|
|
);
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
button: {
|
|
backgroundColor: Colors.primary,
|
|
paddingVertical: Spacing.lg,
|
|
paddingHorizontal: Spacing.lg,
|
|
borderRadius: BorderRadius.xl,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
},
|
|
text: {
|
|
color: Colors.background,
|
|
fontSize: Typography.fontSize.sm,
|
|
fontFamily: Typography.fontFamily.bold,
|
|
},
|
|
disabled: {
|
|
backgroundColor: Colors.primary,
|
|
},
|
|
});
|
|
|
|
export default Button;
|