Typography
Typography component is used to present your design and content as clearly and efficiently as possible.
Import
import { Typography } from '@lazy-panda-ui/lazy-panda-ui';
Usage
import React from 'react';
import { Typography } from '@lazy-panda-ui/lazy-panda-ui';
function MyComponent() {
return (
<>
<Typography variant="h1">Heading 1</Typography>
<Typography variant="body1">Regular text content</Typography>
</>
);
}
Props
Name | Type | Default | Description |
---|---|---|---|
variant | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'subtitle1' | 'subtitle2' | 'body1' | 'body2' | 'caption' | 'overline' | 'body1' | The variant to use |
color | string | 'text' | The color of the text |
align | 'left' | 'center' | 'right' | 'justify' | 'left' | Text alignment |
numberOfLines | number | - | Maximum number of lines to show |
style | StyleProp<TextStyle> | - | Additional styles for the text |
Variants
Headings
<>
<Typography variant="h1">Heading 1</Typography>
<Typography variant="h2">Heading 2</Typography>
<Typography variant="h3">Heading 3</Typography>
<Typography variant="h4">Heading 4</Typography>
<Typography variant="h5">Heading 5</Typography>
<Typography variant="h6">Heading 6</Typography>
</>
Body Text
<>
<Typography variant="body1">
Body 1. Default text style for content.
</Typography>
<Typography variant="body2">
Body 2. Slightly smaller text.
</Typography>
</>
Other Variants
<>
<Typography variant="subtitle1">Subtitle 1</Typography>
<Typography variant="subtitle2">Subtitle 2</Typography>
<Typography variant="caption">Caption text</Typography>
<Typography variant="overline">OVERLINE TEXT</Typography>
</>
Examples
With Custom Color
<Typography
variant="h6"
color="primary"
>
Colored Heading
</Typography>
Multiline Text with Ellipsis
<Typography
variant="body1"
numberOfLines={2}
>
This is a very long text that will be truncated after two lines.
Any text beyond the second line will be replaced with an ellipsis.
</Typography>
Custom Styled Text
<Typography
style={{
textDecorationLine: 'underline',
fontStyle: 'italic'
}}
>
Custom styled text
</Typography>
Responsive Text
<Typography
variant="h1"
style={[
{ fontSize: 24 }, // Base size
{ '@media (min-width: 768px)': { fontSize: 32 } } // Larger on tablets
]}
>
Responsive heading
</Typography>
Accessibility
The Typography component supports all Text accessibility props:
<Typography
accessibilityLabel="Important heading"
accessibilityRole="header"
>
Important Information
</Typography>
API Reference
Theme Integration
Typography uses the theme's typography settings:
// In your theme
const theme = {
typography: {
h1: {
fontSize: 32,
fontWeight: 'bold',
lineHeight: 40,
},
body1: {
fontSize: 16,
lineHeight: 24,
},
// ... other variants
}
};
Platform Specific
The component handles platform-specific font families:
<Typography
style={{
fontFamily: Platform.select({
ios: 'San Francisco',
android: 'Roboto',
})
}}
>
Platform specific font
</Typography>
Best Practices
- Use appropriate variants for content hierarchy
- Maintain consistent text styles throughout your app
- Consider readability when choosing colors and sizes
- Use responsive typography for different screen sizes
- Follow platform typography guidelines
- Consider line height for readability
- Use appropriate text alignment for different languages