개요

수많은 프로젝트를 진행하면서 버튼/인풋/셀렉트 등등 여러 컴포넌트를 제작하고 사용했지만 타이포그래피는 선언만 해놓고 정작 제대로 사용이 이루어지지 않아서 텍스트 구조를 일관성 있게 유지하지 못했다.

그러던 도중 토스의 디자인 시스템에서 Paragraph라는 컴포넌트를 발견하고 해당 컴포넌트를 보면서 이제는 텍스트 구조 또한 시스템화하여 재활용하는게 좋겠다는 생각이 들었다.

폴더 구조

Pasted image 20260923144156.png

스타일 코드

브라우저 디버깅 결과 토스에서는 CSS 셀렉터를 사용하는걸로 보니 스타일은 네이티브 CSS로 관리하는 듯 했지만 본인은 구현하기 편한 리액트 CSS 프로퍼티 방법을 사용했다

import { ParagraphProps } from "./paragraph.types";

export const ParagraphTextAlign: Record<
  NonNullable<ParagraphProps["textAlign"]>,
  React.CSSProperties
> = {
  inherit: { textAlign: "inherit" },

  initial: { textAlign: "initial" },

  revert: { textAlign: "revert" },

  "revert-layer": { textAlign: "revert-layer" },

  unset: { textAlign: "unset" },

  center: { textAlign: "center" },

  end: { textAlign: "end" },

  justify: { textAlign: "justify" },

  left: { textAlign: "left" },

  "match-parent": { textAlign: "match-parent" },

  right: { textAlign: "right" },

  start: { textAlign: "start" },
};

export const ParagraphTypography: Record<
  NonNullable<ParagraphProps["typography"]>,
  React.CSSProperties
> = {
  t1: { fontSize: "2rem", lineHeight: "2.5rem" },

  t2: { fontSize: "1.5rem", lineHeight: "2rem" },

  t3: { fontSize: "1.25rem", lineHeight: "1.75rem" },

  t4: { fontSize: "1rem", lineHeight: "1.5rem" },

  t5: { fontSize: "0.875rem", lineHeight: "1.25rem" },

  t6: { fontSize: "0.75rem", lineHeight: "1rem" },

  t7: { fontSize: "0.625rem", lineHeight: "0.875rem" },

  st1: { fontSize: "2.5rem", lineHeight: "3rem" },

  st2: { fontSize: "2.25rem", lineHeight: "2.75rem" },

  st3: { fontSize: "2rem", lineHeight: "2.5rem" },

  st4: { fontSize: "1.75rem", lineHeight: "2.25rem" },

  st5: { fontSize: "1.5rem", lineHeight: "2rem" },

  st6: { fontSize: "1.25rem", lineHeight: "1.75rem" },

  st7: { fontSize: "1rem", lineHeight: "1.5rem" },

  st8: { fontSize: "0.875rem", lineHeight: "1.25rem" },

  st9: { fontSize: "0.75rem", lineHeight: "1rem" },

  st10: { fontSize: "0.625rem", lineHeight: "0.875rem" },

  st11: { fontSize: "0.5rem", lineHeight: "0.75rem" },

  st12: { fontSize: "0.375rem", lineHeight: "0.5rem" },

  st13: { fontSize: "0.25rem", lineHeight: "0.375rem" },
};

export const ParagraphFontWeight: Record<
  NonNullable<ParagraphProps["fontWeight"]>,
  React.CSSProperties
> = {
  regular: { fontWeight: 400 },

  medium: { fontWeight: 500 },

  semibold: { fontWeight: 600 },

  bold: { fontWeight: 700 },
};

export const ParagraphDisplay: Record<
  NonNullable<ParagraphProps["display"]>,
  React.CSSProperties
> = {
  block: { display: "block" },

  inline: { display: "inline" },
};

export const ParagraphColor: Record<
  NonNullable<ParagraphProps["color"]>,
  React.CSSProperties
> = {
  primary: { color: "var(--primary)" },

  destructive: { color: "var(--destructive)" },

  info: { color: "var(--info)" },

  neutral: { color: "var(--neutral)" },

  secondary: { color: "var(--secondary)" },

  success: { color: "var(--success)" },

  warning: { color: "var(--warning)" },

  white: { color: "var(--white)" },
};

컴포넌트 코드

텍스트 컴포넌트라서 그런지 구조는 생각보다 간단하게 이루어졌다 근데 TDS를 사용하면서 느낀 점은 Paragraph.Text / Paragraph.Icon 같은 형식의 컴포넌트를 자주 사용하는것을 보았다

나는 Angular를 주력으로 사용해왔기 때문에 해당 패턴은 생각치 못했는데 이번 기회에 자주 활용해볼 계획이다

import { ParagraphIcon } from "./icon/paragraph-icon";

import {
  ParagraphColor,
  ParagraphDisplay,
  ParagraphFontWeight,
  ParagraphTextAlign,
  ParagraphTypography,
} from "./paragraph.styles";

import { ParagraphProps } from "./paragraph.types";

import { ParagraphText } from "./text/paragraph-text";

export type { ParagraphIconProps } from "./icon/paragraph-icon.types";

function ParagraphRoot(
  props: ParagraphProps & React.HTMLAttributes<HTMLParagraphElement>,
) {
  const {
    ellipsisAfterLines,

    typography,

    fontWeight,

    color,

    display,

    textAlign,

    ...rest
  } = props;

  return (
    <p
      {...rest}
      style={{
        ...(typography ? ParagraphTypography[typography] : {}),

        ...(fontWeight ? ParagraphFontWeight[fontWeight] : {}),

        ...(color ? ParagraphColor[color] : {}),

        ...(display ? ParagraphDisplay[display] : {}),

        ...(textAlign ? ParagraphTextAlign[textAlign] : {}),

        ...(ellipsisAfterLines && ellipsisAfterLines > 0
          ? {
              display: "-webkit-box",

              WebkitBoxOrient: "vertical",

              WebkitLineClamp: Math.floor(ellipsisAfterLines),

              overflow: "hidden",
            }
          : {}),
      }}
    >
            {props.children}   {" "}
    </p>
  );
}

export const Paragraph = Object.assign(ParagraphRoot, {
  Text: ParagraphText,

  Icon: ParagraphIcon,
});

사용

<div className="flex flex-col gap-1">

        <Paragraph typography="t2" fontWeight="bold">

          {title || ""}

        </Paragraph>

        <Paragraph typography="st8" className="text-gray-500">

          {description || ""}

        </Paragraph>

      </div>

Pasted image 20260923150259.png