A styled text component for React Native that provides consistent typography and theming capabilities with additional text styling variants.
- 🎨 Theme Integration - Seamlessly integrates with the design system
- 📝 Multiple Variants - Regular, Bold, and Italic text styles
- 🎯 Customizable - Override colors, fonts, and sizes easily
- ♿ Accessible - Inherits all React Native Text accessibility features
- 🔧 TypeScript Ready - Full type safety and IntelliSense support
- 🎪 Styled Components - Built with styled-components for optimal performance
npm install rn-base-component
# or
yarn add rn-base-componentimport React from 'react'
import {Text} from 'rn-base-component'
export default function App() {
return <Text>Hello, World!</Text>
}import {Text} from 'rn-base-component'
;<Text>This is regular text</Text>import {TextBold} from 'rn-base-component'
;<TextBold>This is bold text</TextBold>import {TextItalic} from 'rn-base-component'
;<TextItalic>This is italic text</TextItalic><Text color="#FF6B6B">Red colored text</Text>
<Text color="#4ECDC4">Teal colored text</Text>
<Text color="#45B7D1">Blue colored text</Text><Text fontSize={12}>Small text</Text>
<Text fontSize={16}>Regular text</Text>
<Text fontSize={20}>Large text</Text>
<Text fontSize={24}>Extra large text</Text><Text fontFamily="Arial">Text with Arial font</Text>
<Text fontFamily="Helvetica">Text with Helvetica font</Text>
<TextBold fontFamily="CustomFont-Bold">Bold with custom font</TextBold><Text color="#333333" fontSize={18} fontFamily="Roboto-Medium">
Custom styled text
</Text>;<Text numberOfLines={2} ellipsizeMode="tail" selectable style={styles.centeredText}>
This text will be truncated after two lines and can be selected
</Text>
const styles = StyleSheet.create({
centeredText: {
textAlign: 'center',
},
})| Prop | Type | Default | Description |
|---|---|---|---|
fontSize |
TextStyle['fontSize'] |
theme.components.Text.fontSize |
Custom font size |
color |
string |
theme.components.Text.color |
Text color |
fontFamily |
string |
theme.fonts.regular |
Custom font family |
The Text component also accepts all props from React Native's TextProps:
style- Additional stylingnumberOfLines- Limit number of linesellipsizeMode- Text truncation behaviorselectable- Allow text selectiontestID- Testing identifier- And all other React Native Text props
The base text component with theme defaults.
Text component with bold font weight using the theme's bold font family.
Text component with italic font style applied.
The Text component integrates with the theme system:
// Theme configuration
const theme = {
components: {
Text: {
fontSize: 16,
color: '#333333',
},
},
fonts: {
regular: 'System',
bold: 'System-Bold',
},
}// Recommended font sizes
<Text fontSize={12}>Caption text</Text>
<Text fontSize={14}>Small text</Text>
<Text fontSize={16}>Body text</Text>
<Text fontSize={18}>Subheading</Text>
<Text fontSize={20}>Heading</Text>
<Text fontSize={24}>Large heading</Text>// Semantic colors
<Text color="#333333">Primary text</Text>
<Text color="#666666">Secondary text</Text>
<Text color="#999999">Tertiary text</Text>
<Text color="#FF0000">Error text</Text>
<Text color="#00AA00">Success text</Text>;<View style={styles.labelContainer}>
<TextBold fontSize={18}>Username</TextBold>
<Text color="#666666">john.doe@example.com</Text>
</View>
const styles = StyleSheet.create({
labelContainer: {
marginBottom: 16,
},
});<View style={styles.formField}>
<TextBold fontSize={14}>Email Address</TextBold>
<TextInput placeholder="Enter your email" />
</View>
const styles = StyleSheet.create({
formField: {
marginBottom: 16,
},
})<Text color="#00AA00">✓ Success: Data saved</Text>
<Text color="#FF0000">✗ Error: Invalid input</Text>
<Text color="#FF9500">⚠ Warning: Please check</Text>;<View style={styles.articleContainer}>
<TextBold fontSize={20}>Article Title</TextBold>
<Text color="#666666" fontSize={12}>
Published on March 15, 2024
</Text>
<Text style={styles.articleContent}>Article content goes here...</Text>
</View>
const styles = StyleSheet.create({
articleContainer: {
padding: 16,
},
articleContent: {
marginTop: 10,
lineHeight: 24,
},
});<TouchableOpacity style={styles.navButton}>
<Text color="#007AFF">Learn More →</Text>
</TouchableOpacity>
const styles = StyleSheet.create({
navButton: {
padding: 12,
alignSelf: 'flex-start',
},
})<Text accessibilityLabel="Welcome message" accessibilityRole="text">
Welcome to our app!
</Text><Text accessibilityRole="header" fontSize={20}>
Page Title
</Text>- Consistent Typography - Use theme values for consistent font sizes and colors
- Semantic Colors - Use meaningful color names and values
- Hierarchy - Use font sizes and weights to create clear visual hierarchy
- Accessibility - Ensure sufficient color contrast (4.5:1 for normal text)
- Line Height - Consider line spacing for readability
- Font Loading - Ensure custom fonts are properly loaded before use
- The Text component is optimized with styled-components
- Font changes may trigger re-renders
- Consider memoization for dynamic text with frequent updates
- Custom fonts should be preloaded for optimal performance
Custom font not displaying
- Verify the font is properly linked in your project
- Check font family name spelling
- Ensure font files are included in the build
Theme colors not applying
- Verify theme provider is properly configured
- Check theme structure matches expected format
- Ensure component is wrapped in theme provider
Text not wrapping properly
- Add
flexShrink: 1to parent container - Consider using
numberOfLinesfor truncation - Check parent container width constraints
Styling conflicts
- Theme styles have lower priority than direct props
- Use
styleprop for one-off customizations - Check for conflicting styles in parent components