Button
A versatile and customizable button component for Expo React Native applications.
Button
The Button component is a versatile and customizable component that can be used for various interactions in your React Native application. It supports different variants, sizes, loading states, and can be used for navigation with the href
prop.
Features
- Multiple Variants: Choose from primary, secondary, outline, and ghost variants
- Customizable Sizes: Small, medium, and large size options
- Loading State: Built-in loading indicator
- Border Radius Customization: Various rounded styles from none to full
- Navigation Support: Can be used as a link with the href prop
- Icon Support: Add icons at the start and/or end of the button
- Accessibility: Properly handles disabled states
- Dark Mode Support: Automatically handles light/dark mode styles
Import
Props
Core Props
Prop | Type | Default | Description |
---|---|---|---|
title | string | — | The text displayed inside the button |
onPress | () => void | — | Function called when the button is pressed |
disabled | boolean | false | Whether the button is disabled |
loading | boolean | false | Displays a loading spinner instead of content |
href | string | — | If provided, button acts as a navigation link |
Styling Props
Prop | Type | Default | Description |
---|---|---|---|
variant | 'primary' | 'secondary' | 'outline' | 'ghost' | 'primary' | The visual style of the button |
size | 'small' | 'medium' | 'large' | 'medium' | The size of the button |
rounded | 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'lg' | The border radius of the button |
className | string | '' | Additional Tailwind classes for the button container |
textClassName | string | '' | Additional Tailwind classes for the button text |
Icon Props
Prop | Type | Default | Description |
---|---|---|---|
iconStart | IconName | — | Icon displayed before the text |
iconEnd | IconName | — | Icon displayed after the text |
iconSize | number | Based on button size | Custom size for the icons |
iconColor | string | Based on variant | Custom color for the icons |
iconClassName | string | '' | Additional Tailwind classes for the icons |
Usage Examples
Basic Button
Different Variants
Sizes
Loading State
With Icons
Navigation Button
Custom Styling
Best Practices
Consistent Variant Usage
Use the same button variant for similar actions across your application:
- Use
primary
for main actions like "Submit", "Save", or "Continue" - Use
secondary
for alternative actions like "Cancel" or "Skip" - Use
outline
orghost
for less important actions or in dense UI areas
Loading States
Always provide feedback to users during asynchronous operations:
Icon Usage
Use icons consistently to enhance clarity:
- Use recognizable icons that match your button's action
- Maintain consistent positioning (start vs end) for similar buttons
- Consider using
iconStart
for back/previous navigation andiconEnd
for forward/next navigation
Accessibility
The Button component includes accessibility features:
- Properly handles disabled states
- Provides visual feedback with loading indicators
- Uses appropriate touch targets for different sizes
Implementation Details
Under the hood, the Button component uses React Native's TouchableOpacity
for press interactions. When the href
prop is provided, it uses Expo Router's navigation system.
The button's styles are defined using TailwindCSS for React Native, which automatically handles light and dark mode.
Notes
- The
href
prop uses Expo Router's navigation system - When both
loading
anddisabled
props are true, the button will be disabled - Default icon sizes are determined by the button size (small: 16, medium: 18, large: 20)
- Default icon colors match the text color based on the button variant