eletrotupi / tcc/ frontend/components/ui/collapsible.tsx98f51d926694a10e1a4625987f1b32e03ec683da
1.3 KB | 45 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
import { useColorScheme } from '@/hooks/use-color-scheme';
9

10
export function Collapsible({ children, title }: PropsWithChildren & { title: string }) {
11
  const [isOpen, setIsOpen] = useState(false);
12
  const theme = useColorScheme() ?? 'light';
13

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

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

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