Typography
A typography component with semantic variants and consistent text styling.
Typography is the React Native implementation shipped by the native-typography registry item. The component adapts the registry's web-facing composition to native primitives and touch-based interaction.
The native Typography component provides a single text primitive for the native registry. It combines the project's shared typography variants with React Native's Text component and automatically applies accessibility semantics for headings.
Typography also supports a context-based class name. Components such as the native Button, Card, Badge, and Field primitives use this context to provide consistent nested text styling.
Installation
CLI
npx shadcn add https://ui.tiesen.id.vn/r/native-typography.jsonManual
Copy and paste the following code into your project.
import type { VariantProps } from 'class-variance-authority'import type { AccessibilityRole } from 'react-native'import * as React from 'react'import { Text } from 'react-native'import { cn } from '@/lib/utils'import { typographyVariants } from '@/components/ui/typography'const TypographyContext = React.createContext('')type TypographyProps = VariantProps<typeof typographyVariants>const ROLES = { h1: 'header', h2: 'header', h3: 'header', h4: 'header',} as const satisfies Partial< Record<NonNullable<TypographyProps['variant']>, AccessibilityRole>>const LEVELS = { h1: 1, h2: 2, h3: 3, h4: 4,} as const satisfies Partial< Record<NonNullable<TypographyProps['variant']>, number>>function Typography({ className, variant = 'p', ...props}: React.ComponentProps<typeof Text> & VariantProps<typeof typographyVariants>) { const classCtx = React.use(TypographyContext) return ( <Text data-slot='typography' accessibilityRole={ROLES[variant as keyof typeof ROLES] ?? 'text'} aria-level={LEVELS[variant as keyof typeof LEVELS]} className={cn( 'text-base font-normal text-foreground', typographyVariants({ variant }), classCtx, className )} {...props} /> )}export { typographyVariants } from '@/components/ui/typography'export { TypographyContext, Typography }Features
- Shared typography variants from the project's typography registry.
- Heading accessibility roles for
h1throughh4. - Heading levels are exposed through
aria-level. - Supports React Native
Textprops. - Supports inherited typography classes through
TypographyContext. - Works with NativeWind/Uniwind
classNamestyling.
Registry dependencies: This component uses the shared web
typographyregistry styles.
Usage
import { Typography } from '@/components/native/typography'
export function TypographyExample() {
return (
<View className='gap-2'>
<Typography variant='h1'>
Account settings
</Typography>
<Typography variant='p'>
Update your profile and notification preferences.
</Typography>
</View>
)
}Variants
The available variants are inherited from the project's shared typographyVariants. Common semantic variants include headings and paragraph/body styles.
<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='p'>Paragraph</Typography>The exact variant list is defined by the shared @/registry/ui/typography implementation.
Accessibility
The component maps heading variants to React Native accessibility metadata:
h1→accessibilityRole="header", level1h2→accessibilityRole="header", level2h3→accessibilityRole="header", level3h4→accessibilityRole="header", level4
Other variants use the text accessibility role.
Typography context
TypographyContext allows a parent component to provide additional classes to nested typography.
<TypographyContext value='text-primary'>
<Typography>Inherited text color</Typography>
</TypographyContext>The component combines the context class with the component's variant and local className.
API Reference
Typography
| Prop | Type | Default |
|---|---|---|
variant | TypographyVariant from typographyVariants | "p" |
className | string | — |
children | React.ReactNode | — |
...props | React.ComponentProps<typeof Text> | — |
Heading variants automatically expose heading accessibility metadata.
TypographyContext
const TypographyContext: React.Context<string>Provides inherited typography classes to nested Typography components.
typographyVariants
typographyVariants(
props?: VariantProps<typeof typographyVariants>
)The shared CVA helper used to resolve typography classes.