"use client"; import type { CSSProperties, ReactNode } from "react"; import type { CssSection, CssToken } from "./read-css-tokens"; import styles from "./dev-test.module.scss"; /** * ⚠️ 값으로 그 토큰의 CSS 변수가 아니라 **섹션의 선언 원문**을 넣는다. 변수를 쓰면 PC * 섹션이 좁은 창에서 모바일 값으로, Light 섹션이 다크 테마에서 다크 색으로 그려진다. * 렌더할 토큰을 미리 알 수 없어 인라인 `style`을 쓰는 예외 지점이기도 하다. */ const PREVIEWS: { match: RegExp; render: (value: string) => ReactNode }[] = [ { match: /(^|-)padding(-|$)/, render: (value) => (
첫 번째 문단
두 번째 문단
첫 번째 문단
두 번째 문단
다람쥐 헌 쳇바퀴에 타고파 · Handgloves 0123
), }, { match: /^font-family-/, render: (value) => (다람쥐 헌 쳇바퀴에 타고파 · Handgloves 0123
), }, { match: /^font-weight-/, render: (value) => (다람쥐 헌 쳇바퀴에 타고파 · Handgloves 0123
), }, ]; function previewFor(token: CssToken): ReactNode { if (isColor(token)) { // 색은 값 칸의 칩이 이미 보여준다. return null; } const hit = PREVIEWS.find((entry) => entry.match.test(token.name)); return hit ? hit.render(token.declaration) : null; } /** 이 세 접두사만 색이다. */ function isColor(token: CssToken): boolean { return /^(color|primitive|theme)-/.test(token.name); } /** 참조든 리터럴이든 원문을 그대로 넣는다 — 참조 대상은 모드 무관 값이라 안전하다. */ function chipStyle(token: CssToken): CSSProperties { return { background: token.declaration }; } export function TokenView({ section }: { section: CssSection }) { const hasPreview = section.tokens.some((token) => previewFor(token) !== null); return ({section.source} — 값은 컴파일된 스타일시트에서 직접 읽습니다. 참조면 가리키는 토큰을, 아니면 값을 표시합니다.
| 토큰 | 값 / 참조 | {hasPreview ?미리보기 | : null}
|---|---|---|
| {token.name} | {isColor(token) ? ( ) : null} {token.alias !== null ? ( → {token.alias} ) : ( token.declaration )} | {hasPreview ?{previewFor(token)} | : null}