Section
A structured container component for organizing content with optional title, subtitle, and icon.
Section
The Section component provides a structured container for organizing content with optional title, subtitle, icon, and footer elements. It's designed to create consistent section layouts throughout your application.
Features
- Title & Subtitle: Optional heading elements with customizable styling
- Icon Support: Optional icon to display next to the title
- Custom Header: Support for custom header content in place of default title/subtitle
- Footer Support: Optional footer content
- Customizable Padding: Control vertical spacing with predefined sizes
- Styling Control: Accepts additional Tailwind classes and style objects
- Dark Mode Support: Automatically adapts to light/dark mode
Import
Props
Prop | Type | Default | Description |
---|---|---|---|
title | string | — | Main title text |
subtitle | string | — | Secondary text displayed below title |
icon | IconName | — | Icon displayed next to the title |
header | React.ReactNode | — | Custom header content (replaces title/subtitle) |
footer | React.ReactNode | — | Content displayed at the bottom of the section |
padding | 'none' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | 'none' | Vertical padding size |
titleSize | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | 'xl' | Font size of the title |
className | string | '' | Additional Tailwind classes |
style | ViewStyle | — | Additional style object |
children | React.ReactNode | — | Content to display in the section |
Usage Examples
Basic Section with Title
Section with Title and Subtitle
Section with Icon
Section with Custom Header
Section with Footer
Profile Screen Example
Settings Screen Example
Best Practices
Consistent Section Structure
Use Sections consistently to create a cohesive user interface:
Choose Appropriate Padding
Select the appropriate padding size based on content density:
Use Icons for Visual Consistency
Add icons to sections for better visual hierarchy and scannability:
Implementation Details
The Section component uses React Native's View
component to create a structured container with optional header and footer elements. The header can be either a combination of title, subtitle, and icon, or a completely custom header provided through the header
prop.
The padding is applied vertically (top and bottom) and is controlled through the padding
prop, which maps to predefined Tailwind CSS classes. The title size is similarly mapped to Tailwind text size classes through the titleSize
prop.
The component uses the ThemedText
component for text elements, ensuring proper appearance in both light and dark modes.
Notes
- The Section component is typically used to organize content in scrollable screens
- For simple sections with just a title, you might not need padding, as the content itself can define appropriate spacing
- When using custom headers, you have complete control over the header's layout and content
- The footer is positioned at the bottom of the section and is typically used for action buttons
- All text elements automatically adapt to dark mode through the
ThemedText
component