타이포그래피

Devup UI는 정적 스타일, 반응형 타이포그래피, 테마 통합을 지원하는 강력한 타이포그래피 시스템을 제공합니다.

기본 타이포그래피

devup.json에 타이포그래피 스타일을 정의합니다.

1{
2  "theme": {
3    "typography": {
4      "h1": {
5        "fontFamily": "Pretendard",
6        "fontSize": "48px",
7        "fontWeight": 800,
8        "lineHeight": 1.2,
9        "letterSpacing": "-0.02em"
10      },
11      "h2": {
12        "fontFamily": "Pretendard",
13        "fontSize": "36px",
14        "fontWeight": 700,
15        "lineHeight": 1.3,
16        "letterSpacing": "-0.02em"
17      },
18      "body": {
19        "fontFamily": "Pretendard",
20        "fontSize": "16px",
21        "fontWeight": 400,
22        "lineHeight": 1.5
23      },
24      "caption": {
25        "fontFamily": "Pretendard",
26        "fontSize": "14px",
27        "fontWeight": 400,
28        "lineHeight": 1.4
29      }
30    }
31  }
32}
1{
2  "theme": {
3    "typography": {
4      "h1": {
5        "fontFamily": "Pretendard",
6        "fontSize": "48px",
7        "fontWeight": 800,
8        "lineHeight": 1.2,
9        "letterSpacing": "-0.02em"
10      },
11      "h2": {
12        "fontFamily": "Pretendard",
13        "fontSize": "36px",
14        "fontWeight": 700,
15        "lineHeight": 1.3,
16        "letterSpacing": "-0.02em"
17      },
18      "body": {
19        "fontFamily": "Pretendard",
20        "fontSize": "16px",
21        "fontWeight": 400,
22        "lineHeight": 1.5
23      },
24      "caption": {
25        "fontFamily": "Pretendard",
26        "fontSize": "14px",
27        "fontWeight": 400,
28        "lineHeight": 1.4
29      }
30    }
31  }
32}

typography prop으로 타이포그래피를 적용합니다.

1const h1Example = <Text typography="h1">Heading 1</Text>
2const h2Example = <Text typography="h2">Heading 2</Text>
3const bodyExample = <Text typography="body">Body text</Text>
4const captionExample = <Text typography="caption">Caption text</Text>
1const h1Example = <Text typography="h1">Heading 1</Text>
2const h2Example = <Text typography="h2">Heading 2</Text>
3const bodyExample = <Text typography="body">Body text</Text>
4const captionExample = <Text typography="caption">Caption text</Text>

타이포그래피 속성

각 타이포그래피 스타일에는 다음 속성을 포함할 수 있습니다.

속성설명예시
fontFamily글꼴 패밀리 이름"Pretendard"
fontSize글꼴 크기"16px"
fontWeight글꼴 굵기(숫자 또는 문자열)

700 또는 "bold"

fontStyle글꼴 스타일

"normal" 또는 "italic"

lineHeight줄 높이(숫자 또는 문자열)

1.5 또는 "150%"

letterSpacing자간"-0.02em"
textTransform텍스트 변환"uppercase"

반응형 타이포그래피

배열을 사용해 반응형 타이포그래피를 정의합니다. 각 인덱스는 하나의 브레이크포인트에 대응합니다.

1{
2  "theme": {
3    "typography": {
4      "h1": [
5        {
6          "fontFamily": "Pretendard",
7          "fontSize": "32px",
8          "fontWeight": 800,
9          "lineHeight": 1.2
10        },
11        null,
12        null,
13        null,
14        {
15          "fontFamily": "Pretendard",
16          "fontSize": "48px",
17          "fontWeight": 800,
18          "lineHeight": 1.2
19        }
20      ]
21    }
22  }
23}
1{
2  "theme": {
3    "typography": {
4      "h1": [
5        {
6          "fontFamily": "Pretendard",
7          "fontSize": "32px",
8          "fontWeight": 800,
9          "lineHeight": 1.2
10        },
11        null,
12        null,
13        null,
14        {
15          "fontFamily": "Pretendard",
16          "fontSize": "48px",
17          "fontWeight": 800,
18          "lineHeight": 1.2
19        }
20      ]
21    }
22  }
23}

