|
| 1 | +import React from 'react'; |
| 2 | +import { |
| 3 | + TouchableOpacity, |
| 4 | + Text, |
| 5 | + StyleSheet, |
| 6 | + type TouchableOpacityProps, |
| 7 | +} from 'react-native'; |
| 8 | +import { theme } from '../constants/theme'; |
| 9 | + |
| 10 | +export type ButtonVariant = |
| 11 | + | 'primary' |
| 12 | + | 'secondary' |
| 13 | + | 'success' |
| 14 | + | 'warning' |
| 15 | + | 'error'; |
| 16 | + |
| 17 | +interface ButtonProps extends TouchableOpacityProps { |
| 18 | + title: string; |
| 19 | + variant?: ButtonVariant; |
| 20 | + fullWidth?: boolean; |
| 21 | + loading?: boolean; |
| 22 | +} |
| 23 | + |
| 24 | +export const Button: React.FC<ButtonProps> = ({ |
| 25 | + title, |
| 26 | + variant = 'primary', |
| 27 | + fullWidth = true, |
| 28 | + loading = false, |
| 29 | + disabled, |
| 30 | + style, |
| 31 | + ...props |
| 32 | +}) => { |
| 33 | + const buttonStyle = [ |
| 34 | + styles.button, |
| 35 | + styles[variant], |
| 36 | + fullWidth && styles.fullWidth, |
| 37 | + (disabled || loading) && styles.disabled, |
| 38 | + style, |
| 39 | + ]; |
| 40 | + |
| 41 | + const textStyle = [styles.text, (disabled || loading) && styles.disabledText]; |
| 42 | + |
| 43 | + return ( |
| 44 | + <TouchableOpacity |
| 45 | + style={buttonStyle} |
| 46 | + disabled={disabled || loading} |
| 47 | + activeOpacity={0.8} |
| 48 | + {...props} |
| 49 | + > |
| 50 | + <Text style={textStyle}>{loading ? 'Processando...' : title}</Text> |
| 51 | + </TouchableOpacity> |
| 52 | + ); |
| 53 | +}; |
| 54 | + |
| 55 | +const styles = StyleSheet.create({ |
| 56 | + button: { |
| 57 | + paddingVertical: theme.spacing.md, |
| 58 | + paddingHorizontal: theme.spacing.lg, |
| 59 | + borderRadius: theme.borderRadius.md, |
| 60 | + alignItems: 'center', |
| 61 | + justifyContent: 'center', |
| 62 | + marginBottom: theme.spacing.sm, |
| 63 | + ...theme.shadows.small, |
| 64 | + }, |
| 65 | + fullWidth: { |
| 66 | + width: '100%', |
| 67 | + }, |
| 68 | + text: { |
| 69 | + ...theme.typography.body, |
| 70 | + fontWeight: '600', |
| 71 | + color: theme.colors.textPrimary, |
| 72 | + }, |
| 73 | + disabled: { |
| 74 | + opacity: 0.6, |
| 75 | + }, |
| 76 | + disabledText: { |
| 77 | + color: theme.colors.textSecondary, |
| 78 | + }, |
| 79 | + |
| 80 | + // Variants |
| 81 | + primary: { |
| 82 | + backgroundColor: theme.colors.primary, |
| 83 | + }, |
| 84 | + secondary: { |
| 85 | + backgroundColor: theme.colors.secondary, |
| 86 | + }, |
| 87 | + success: { |
| 88 | + backgroundColor: theme.colors.success, |
| 89 | + }, |
| 90 | + warning: { |
| 91 | + backgroundColor: theme.colors.warning, |
| 92 | + }, |
| 93 | + error: { |
| 94 | + backgroundColor: theme.colors.error, |
| 95 | + }, |
| 96 | +}); |
0 commit comments