eletrotupi / tcc/ frontend/components/ui/collapsible.tsx7fee969bd7c3a184aabf448e27667c76b4e49617
1.2 KB | 42 lines Raw
1
import { PropsWithChildren, useState } from 'react';
2
import { StyleSheet, TouchableOpacity } from 'react-native';
3

4
import { Text } from '@/components/ui/Text';
5
import { ThemedView } from '@/components/misc/themed-view';
6
import { IconSymbol } from '@/components/ui/icon-symbol';
7
import { Colors } from '@/constants/theme';
8

9
export function Collapsible({ children, title }: PropsWithChildren & { title: string }) {
10
  const [isOpen, setIsOpen] = useState(false);
11

12
  return (
13
    <ThemedView>
14
      <TouchableOpacity
15
        style={styles.heading}
16
        onPress={() => setIsOpen((value) => !value)}
17
        activeOpacity={0.8}>
18
        <IconSymbol
19
          name="chevron.right"
20
          size={18}
21
          color={Colors.light.icon}
22
          style={{ transform: [{ rotate: isOpen ? '90deg' : '0deg' }] }}
23
        />
24

25
        <Text style={{ fontWeight: '600' }}>{title}</Text>
26
      </TouchableOpacity>
27
      {isOpen && <ThemedView style={styles.content}>{children}</ThemedView>}
28
    </ThemedView>
29
  );
30
}
31

32
const styles = StyleSheet.create({
33
  heading: {
34
    flexDirection: 'row',
35
    alignItems: 'center',
36
    gap: 6,
37
  },
38
  content: {
39
    marginTop: 6,
40
    marginLeft: 24,
41
  },
42
});