브레이크포인트는 다음과 같습니다.

  • 인덱스 0: 0px(모바일)
  • 인덱스 1: 480px
  • 인덱스 2: 768px
  • 인덱스 3: 992px
  • 인덱스 4: 1280px(데스크톱)
  • 인덱스 5: 1600px

null을 사용하면 해당 브레이크포인트를 건너뛰고 이전 값을 그대로 이어받습니다.

전체 타이포그래피 스케일

권장하는 타이포그래피 스케일은 다음과 같습니다.

1{
2  "theme": {
3    "typography": {
4      "h1": [
5        {
6          "fontFamily": "Pretendard",
7          "fontSize": "32px",
8          "fontWeight": 800,
9          "lineHeight": 1.2,
10          "letterSpacing": "-0.03em"
11        },
12        null,
13        null,
14        null,
15        {
16          "fontFamily": "Pretendard",
17          "fontSize": "48px",
18          "fontWeight": 800,
19          "lineHeight": 1.2,
20          "letterSpacing": "-0.03em"
21        }
22      ],
23      "h2": [
24        {
25          "fontFamily": "Pretendard",
26          "fontSize": "28px",
27          "fontWeight": 700,
28          "lineHeight": 1.3
29        },
30        null,
31        null,
32        null,
33        {
34          "fontFamily": "Pretendard",
35          "fontSize": "36px",
36          "fontWeight": 700,
37          "lineHeight": 1.3
38        }
39      ],
40      "h3": [
41        {
42          "fontFamily": "Pretendard",
43          "fontSize": "24px",
44          "fontWeight": 600,
45          "lineHeight": 1.3
46        },
47        null,
48        null,
49        null,
50        {
51          "fontFamily": "Pretendard",
52          "fontSize": "28px",
53          "fontWeight": 600,
54          "lineHeight": 1.3
55        }
56      ],
57      "body": {
58        "fontFamily": "Pretendard",
59        "fontSize": "16px",
60        "fontWeight": 400,
61        "lineHeight": 1.5
62      },
63      "bodyBold": {
64        "fontFamily": "Pretendard",
65        "fontSize": "16px",
66        "fontWeight": 700,
67        "lineHeight": 1.5
68      },
69      "caption": {
70        "fontFamily": "Pretendard",
71        "fontSize": "14px",
72        "fontWeight": 400,
73        "lineHeight": 1.4
74      },
75      "small": {
76        "fontFamily": "Pretendard",
77        "fontSize": "12px",
78        "fontWeight": 400,
79        "lineHeight": 1.4
80      },
81      "buttonL": {
82        "fontFamily": "Pretendard",
83        "fontSize": "18px",
84        "fontWeight": 600,
85        "lineHeight": 1.3
86      },
87      "buttonM": {
88        "fontFamily": "Pretendard",
89        "fontSize": "16px",
90        "fontWeight": 600,
91        "lineHeight": 1.3
92      },
93      "buttonS": {
94        "fontFamily": "Pretendard",
95        "fontSize": "14px",
96        "fontWeight": 600,
97        "lineHeight": 1.3
98      }
99    }
100  }
101}
1{
2  "theme": {
3    "typography": {
4      "h1": [
5        {
6          "fontFamily": "Pretendard",
7          "fontSize": "32px",
8          "fontWeight": 800,
9          "lineHeight": 1.2,
10          "letterSpacing": "-0.03em"
11        },
12        null,
13        null,
14        null,
15        {
16          "fontFamily": "Pretendard",
17          "fontSize": "48px",
18          "fontWeight": 800,
19          "lineHeight": 1.2,
20          "letterSpacing": "-0.03em"
21        }
22      ],
23      "h2": [
24        {
25          "fontFamily": "Pretendard",
26          "fontSize": "28px",
27          "fontWeight": 700,
28          "lineHeight": 1.3
29        },
30        null,
31        null,
32        null,
33        {
34          "fontFamily": "Pretendard",
35          "fontSize": "36px",
36          "fontWeight": 700,
37          "lineHeight": 1.3
38        }
39      ],
40      "h3": [
41        {
42          "fontFamily": "Pretendard",
43          "fontSize": "24px",
44          "fontWeight": 600,
45          "lineHeight": 1.3
46        },
47        null,
48        null,
49        null,
50        {
51          "fontFamily": "Pretendard",
52          "fontSize": "28px",
53          "fontWeight": 600,
54          "lineHeight": 1.3
55        }
56      ],
57      "body": {
58        "fontFamily": "Pretendard",
59        "fontSize": "16px",
60        "fontWeight": 400,
61        "lineHeight": 1.5
62      },
63      "bodyBold": {
64        "fontFamily": "Pretendard",
65        "fontSize": "16px",
66        "fontWeight": 700,
67        "lineHeight": 1.5
68      },
69      "caption": {
70        "fontFamily": "Pretendard",
71        "fontSize": "14px",
72        "fontWeight": 400,
73        "lineHeight": 1.4
74      },
75      "small": {
76        "fontFamily": "Pretendard",
77        "fontSize": "12px",
78        "fontWeight": 400,
79        "lineHeight": 1.4
80      },
81      "buttonL": {
82        "fontFamily": "Pretendard",
83        "fontSize": "18px",
84        "fontWeight": 600,
85        "lineHeight": 1.3
86      },
87      "buttonM": {
88        "fontFamily": "Pretendard",
89        "fontSize": "16px",
90        "fontWeight": 600,
91        "lineHeight": 1.3
92      },
93      "buttonS": {
94        "fontFamily": "Pretendard",
95        "fontSize": "14px",
96        "fontWeight": 600,
97        "lineHeight": 1.3
98      }
99    }
100  }
101}

