eletrotupi / tcc/ frontend/components/ui/Cards.tsx98f51d926694a10e1a4625987f1b32e03ec683da
2.3 KB | 107 lines Raw
1
import React from 'react';
2
import {
3
  View,
4
  StyleSheet,
5
  Pressable,
6
  ViewStyle,
7
} from 'react-native';
8

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

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

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

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

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

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

69
interface SubtleInfoCardProps {
70
  text: string;
71
  style?: ViewStyle;
72
};
73

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

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

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

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