eletrotupi / tcc/ frontend/components/ui/Sections.tsx87bfdbe89f107ee4cfd523c6b559754da54cdd4d
2.2 KB | 95 lines Raw
1
import React from 'react';
2
import {
3
  View,
4
  StyleSheet,
5
  Pressable,
6
  ViewStyle,
7
} from 'react-native';
8
import { ThemedText } from '@/components/misc/themed-text'
9

10
import { Colors, Typography, Spacing, BorderRadius } from '@/constants/theme';
11
import { useThemeColor } from '@/hooks/use-theme-color';
12

13
interface SectionProps {
14
  children: React.ReactNode;
15
  style?: ViewStyle;
16
}
17

18
export const Section: React.FC<SectionProps> = ({ children, style }) => {
19
  const styles = StyleSheet.create({
20
    section: {
21
      marginBottom: Spacing.sectionGap,
22
    },
23
  });
24
  return <View style={[styles.section, style]}>{children}</View>;
25
};
26

27
interface SectionHeaderProps {
28
  title: string;
29
  actionLabel?: string;
30
  onActionPress?: () => void;
31
  style?: ViewStyle;
32
}
33

34
// XXX: A Section must either have a label as a pill/informative thing
35
// or it should be a link
36
export const SectionHeader: React.FC<SectionHeaderProps> = ({
37
  title,
38
  info,
39
  actionLabel,
40
  onActionPress,
41
  style,
42
}) => {
43
  const textColor = useThemeColor({}, 'text');
44
  const tintColor = useThemeColor({}, 'tint');
45

46
  const styles = StyleSheet.create({
47
    headerContainer: {
48
      flexDirection: 'row',
49
      justifyContent: 'space-between',
50
      alignItems: 'center',
51
      marginBottom: (Spacing.cardGap * 2),
52
    },
53
    title: {
54
      fontSize: Typography.headlineMd.fontSize,
55
      fontWeight: Typography.headlineMd.fontWeight,
56
      color: textColor,
57
    },
58
    actionButton: {
59
      padding: 4,
60
    },
61
    actionText: {
62
      fontSize: Typography.bodyMd.fontSize,
63
      fontWeight: '600',
64
      color: tintColor,
65
    },
66
  });
67

68
  // TODO: Rework these when we finally have chips/badges
69
  return (
70
    <View style={[styles.headerContainer, style]}>
71
      <ThemedText style={styles.title}>
72
        {title}
73
      </ThemedText>
74

75
      {info && !actionLabel && (
76
        <ThemedText>
77
          {info}
78
        </ThemedText>
79
      )}
80

81
      {actionLabel && !info && onActionPress && (
82
        <Pressable
83
          style={styles.actionButton}
84
          onPress={onActionPress}
85
          hitSlop={8}
86
        >
87
          <ThemedText style={styles.actionText}>
88
            {actionLabel}
89
          </ThemedText>
90
        </Pressable>
91
      )}
92
    </View>
93
  );
94
};
95