diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-08-28 15:53:21 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-08-28 15:53:21 +0200 |
commit | 83643a78b73dee5610be6ad9837fb72e9b944cb7 (patch) | |
tree | 1eca6bad452656f78879c829181362f3b586d697 /components/Collapsible.tsx |
Initial commit
Generated by create-expo-app 3.0.0.
Diffstat (limited to 'components/Collapsible.tsx')
-rw-r--r-- | components/Collapsible.tsx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/components/Collapsible.tsx b/components/Collapsible.tsx new file mode 100644 index 0000000..c326473 --- /dev/null +++ b/components/Collapsible.tsx @@ -0,0 +1,41 @@ +import Ionicons from '@expo/vector-icons/Ionicons'; +import { PropsWithChildren, useState } from 'react'; +import { StyleSheet, TouchableOpacity, useColorScheme } from 'react-native'; + +import { ThemedText } from '@/components/ThemedText'; +import { ThemedView } from '@/components/ThemedView'; +import { Colors } from '@/constants/Colors'; + +export function Collapsible({ children, title }: PropsWithChildren & { title: string }) { + const [isOpen, setIsOpen] = useState(false); + const theme = useColorScheme() ?? 'light'; + + return ( + <ThemedView> + <TouchableOpacity + style={styles.heading} + onPress={() => setIsOpen((value) => !value)} + activeOpacity={0.8}> + <Ionicons + name={isOpen ? 'chevron-down' : 'chevron-forward-outline'} + size={18} + color={theme === 'light' ? Colors.light.icon : Colors.dark.icon} + /> + <ThemedText type="defaultSemiBold">{title}</ThemedText> + </TouchableOpacity> + {isOpen && <ThemedView style={styles.content}>{children}</ThemedView>} + </ThemedView> + ); +} + +const styles = StyleSheet.create({ + heading: { + flexDirection: 'row', + alignItems: 'center', + gap: 6, + }, + content: { + marginTop: 6, + marginLeft: 24, + }, +}); |