레거시 디자인 시스템 고도화하기
6주차는 레거시 디자인 시스템을 고도화하는 시간이었다. before로 작성된, 이상하게 구현된 디자인 시스템을 shadcn, tailwind 등을 통해 접근성과 더 나은 유지보수를 구현하는 일이었다.
- 디자인 시스템의 스타일 가이드 요소인 색상, 글자, 간격의 스타일 속성을 변수로 정의하여 코드화한 것이다. #KRDS
- 이는 일관성과 가독성을 유지하고, 개발자와 디자이너가 동일한 언어로 토큰을 이해할 수 있도록 돕는다.
https://www.krds.go.kr/html/site/style/style_07.html
📦tokens
┣ 📂primitives
┃ ┣ 📜colors.css
┃ ┣ 📜motion.css
┃ ┣ 📜rounded.css
┃ ┣ 📜shadow.css
┃ ┣ 📜spacing.css
┃ ┗ 📜typography.css
┣ 📂semantic
┃ ┣ 📜colors.css
┃ ┣ 📜motion.css
┃ ┣ 📜rounded.css
┃ ┣ 📜shadow.css
┃ ┣ 📜spacing.css
┃ ┗ 📜typography.css
┗ 📜index.css
index.css
:root {
/* ===== BLUE SCALE ===== */
--blue-50: #e3f2fd;
--blue-500: #0288d1;
--blue-600: #1976d2;
--blue-700: #1565c0;
--blue-900: #0d47a1;
..
..
/* ===== FONT SIZES (Typography Primitives) ===== */
--text-xs: 0.75rem; /* 12px */
--text-sm: 0.875rem; /* 14px */
--text-base: 1rem; /* 16px */
--text-lg: 1.125rem; /* 18px */
primitives/colors.css
/*
* Primitives
* src/index.css의 :root 변수들을 Tailwind 토큰으로 등록
*/
@theme {
/* ===== BLUE SCALE ===== */
--color-blue-50: var(--blue-50);
--color-blue-500: var(--blue-500);
--color-blue-600: var(--blue-600);
semantic/colors.css
@theme {
/* ===== BUTTON COLORS ===== */
--color-button-primary-bg: var(--color-blue-600);
--color-button-primary-bg-hover: var(--color-blue-700);
--color-button-primary-text-color: var(--color-white);
사실 3계층이 primitives/semantic/components 로 구성돼있는데, 나는 index.css(root)/primitives/semantic 으로 구성했다.
button.tsx
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-button transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] cursor-pointer",
{
variants: {
variant: {
primary:
"bg-button-primary-bg text-button-primary-text-color hover:bg-button-primary-bg-hover",
secondary:
"bg-button-secondary-bg text-button-secondary-text border border-button-secondary-border hover:bg-button-secondary-bg-hover",
bg-button-primary-bg , bg-button-secondary-bg 처럼 variant에 요소를 작성했다.
사용하는 부분
<Button
variant="secondary"
size="md"
onClick={handleCloseCreateModal}
>
취소
</Button>
// semantic/colors.css
--color-button-primary-text-color: var(--color-white);
// semantic/typography.css
--text-size-button-sm: var(--text-sm);
// button.tsx
variants: {
variant: {
primary:
"bg-button-primary-bg text-button-primary-text-color hover:bg-button-primary-bg-hover",
size: {
default: "h-9 px-4 py-2 has-[>svg]:px-3",
sm: "h-8 gap-1.5 px-3 has-[>svg]:px-2 text-size-button-sm",
defaultVariants: {
variant: "primary",
size: "sm",
},
text-button-primary-text-color 와 size sm의 text-size-button-sm으로 작성 후 확인해보면, semantic으로 작성한 두 개의 text 네임스페이스가 충돌하게되어 마지막으로 작성된 내용만 반영됨을 볼 수 있었다..text-sm을 적용했다. 기존 디자인 똑같이 따라하려고 이상하게 짜여진 사이즈 같은 경우를 토큰화 하려는데, 그걸 굳이 토큰화한다는건 오히려 좋지 않은 것! 디자인 시스템 컨벤션에 어울리지 않는것이라 할 수 있다.