Migrating to CSS variables
Migrating to CSS variables (CSS 변수로 마이그레이션하기)
기존 Primer 스타일링 시스템에서 새 CSS variable 프리미티브로 옮기는 방법을 빠르게 참고할 수 있는 페이지예요. Primer React의 sx props에서 CSS Modules로, 그리고 Primer CSS의 legacy SCSS 변수에서 새 CSS 변수로 마이그레이션할 때 매핑 표를 안내해요.
출처: 문서
본문
기존 Primer 스타일링 시스템에서 새 CSS variable 프리미티브로 마이그레이션하기 위한 빠른 참고서예요.
sx props (Primer React)에서 마이그레이션하기
✨ React 코드를 CSS Modules로 옮길 때 도와주는 VSCode extension이 있어요. 이 확장이 JavaScript 문법을 CSS로 변환하고, Primer theme 키워드를 CSS 변수로 바꾸고, module 파일을 만드는 등의 작업을 자동으로 처리해요.
Spacing (간격)
Stacks (스택)
스택은 콘텐츠를 세로 또는 가로로 배치하는 흐름 콘텐츠를 담는 박스예요. 보통 display: flex나 grid, 또는 block이에요.
스택 패딩 (Stack padding)
스택 가장자리의 내부 padding(p, px, py, pr 등의 단축 표기 포함)에 아래 값을 사용해요.
sx 키워드 |
해석 값 | 프리미티브 |
|---|---|---|
0 |
0px | 0 |
1 |
4px | --base-size-4 |
2 |
8px | --base-size-8 |
3 |
16px | --base-size-16 |
4 |
24px | --base-size-24 |
5 |
32px | --base-size-32 |
6 |
40px | --base-size-40 |
7 |
48px | --base-size-48 |
8 |
64px | --base-size-64 |
9 |
80px | --base-size-80 |
10 |
96px | --base-size-96 |
11 |
112px | --base-size-112 |
12 |
128px | --base-size-128 |
스택 마진 (Stack margin)
margin은 컴포넌트 바깥으로 공간이 새기 때문에 사용하지 않는 편이 좋아요. margin은 컨테이너 padding이나 flex layout의 gap으로 바꾸는 게 좋아요. 위 패딩 값을 참고하세요. margin 프리미티브는 따로 없어요.
스택 콘텐츠 간격 (Stack content spacing)
보통 flex(column 방향)나 grid 레이아웃의 CSS gap이에요. 아직 flexbox/grid로 갱신되지 않은 항목 사이의 margin일 수도 있어요.
sx 키워드 |
해석 값 | 프리미티브 |
|---|---|---|
0 |
0px | 0 |
1 |
4px | --base-size-4 |
2 |
8px | --stack-gap-condensed |
3 |
16px | --stack-gap-normal |
4 |
24px | --stack-gap-spacious |
5 |
32px | --base-size-32 |
6 |
40px | --base-size-40 |
7 |
48px | --base-size-48 |
8 |
64px | --base-size-64 |
9 |
80px | --base-size-80 |
10 |
96px | --base-size-96 |
11 |
112px | --base-size-112 |
12 |
128px | --base-size-128 |
Control stacks (컨트롤 스택)
컨트롤 스택은 인라인 인터랙티브 항목(예: 버튼·라벨 묶음)을 나란히 배치하는 가로(인라인) 행이에요. 보통 display: flex나 inline-flex에 flex-direction: row예요. 컨트롤 스택의 크기는 그 안의 컨트롤 크기에 따라 달라져요. 예를 들어 'small' IconButton이 들어 있는 스택은 'small' 스택이에요.
컨트롤 스택 패딩/마진
세로 스택과 같은 패딩·마진 값을 사용해요.
컨트롤 스택 콘텐츠 간격
flex 레이아웃의 gap 속성, 또는 오래된 레이아웃의 항목 margin이에요.
sx 키워드 |
해석 값 | 프리미티브 |
|---|---|---|
0 |
0px | 0 |
1 |
4px | --base-size-4 |
2 |
8px | --controlStack-small-gap-condensed / --controlStack-medium-gap-condensed / --controlStack-large-gap-condensed |
3 |
16px | --controlStack-small-gap-spacious / --controlStack-medium-gap-spacious / --controlStack-large-gap-spacious |
4 |
24px | --base-size-24 |
5 |
32px | --base-size-32 |
| ... | ... | (--base-size-*로 이어짐) |
Controls (컨트롤)
컨트롤은 Button, Label 같은 작은 빌딩 블록 요소예요. 이 값들은 컨트롤의 크기·밀도 수준·위/아래 대 측면별로 다르기 때문에 경우에 따라 개별적으로 판단해야 해요. 좋은 값을 찾으려면 the primitives list를 참고하거나 당분간 --base-size 값을 쓰세요.
Colors (색상)
Canvas
sx 키워드 |
프리미티브 |
|---|---|
canvas.default |
--bgColor-default |
canvas.overlay |
--overlay-bgColor |
canvas.inset |
--bgColor-inset |
canvas.subtle |
--bgColor-muted |
Foreground
sx 키워드 |
프리미티브 |
|---|---|
fg.default |
--fgColor-default |
fg.muted |
--fgColor-muted |
fg.subtle |
제거됨, 대신 --fgColor-muted 사용 |
fg.onEmphasis |
--fgColor-onEmphasis |
Border
sx 키워드 |
프리미티브 |
|---|---|
border.default |
--borderColor-default |
border.muted |
--borderColor-muted |
border.subtle |
제거됨, 대신 --borderColor-muted 사용 |
Accent
sx 키워드 |
프리미티브 |
|---|---|
accent.fg |
--fgColor-accent |
accent.emphasis |
--bgColor-accent-emphasis |
accent.muted |
--borderColor-accent-muted |
accent.subtle |
--bgColor-accent-muted |
Success, Attention, Severe, Danger, Open, Closed, Done, Sponsors
sx 키워드 |
프리미티브 |
|---|---|
{name}.fg |
--fgColor-{name} |
{name}.emphasis |
--bgColor-{name}-emphasis |
{name}.muted |
--borderColor-{name}-muted |
{name}.subtle |
--bgColor-{name}-muted |
Fonts (글꼴)
Font size
스타일링하는 텍스트 종류에 맞는 값을 사용해요.
타이틀 (Titles) — Heading 등
sx 키워드 |
해석 값 | 프리미티브 |
|---|---|---|
0 |
12px | --base-size-12 |
1 |
14px | --base-size-14 |
2 |
16px | --text-title-size-small |
3 |
20px | --text-title-size-medium |
4 |
24px | --base-size-24 |
5 |
32px | --text-title-size-large |
6 |
40px | --base-size-40 |
7 |
48px | --base-size-48 |
8 |
56px | --base-size-56 |
본문 텍스트 (Body text)
sx 키워드 |
해석 값 | 프리미티브 |
|---|---|---|
0 |
12px | --text-body-size-small |
1 |
14px | --text-body-size-medium |
2 |
16px | --text-body-size-large |
3 |
20px | --base-size-20 |
4 |
24px | --base-size-24 |
| ... | ... | (--base-size-*로 이어짐) |
Font family
sx 키워드 |
프리미티브 |
|---|---|
normal |
--fontStack-system 또는 명시적으로 --fontStack-sansSerif |
mono |
--fontStack-monospace |
Borders (테두리)
Border width
이전에 쓰던 숫자나 픽셀 값 대신 아래 프리미티브를 선호해요.
sx 키워드 |
해석 값 | 프리미티브 |
|---|---|---|
0 |
0px | 0 |
1 |
1px | --borderWidth-thin |
| 2px | --borderWidth-thick |
|
| 3px | --borderWidth-thicker |
Border radius
sx 키워드 |
해석 값 | 프리미티브 |
|---|---|---|
0 |
0px | 0 |
1 |
3px | --borderRadius-small |
2 |
6px | --borderRadius-medium |
| 12px | --borderRadius-large |
|
3 |
아주 큼 | --borderRadius-full |
Sizes and Breakpoints
보통 breakpoint·높이·너비에 사용해요. (다이얼로그 같은) overlay에는 새 overlay 프리미티브를 선호해요. 이 크기들은 기존 키워드와 1:1 매핑이 아니에요.
CSS 변수는 @media나 @container 쿼리 표현식에 쓸 수 없어요. 그 경우 일반 픽셀 값을 써야 해요. 미래의 media query 지원을 기다리세요.
sx breakpoint 키워드 |
sx size 키워드 |
해석 값 | 프리미티브 |
|---|---|---|---|
| 320px | --breakpoint-xsmall |
||
0 |
size.small |
544px | --breakpoint-small |
1 |
size.medium |
768px | --breakpoint-medium |
2 |
size.large |
1012px | --breakpoint-large |
3 |
size.xlarge |
1280px | --breakpoint-xlarge |
| 1400px | --breakpoint-xxlarge |
SCSS Variables에서 마이그레이션하기
Primer CSS의 대부분 legacy SCSS 변수는 새 CSS 변수로 대체할 수 있어요. 대체 항목이 없는 값은 원시 값을 쓰거나 값이 비슷한 대체 항목을 찾으세요.
Legacy scss 변수 |
새 css 변수 |
|---|---|
$h00-size-mobile |
--text-display-size |
$h0-size-mobile |
--text-title-size-large |
$h1-size-mobile |
26px (deprecated) |
$h2-size-mobile |
22px (deprecated) |
$h3-size-mobile |
18px (deprecated) |
$h00-size |
--base-size-48 |
$h0-size |
--text-display-size |
$h1-size |
--text-title-size-large |
$h2-size |
--base-size-24 |
$h3-size |
--text-title-size-medium |
$h4-size |
--text-title-size-small |
$h5-size |
--text-body-size-medium |
$h6-size |
--text-body-size-small |
$font-size-small |
--text-body-size-small |
$font-weight-bold |
--base-text-weight-semibold |
$font-weight-semibold |
--base-text-weight-medium |
$font-weight-normal |
--base-text-weight-normal |
$font-weight-light |
--base-text-weight-light |
$body-font |
--fontStack-system |
$mono-font |
--fontStack-monospace |
$body-font-size |
--text-body-size-medium |
$spacer / $spacer-2 |
--base-size-8 |
$spacer-1 |
--base-size-4 |
$spacer-3 |
--base-size-16 |
$spacer-4 |
--base-size-24 |
$spacer-5 |
--base-size-32 |
$spacer-6 |
--base-size-40 |
$spacer-7 |
--base-size-48 |
$spacer-8 |
--base-size-64 |
$spacer-9 |
--base-size-80 |
$spacer-10 |
--base-size-96 |
$spacer-11 |
--base-size-112 |
$spacer-12 |
--base-size-128 |
$size / $size-1 |
--base-size-16 |
$size-2 |
--base-size-20 |
$size-3 |
--base-size-24 |
$size-4 |
--base-size-28 |
$size-5 |
--base-size-32 |
$size-6 |
--base-size-40 |
$size-7 |
--base-size-48 |
$size-8 |
--base-size-64 |
$width-sm / $container-sm |
--breakpoint-small |
$width-md / $container-md |
--breakpoint-medium |
$width-lg / $container-lg |
--breakpoint-large |
$width-xl / $container-xl |
--breakpoint-xlarge |
$viewport-narrow |
--viewportRange-narrow |
$viewport-regular |
--viewportRange-regular |
$viewport-wide |
--viewportRange-wide |
$border-width |
--borderWidth-thin |
$border / $border-rem |
solid var(--borderWidth-thin) var(--borderColor-default) |
$border-radius-1 |
--borderRadius-small |
$border-radius-2 |
--borderRadius-medium |
$border-radius |
--borderRadius-small |
(deprecated로 표시된 $h1-size-mobile·$em-spacer-*·$container-width·$grid-gutter·$width-xs·$border-style 등은 원시 값 사용)
더 알아보기 (Learn more)
- React 코드를 CSS Modules로 옮길 때 VSCode extension을 활용하면 변환을 자동화할 수 있어요.
sx공간·간격 값은--base-size-*,--stack-gap-*,--controlStack-*-gap-*프리미티브로 옮겨요.- 색상은
--bgColor-*,--fgColor-*,--borderColor-*구조로 매핑하고, 제거된fg.subtle·border.subtle은 muted 계열을 쓰세요. - 대부분 legacy SCSS 변수는 대응하는 CSS 변수가 있으니 매핑 표를 활용하세요.