"use client"; import type { CSSProperties, ReactNode } from "react"; import type { ManifestSection, ManifestToken } from "./token-manifest"; 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: ManifestToken): ReactNode { if (token.type === "color") { // 색은 값 칸의 칩이 이미 보여준다. return null; } const hit = PREVIEWS.find((entry) => entry.match.test(token.name)); return hit ? hit.render(token.resolved) : null; } /** 참조 대상이 우리가 갖고 있지 않은 컬렉션일 때 생성기가 붙이는 표시. */ function isForeign(alias: string | null): boolean { return Boolean(alias?.includes("미제공")); } function chipStyle(token: ManifestToken): CSSProperties { return { background: token.resolved }; } export function TokenView({ section }: { section: ManifestSection }) { const hasPreview = section.tokens.some((token) => previewFor(token) !== null); const foreignCount = section.tokens.filter((token) => isForeign(token.alias)).length; return ({section.file} — 파일에 값이 적혀 있으면 그 값을, 다른 토큰을 가리키면 참조 토큰을 표시합니다. {foreignCount > 0 ? ` 이 중 ${foreignCount}개는 제공되지 않은 컬렉션을 가리킵니다.` : ""}
| 토큰 | 값 / 참조 | {hasPreview ?미리보기 | : null}
|---|---|---|
| {token.name} {token.figma} | {token.type === "color" ? ( ) : null} {token.literal !== null ? ( token.literal ) : ( → {token.alias} )} | {hasPreview ?{previewFor(token)} | : null}