Introduction
Components
- Accordion
- Action Sheet
- Alert
- Audio Player
- Audio Recorder
- Audio Waveform
- Avatar
- Badge
- BottomSheet
- Button
- Camera
- Camera Preview
- Card
- Carousel
- Checkbox
- Collapsible
- Color Picker
- Combobox
- Date Picker
- File Picker
- Gallery
- Hello Wave
- Icon
- Image
- Input
- Input OTP
- Link
- MediaPicker
- Mode Toggle
- Onboarding
- ParallaxScrollView
- Picker
- Popover
- Progress
- Radio
- ScrollView
- SearchBar
- Separator
- Share
- Sheet
- Skeleton
- Spinner
- Switch
- Table
- Tabs
- Text
- Toast
- Toggle
- Video
- View
Charts
import { Collapsible } from '@/components/ui/collapsible';
import { Text } from '@/components/ui/text';
import React from 'react';
export function CollapsibleDemo() {
return (
<Collapsible title='What is React Native?'>
<Text variant='body'>
React Native is an open-source UI software framework created by Meta. It
is used to develop applications for Android, iOS, macOS, tvOS, Web,
Windows and UWP by enabling developers to use React's framework along
with native platform capabilities.
</Text>
</Collapsible>
);
}
Installation
pnpm dlx bna-ui add collapsible
Usage
import { Collapsible } from '@/components/ui/collapsible';
<Collapsible title='What is React Native?'>
<Text>
React Native is an open-source UI software framework created by Meta. It is
used to develop applications for multiple platforms.
</Text>
</Collapsible>
Examples
Default
import { Collapsible } from '@/components/ui/collapsible';
import { Text } from '@/components/ui/text';
import React from 'react';
export function CollapsibleDemo() {
return (
<Collapsible title='What is React Native?'>
<Text variant='body'>
React Native is an open-source UI software framework created by Meta. It
is used to develop applications for Android, iOS, macOS, tvOS, Web,
Windows and UWP by enabling developers to use React's framework along
with native platform capabilities.
</Text>
</Collapsible>
);
}
Multiple Collapsibles
import { Collapsible } from '@/components/ui/collapsible';
import { Text } from '@/components/ui/text';
import { View } from '@/components/ui/view';
import React from 'react';
export function CollapsibleMultiple() {
return (
<View style={{ gap: 16 }}>
<Collapsible title='Getting Started'>
<Text variant='body'>
To get started with React Native, you'll need to set up your
development environment. This includes installing Node.js, React
Native CLI, and either Android Studio or Xcode.
</Text>
</Collapsible>
<Collapsible title='Components'>
<Text variant='body'>
React Native provides many built-in components like View, Text,
ScrollView, TextInput, and more. You can also create custom components
to build your app's interface.
</Text>
</Collapsible>
<Collapsible title='Navigation'>
<Text variant='body'>
For navigation between screens, React Navigation is the most popular
solution. It provides stack, tab, and drawer navigation patterns that
work seamlessly with React Native.
</Text>
</Collapsible>
</View>
);
}
Nested Collapsibles
import { Collapsible } from '@/components/ui/collapsible';
import { Text } from '@/components/ui/text';
import { View } from '@/components/ui/view';
import React from 'react';
export function CollapsibleNested() {
return (
<Collapsible title='Mobile Development'>
<Text variant='body' style={{ marginBottom: 16 }}>
Mobile development encompasses various platforms and technologies:
</Text>
<View style={{ gap: 12 }}>
<Collapsible title='iOS Development'>
<Text variant='body'>
iOS development primarily uses Swift or Objective-C with Xcode as
the main development environment. Apps are distributed through the
Apple App Store.
</Text>
</Collapsible>
<Collapsible title='Android Development'>
<Text variant='body'>
Android development can be done with Java, Kotlin, or cross-platform
frameworks. Android Studio is the official IDE, and apps are
distributed through Google Play Store.
</Text>
</Collapsible>
<Collapsible title='Cross-Platform'>
<Text variant='body'>
Cross-platform frameworks like React Native, Flutter, and Xamarin
allow you to write code once and deploy to multiple platforms.
</Text>
</Collapsible>
</View>
</Collapsible>
);
}
With Interactive Content
import { Checkbox } from '@/components/ui/checkbox';
import { Collapsible } from '@/components/ui/collapsible';
import { Text } from '@/components/ui/text';
import { View } from '@/components/ui/view';
import React, { useState } from 'react';
export function CollapsibleWithContent() {
const [preferences, setPreferences] = useState({
darkMode: false,
notifications: true,
analytics: false,
});
return (
<View style={{ gap: 16 }}>
<Collapsible title='App Settings'>
<View style={{ gap: 12 }}>
<Checkbox
checked={preferences.darkMode}
onCheckedChange={(checked) =>
setPreferences((prev) => ({ ...prev, darkMode: checked }))
}
label='Enable dark mode'
/>
<Checkbox
checked={preferences.notifications}
onCheckedChange={(checked) =>
setPreferences((prev) => ({ ...prev, notifications: checked }))
}
label='Push notifications'
/>
<Checkbox
checked={preferences.analytics}
onCheckedChange={(checked) =>
setPreferences((prev) => ({ ...prev, analytics: checked }))
}
label='Analytics tracking'
/>
</View>
</Collapsible>
<Collapsible title='Account Information'>
<View style={{ gap: 8 }}>
<Text variant='body'>Email: user@example.com</Text>
<Text variant='body'>Member since: January 2024</Text>
<Text variant='body'>Subscription: Premium</Text>
</View>
</Collapsible>
</View>
);
}
FAQ Style
import { Collapsible } from '@/components/ui/collapsible';
import { Text } from '@/components/ui/text';
import { View } from '@/components/ui/view';
import React from 'react';
export function CollapsibleFAQ() {
const faqs = [
{
question: 'How do I reset my password?',
answer:
"You can reset your password by clicking on the 'Forgot Password' link on the login page. Enter your email address and we'll send you instructions to reset your password.",
},
{
question: 'Can I cancel my subscription anytime?',
answer:
'Yes, you can cancel your subscription at any time from your account settings. Your subscription will remain active until the end of your current billing period.',
},
{
question: 'Is my data secure?',
answer:
'We take data security seriously. All data is encrypted in transit and at rest. We follow industry best practices and comply with relevant data protection regulations.',
},
{
question: 'How do I contact support?',
answer:
'You can reach our support team through the in-app chat, email us at support@example.com, or call our toll-free number during business hours.',
},
];
return (
<View style={{ gap: 16 }}>
<Text variant='subtitle' style={{ marginBottom: 8 }}>
Frequently Asked Questions
</Text>
<View style={{ gap: 12 }}>
{faqs.map((faq, index) => (
<Collapsible key={index} title={faq.question}>
<Text variant='body'>{faq.answer}</Text>
</Collapsible>
))}
</View>
</View>
);
}
API Reference
Collapsible
An expandable/collapsible container component that shows or hides its content.
Prop | Type | Default | Description |
---|---|---|---|
title | string | - | The title text displayed in the header. |
children | ReactNode | - | The content to show/hide when toggled. |
Component Structure
The Collapsible component consists of:
- Header: A touchable area containing the title and chevron icon
- Content: The collapsible content that shows/hides based on state
- Icon: A chevron that rotates to indicate open/closed state
Behavior
- Initially collapsed by default
- Clicking the header toggles the collapsed/expanded state
- Smooth rotation animation for the chevron icon
- Content appears with proper indentation when expanded
- Each collapsible manages its own state independently
Accessibility
The Collapsible component is built with accessibility in mind:
- Uses TouchableOpacity for proper touch handling
- Visual indicator (chevron) shows current state
- Proper spacing and indentation for content hierarchy
- Supports nested content and interactive elements
- Clear visual feedback with activeOpacity on touch
Styling
The component uses:
- Flexible layout with proper spacing
- Icon rotation animation for visual feedback
- Consistent indentation for nested content
- Theme-aware text styling through the Text component
- Responsive touch areas for better usability
Use Cases
Perfect for:
- FAQ sections
- Settings panels
- Navigation menus
- Content organization
- Progressive disclosure
- Help documentation
- Feature explanations