mirror of
https://github.com/DocNR/POWR.git
synced 2025-04-23 01:01:27 +00:00
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
// components/Collapsible.tsx
|
|
import { PropsWithChildren, useState } from 'react';
|
|
import { StyleSheet, TouchableOpacity } from 'react-native';
|
|
import { ThemedText } from '@/components/ThemedText';
|
|
import { ThemedView } from '@/components/ThemedView';
|
|
import { IconSymbol } from '@/components/ui/IconSymbol';
|
|
import { useColorScheme } from '@/hooks/useColorScheme';
|
|
|
|
interface CollapsibleProps {
|
|
title: string;
|
|
}
|
|
|
|
export function Collapsible({ children, title }: PropsWithChildren<CollapsibleProps>) {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const { colors } = useColorScheme();
|
|
|
|
return (
|
|
<ThemedView>
|
|
<TouchableOpacity
|
|
style={styles.heading}
|
|
onPress={() => setIsOpen((value) => !value)}
|
|
activeOpacity={0.8}
|
|
>
|
|
<IconSymbol
|
|
name="chevron.right"
|
|
size={18}
|
|
weight="medium"
|
|
color={colors.text}
|
|
style={{ transform: [{ rotate: isOpen ? '90deg' : '0deg' }] }}
|
|
/>
|
|
<ThemedText style={styles.title}>{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,
|
|
},
|
|
title: {
|
|
fontSize: 16,
|
|
fontWeight: '600',
|
|
},
|
|
}); |