eletrotupi / tcc/ frontend/components/ui/Cards.tsx9e81281bc996022abab0d2183e9466b5b3553b51
2.4 KB | 108 lines Raw
1
import React from 'react';
2
import {
3
  View,
4
  StyleSheet,
5
  Pressable,
6
  ViewStyle,
7
  type StyleProp,
8
} from 'react-native';
9

10
import { Colors, Spacing, BorderRadius, Shadows } from '@/constants/theme';
11
import { useThemeColor } from '@/hooks/use-theme-color';
12
import { Text } from '@/components/ui/Text'
13
import { Ionicons } from '@expo/vector-icons';
14

15
interface CardProps {
16
  children: React.ReactNode;
17
  onPress?: () => void;
18
  variant?: 'default' | 'highlighted';
19
  style?: StyleProp<ViewStyle>;
20
  testID?: string;
21
}
22

23
export const Card: React.FC<CardProps> = ({
24
  children,
25
  onPress,
26
  variant = 'default',
27
  style,
28
  testID,
29
}) => {
30
  const isHighlighted = variant === 'highlighted';
31

32
  const surfaceColor = useThemeColor({}, 'surface');
33
  const cardBorderColor = useThemeColor({}, 'cardBorder');
34
  const accentBlueColor = useThemeColor({}, 'accentBlue');
35

36
  const styles = StyleSheet.create({
37
    card: {
38
      backgroundColor: surfaceColor,
39
      borderRadius: BorderRadius.lg,
40
      borderWidth: 1,
41
      borderColor: cardBorderColor,
42
      padding: Spacing.containerPadding,
43
      marginBottom: Spacing.cardGap,
44
      ...(isHighlighted && {
45
        backgroundColor: accentBlueColor,
46
        borderColor: 'transparent',
47
      }),
48
      ...Shadows.sm,
49
    },
50
  });
51

52
  return (
53
    <Pressable
54
      onPress={onPress}
55
      disabled={!onPress}
56
      testID={testID}
57
      style={({ pressed }) => [
58
        styles.card,
59
        pressed && onPress && {
60
          opacity: 0.8,
61
        },
62
        style,
63
      ]}
64
    >
65
      {children}
66
    </Pressable>
67
  );
68
};
69

70
interface SubtleInfoCardProps {
71
  text: string;
72
  style?: StyleProp<ViewStyle>;
73
};
74

75
export const SubtleInfoCard: React.FC<SubtleInfoCardProps> = ({
76
  text,
77
  style
78
}) => {
79
  const accentBlueColor = useThemeColor({}, 'accentBlue');
80

81
  const styles = StyleSheet.create({
82
    card: {
83
      backgroundColor: accentBlueColor,
84
      borderRadius: BorderRadius.lg,
85
      padding: Spacing.cardGap,
86
      marginBottom: Spacing.cardGap,
87
      flex: 1,
88
      flexDirection: 'row',
89
      alignItems: 'flex-start'
90
    },
91
    text: {
92
      fontSize: 12,
93
      lineHeight: 18,
94
      color: Colors.light.textSecondary,
95
      marginLeft: 10
96
    },
97
  });
98

99
  return (
100
    <View style={[styles.card, style]}>
101
      <Ionicons name="information-circle-outline" size={20} color="gray" />
102

103
      <Text style={styles.text}>
104
        {text.replace(/\s+/g, ' ').trim()}
105
      </Text>
106
    </View>
107
  )
108
}