Typography
Typography renders text with the Material Design 3 type scale.
Usage
import { Typography } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'
export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, justifyContent: 'center', padding: 16, gap: 8 }}>
<Typography variant="headlineMedium">Hello World</Typography>
<Typography variant="bodyLarge">Body text content.</Typography>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}
Variants
The full MD3 type scale:
| Category | Variants |
|---|---|
| Display | displayLarge, displayMedium, displaySmall |
| Headline | headlineLarge, headlineMedium, headlineSmall |
| Title | titleLarge, titleMedium, titleSmall |
| Body | bodyLarge, bodyMedium, bodySmall |
| Label | labelLarge, labelMedium, labelSmall |
Each of the 15 roles also has an MD3 Expressive <name>Emphasized counterpart,
with the same size and line height and a weight one step heavier. So variant
accepts 30 values in total:
| Category | Emphasized variants |
|---|---|
| Display | displayLargeEmphasized, displayMediumEmphasized, displaySmallEmphasized |
| Headline | headlineLargeEmphasized, headlineMediumEmphasized, headlineSmallEmphasized |
| Title | titleLargeEmphasized, titleMediumEmphasized, titleSmallEmphasized |
| Body | bodyLargeEmphasized, bodyMediumEmphasized, bodySmallEmphasized |
| Label | labelLargeEmphasized, labelMediumEmphasized, labelSmallEmphasized |
<Typography variant="titleMediumEmphasized">Emphasized title</Typography>
Use an emphasized variant instead of a base variant plus a fontWeight
override. The emphasized tokens also adjust the tracking, which a weight
override doesn't.
Accessibility
Pass level (1 to 6) on a heading. It sets the header role and aria-level, so the web renders <h1> to <h6> and a crawler reads the outline. A display or headline variant with no level, plain or Emphasized, announces a header on native only: on the web a level-less header is always <h1>, so it renders a plain element there. An explicit accessibilityRole always wins.
<Typography variant="headlineSmall" level={1}>Dune</Typography>
<Typography variant="titleMedium" level={2}>Cast</Typography>
<Typography variant="displaySmall">Aa</Typography>
The AppBar title is a level={1} heading by default. Pass titleLevel={2} to the bar when a heading above it is the page heading.
Custom Styles
import { Typography } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'
export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Typography variant="bodyMedium" style={{ color: 'red' }}>
Custom colored text
</Typography>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}
Custom Text Component
Use the as prop to render with a custom text component:
import { Typography } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { Animated } from '@rootnative/inertia/reanimated'
import { View } from 'react-native'
export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Typography variant="titleLarge" as={Animated.Text}>
Animated text
</Typography>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}
Props
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | ReactNode | - | Yes | Content to display. Accepts strings, numbers, or nested elements. |
variant | enum | bodyMedium | No | MD3 type scale role. Controls font size, weight, line height, and letter spacing. |
color | string | - | No | Override the text color. Takes priority over `style.color`. Defaults to the theme's `onSurface` color. |
style | StyleProp<TextStyle> | - | No | Additional text styles. Can override the default theme color via `style.color` when no `color` prop is set. |
as | ComponentType<TextProps> | | No | Override the underlying text component (e.g. Animated.Text). |
level | enum | - | No | The outline level of a heading. Sets the header role and `aria-level`, so the web renders `<h1>` to `<h6>` and a crawler reads the outline. Without it, a display or headline variant, plain or `Emphasized`, announces a header on native only: on the web a level-less header is always `<h1>`, and a page with five display texts had five `<h1>`. |