Typography (Typography)
Typography는 시맨틱 타입 variant로 스타일된 텍스트를 렌더링하는 기본 텍스트 컴포넌트예요. type prop으로 제목·본문·코드 프리셋을 고르고, align, color, weight, truncate 같은 직교 props를 조합해 텍스트를 세밀하게 제어할 수 있답니다. Heading, Paragraph, Code 같은 편의 래퍼도 제공해요.
출처: 문서
본문
Import
import { Typography } from 'heroui-native';
Anatomy
<Typography>...</Typography>
{/* Sub-components */}
<Typography.Heading>...</Typography.Heading>
<Typography.Paragraph>...</Typography.Paragraph>
<Typography.Code>...</Typography.Code>
- Typography: 루트 텍스트 요소예요.
type로 타이포그래피 프리셋을 선택하고, 직교하는align,color,weight,truncateprops를 노출해요. - Typography.Heading: 제목 타입(
h1–h6)으로 제한된 편의 래퍼예요.accessibilityRole="header"를 자동으로 추가해요. - Typography.Paragraph: 본문 타입(
body,body-sm,body-xs)으로 제한된 편의 래퍼예요. - Typography.Code: Chip 스타일의 인라인 모노스페이스 텍스트예요. 플랫폼에 적합한 모노스페이스 글꼴 패밀리를 사용해요.
Usage
기본 사용법
Typography 컴포넌트는 기본적으로 본문 텍스트를 렌더링해요.
<Typography>Hello, world!</Typography>
타입 Variant
type prop으로 시맨틱 타이포그래피 프리셋을 선택할 수 있어요.
<Typography type="h1">Heading 1</Typography>
<Typography type="h2">Heading 2</Typography>
<Typography type="h3">Heading 3</Typography>
<Typography type="h4">Heading 4</Typography>
<Typography type="h5">Heading 5</Typography>
<Typography type="h6">Heading 6</Typography>
<Typography type="body">Body text</Typography>
<Typography type="body-sm">Small body text</Typography>
<Typography type="body-xs">Extra-small body text</Typography>
<Typography type="code">Code snippet</Typography>
제목 (Headings)
자동 헤더 접근성 역할이 있는 제목 텍스트에는 Typography.Heading을 사용하세요.
<Typography.Heading type="h1">Page Title</Typography.Heading>
<Typography.Heading type="h2">Section Title</Typography.Heading>
<Typography.Heading type="h3">Subsection Title</Typography.Heading>
문단 (Paragraphs)
본문 텍스트에는 Typography.Paragraph를 사용하세요.
<Typography.Paragraph>
This is a paragraph of body text with the default size.
</Typography.Paragraph>
<Typography.Paragraph type="body-sm">
This is smaller body text.
</Typography.Paragraph>
코드 (Code)
인라인 코드 조각에는 Typography.Code(또는 동등하게 <Typography type="code">)를 사용하세요. 둘 다 미묘한 배경과 둥근 모서리, 그리고 flex 컨테이너에서 늘어나지 않도록 하는 self-start 레이아웃을 가진 chip 스타일의 모노스페이스 인라인 요소를 렌더링해요. 플랫폼 모노스페이스 fontFamily는 Typography 루트에 적용되므로 두 형태는 서로 교환해서 쓸 수 있어요.
<Typography.Code>console.log('hello')</Typography.Code>
<Typography type="code">console.log('hello')</Typography>
정렬 (Alignment)
align prop으로 가로 정렬을 제어할 수 있어요. start와 end는 RTL을 인식해서(오른쪽에서 왼쪽 레이아웃에서 뒤집힘) 동작해요.
<Typography align="start">Start-aligned</Typography>
<Typography align="center">Center-aligned</Typography>
<Typography align="end">End-aligned</Typography>
<Typography align="justify">Justified text spreads across the line.</Typography>
Note:
text-justify는 React Native에서 iOS 전용이에요. Android는 왼쪽 정렬로 대체됩니다.
색상 (Color)
color prop으로 시맨틱 foreground 색상 프리셋을 적용할 수 있어요.
<Typography color="default">Default foreground</Typography>
<Typography color="muted">Muted secondary text</Typography>
다른 테마 색상은 className을 통해 해당 유틸리티를 전달하세요(예: className="text-accent", className="text-danger").
글꼴 두께 (Weight)
weight prop으로 type이 암시하는 글꼴 두께를 오버라이드할 수 있어요. 이 오버라이드는 tailwind-merge로 병합되므로 타입 variant의 기본 두께보다 항상 우선해요.
<Typography type="h1" weight="bold">Bold H1</Typography>
<Typography weight="medium">Medium body</Typography>
<Typography weight="semibold">Semibold body</Typography>
앱이 커스텀 --font-* 패밀리를 정의하면 각 weight는 숫자 두께 대신 일치하는 패밀리로 해석돼요. 그래서 사용하는 모든 weight에 대해 해당 변수가 정의되어 있어야 해요. 커스텀 폰트를 참고하세요.
말줄임 (Truncation)
truncate boolean prop으로 텍스트를 말줄임표(...)가 있는 한 줄로 제한할 수 있어요. React Native의 numberOfLines={1}에 매핑되요. 명시적인 numberOfLines prop이 제공되면 그것이 우선해요.
<Typography truncate>
A long line of text that will be cut off with an ellipsis when it overflows
the container.
</Typography>;
{
/* Multi-line truncation via the underlying RN prop */
}
<Typography numberOfLines={2}>
Two-line truncation works through React Native's standard `numberOfLines`
prop.
</Typography>;
Example
import { Typography } from 'heroui-native';
import { View } from 'react-native';
export default function TypographyExample() {
return (
<View className="flex-1 justify-center px-5 gap-4">
<Typography.Heading type="h1">Welcome</Typography.Heading>
<Typography.Heading type="h3">Getting Started</Typography.Heading>
<Typography.Paragraph>
This is a body paragraph rendered with the Typography component.
</Typography.Paragraph>
<Typography.Paragraph color="muted" type="body-sm">
Smaller supporting text for captions or footnotes.
</Typography.Paragraph>
<Typography.Code>npm install heroui-native</Typography.Code>
</View>
);
}
더 많은 예시는 GitHub 저장소에서 찾을 수 있어요.
API Reference
Typography
Typography는 모든 표준 React Native TextProps를 추가 타이포그래피 props와 함께 확장해요.
| prop | type | default | description |
|---|---|---|---|
type |
'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'body' | 'body-sm' | 'body-xs' | 'code' |
'body' |
시맨틱 타이포그래피 variant(크기, 기본 두께, 행 높이) |
align |
'start' | 'center' | 'end' | 'justify' |
'start' |
가로 정렬. start와 end는 RTL을 인식. justify는 iOS 전용 |
color |
'default' | 'muted' |
'default' |
시맨틱 foreground 색상 프리셋 |
weight |
'normal' | 'medium' | 'semibold' | 'bold' |
- | 글꼴 두께 오버라이드. 설정하면 type이 암시하는 두께를 오버라이드 |
truncate |
boolean |
false |
텍스트를 말줄임표가 있는 한 줄로 자름(numberOfLines={1} 설정). 명시적인 numberOfLines가 우선 |
children |
React.ReactNode |
- | 렌더링할 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 React Native Text props 지원 |
Typography.Heading
Typography 루트 props(align, color, weight, truncate, className, React Native TextProps)를 모두 상속해요. accessibilityRole="header"를 자동으로 설정하고 type을 제목 variant로 제한해요.
| prop | type | default | description |
|---|---|---|---|
type |
'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' |
'h1' |
제목 레벨 |
children |
React.ReactNode |
- | 렌더링할 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 React Native Text props 지원 |
Typography.Paragraph
Typography 루트 props(align, color, weight, truncate, className, React Native TextProps)를 모두 상속해요. type을 본문 variant로 제한해요.
| prop | type | default | description |
|---|---|---|---|
type |
'body' | 'body-sm' | 'body-xs' |
'body' |
문단 텍스트 크기 |
children |
React.ReactNode |
- | 렌더링할 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 React Native Text props 지원 |
Typography.Code
Typography 루트 props(align, color, weight, truncate, className, style, React Native TextProps)를 모두 상속해요. type="code"를 강제하는 가벼운 래퍼예요. 플랫폼 모노스페이스 fontFamily는 Typography 루트에서 병합되므로 <Typography type="code">와 <Typography.Code>는 동일하게 렌더링돼요.
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactNode |
- | 렌더링할 콘텐츠 |
className |
string |
- | 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 React Native Text props 지원 |