Button Component
Primary action component with multiple variants, sizes, and states
Button Component
Overview
The Button component is a foundational interactive element that triggers actions when tapped. It supports multiple visual variants, sizes, loading states, and full accessibility features.
GitHub Source: View the complete implementation in our repository.
Basic Usage
Variants
Our Button component supports multiple visual variants for different use cases:
Primary buttons are used for the main action on a screen. They use the primary brand color and should be used sparingly - typically one per screen or section.
Sizes
Buttons come in three sizes to fit different contexts:
States
Loading State
Show a loading indicator when performing async operations:
Disabled State
Disable buttons when actions aren't available:
Full Example
Here's a complete example showing all features:
Props API
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | required | Button label text |
variant | 'primary' | 'secondary' | 'ghost' | 'danger' | 'primary' | Visual style variant |
size | 'small' | 'medium' | 'large' | 'medium' | Button size |
loading | boolean | false | Shows loading indicator |
disabled | boolean | false | Disables interaction |
onPress | () => void | - | Press event handler |
style | ViewStyle | - | Custom style overrides |
testID | string | - | Test identifier |
Accessibility
The Button component includes comprehensive accessibility features:
- Role: Automatically sets
accessibilityRole="button" - State: Communicates disabled and loading states
- Label: Uses button text as accessibility label
- Feedback: Provides haptic feedback on press (when enabled)
Styling
Buttons use design tokens for consistent styling:
Common Patterns
Button Groups
Group related actions together:
Confirmation Dialogs
Use with modals for confirmations:
Testing
Example test cases for Button component:
Related Components
- IconButton - Button with icon
- Link - Text-based navigation
- Pressable - Custom touchable areas
Migration Guide
If migrating from a previous Button implementation:
Need help? Check the Foundation Components Guide or ask in #ui-development channel.