A versatile and customizable button component for React Native applications with multiple variants and styling options.
- 🎨 Multiple Variants - Primary, Secondary, Outline, and Transparent button styles
- 🎯 Flexible Styling - Extensive customization options for colors, borders, and dimensions
- 🔗 Icon Support - Left and right icon placement capabilities
- ♿ Accessibility Ready - Built-in accessibility features
- 🎨 Theme Integration - Seamlessly integrates with the design system
- 🎮 Touch Feedback - Configurable opacity and press animations
npm install rn-base-component
# or
yarn add rn-base-componentimport React from 'react'
import {Button} from 'rn-base-component'
export default function App() {
return <Button onPress={() => console.log('Button pressed!')}>Click me</Button>
}import {ButtonPrimary} from 'rn-base-component'
;<ButtonPrimary onPress={handlePress}>Primary Action</ButtonPrimary>import {ButtonSecondary} from 'rn-base-component'
;<ButtonSecondary onPress={handlePress}>Secondary Action</ButtonSecondary>import {ButtonOutline} from 'rn-base-component'
;<ButtonOutline onPress={handlePress}>Outline Button</ButtonOutline>import {ButtonTransparent} from 'rn-base-component'
;<ButtonTransparent onPress={handlePress}>Transparent Button</ButtonTransparent>import {Button} from 'rn-base-component'
import {Icon} from 'react-native-vector-icons/MaterialIcons'
<Button
leftIcon={<Icon name="add" size={20} color="white" />}
onPress={handlePress}>
Add Item
</Button>
<Button
rightIcon={<Icon name="arrow-forward" size={20} color="white" />}
onPress={handlePress}>
Continue
</Button>;<Button
backgroundColor="#ff6b6b"
textColor="#ffffff"
borderRadius={25}
style={styles.customButton}
textStyle={styles.customButtonText}
onPress={handlePress}>
Custom Button
</Button>
const styles = StyleSheet.create({
customButton: {
marginVertical: 10,
},
customButtonText: {
fontSize: 18,
fontWeight: 'bold',
},
})<Button outline outlineColor="#007AFF" outlineWidth={2} textColor="#007AFF" onPress={handlePress}>
Outlined Button
</Button><Button disabled disabledColor="#cccccc" onPress={handlePress}>
Disabled Button
</Button>| Prop | Type | Default | Description |
|---|---|---|---|
textColor |
string |
theme.textColor |
Color of the button text |
backgroundColor |
string |
theme.backgroundColor |
Background color of the button |
disabled |
boolean |
false |
Disable interactions for the component |
disabledColor |
string |
theme.disabledColor |
Background color when disabled |
outline |
boolean |
false |
Enable outline style |
outlineColor |
string |
theme.primaryBorder |
Color of the outline border |
outlineWidth |
number |
1 |
Width of the outline border |
borderRadius |
number |
theme.borderRadius |
Custom border radius |
textSize |
number |
theme.fontSize |
Size of the button text |
leftIcon |
ReactNode |
undefined |
Icon to display on the left side |
rightIcon |
ReactNode |
undefined |
Icon to display on the right side |
textProps |
TextProps |
undefined |
Additional props for the text component |
textStyle |
StyleProp<TextStyle> |
undefined |
Custom style for the text |
style |
StyleProp<ViewStyle> |
undefined |
Custom style for the container |
The Button component also accepts all props from React Native's TouchableOpacityProps.
- Use
backgroundColorfor the main button color - Use
textColorfor text visibility and contrast - Use
disabledColorfor accessibility in disabled states
- Button height is controlled by the theme
- Use
borderRadiusfor consistent corner rounding - Icon sizes should complement the button text size
- Always provide meaningful button text
- Use appropriate contrast ratios
- Consider disabled states for user feedback
The Button component integrates with the theme system:
// Theme configuration
const theme = {
components: {
Button: {
backgroundColor: '#007AFF',
textColor: '#FFFFFF',
disabledColor: '#CCCCCC',
borderRadius: 8,
height: 44,
},
},
};<View style={styles.buttonContainer}>
<ButtonPrimary onPress={handleSubmit}>Submit</ButtonPrimary>
<ButtonSecondary onPress={handleCancel}>Cancel</ButtonSecondary>
</View>
const styles = StyleSheet.create({
buttonContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
gap: 12,
},
})<Button rightIcon={<Icon name="arrow-forward" />} onPress={() => navigation.navigate('NextScreen')}>
Continue
</Button><Button disabled={isLoading} leftIcon={isLoading ? <ActivityIndicator /> : undefined} onPress={handleAction}>
{isLoading ? 'Loading...' : 'Submit'}
</Button>- Consistent Sizing - Use theme values for consistent button heights
- Clear Labels - Use descriptive text that clearly indicates the action
- Icon Placement - Place icons logically (e.g., arrow-right for "Next")
- Loading States - Provide visual feedback during async operations
- Accessibility - Ensure sufficient color contrast and touch targets
- Disabled States - Clearly indicate when buttons are not interactive
Button text not visible
- Check color contrast between
textColorandbackgroundColor - Ensure the theme colors are properly configured
Icons not appearing
- Verify icon components are properly imported
- Check icon props and styling
Touch events not working
- Ensure
onPressprop is provided - Check if button is disabled
- Verify no overlapping touchable components