컴포넌트에서 타이포그래피 사용

1// Text 컴포넌트에서 사용
2const titleExample = <Text typography="h1">Main Title</Text>
3const bodyExample = <Text typography="body">Paragraph text goes here.</Text>
4
5// Box 컴포넌트에서 사용
6const boxExample = <Box typography="caption">Caption in a box</Box>
1// Text 컴포넌트에서 사용
2const titleExample = <Text typography="h1">Main Title</Text>
3const bodyExample = <Text typography="body">Paragraph text goes here.</Text>
4
5// Box 컴포넌트에서 사용
6const boxExample = <Box typography="caption">Caption in a box</Box>
1// styled로 만든 컴포넌트에서 사용
2const Title = styled('h1', {
3  typography: 'h1',
4  color: '$text',
5})
1// styled로 만든 컴포넌트에서 사용
2const Title = styled('h1', {
3  typography: 'h1',
4  color: '$text',
5})

다른 스타일과 함께 사용

타이포그래피는 다른 스타일 props와 함께 사용할 수 있습니다. typography 옆에 작성한 속성은 지정한 브레이크포인트부터 그 이후의 모든 브레이크포인트에서 프리셋보다 우선합니다. 따라서 <Text typography="h1" fontSize="14px" />는 h1의 크기가 커지는 구간에서도 14px를 유지합니다. 조건부로만 지정한 속성(fontSize={small ? '12px' : undefined})도 마찬가지입니다. 프리셋 선언은 직접 작성한 선언보다 아래 캐스케이드 레이어에 놓이므로, 직접 작성한 값이 적용될 때는 언제나 그 값이 우선합니다.

1const example = (
2  <Text color="$primary" mb={4} textAlign="center" typography="h1">
3    Centered Title
4  </Text>
5)
1const example = (
2  <Text color="$primary" mb={4} textAlign="center" typography="h1">
3    Centered Title
4  </Text>
5)

타입 안전성

타이포그래피 토큰은 완전한 타입 안전성을 갖습니다.

1// TypeScript 자동 완성 목록: h1, h2, body 등
2const example = <Text typography="" />
3
4// 잘못된 토큰은 TypeScript 오류를 표시합니다
5const invalidExample = <Text typography="invalid" /> // 오류!
1// TypeScript 자동 완성 목록: h1, h2, body 등
2const example = <Text typography="" />
3
4// 잘못된 토큰은 TypeScript 오류를 표시합니다
5const invalidExample = <Text typography="invalid" /> // 오류!