Skip to content

Commit e4c0713

Browse files
committed
chore(docs): support TokenLit
1 parent 63fe0c5 commit e4c0713

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

docs/components/rootage.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ export function stringifyTokenLit(token: AST.TokenLit): AST.TokenRef {
1717
}
1818

1919
export function stringifyValueLit(lit: AST.ValueLit): string {
20+
const tokenReference = (token: AST.TokenLit) => stringifyTokenLit(token);
21+
2022
switch (lit.kind) {
2123
case "DimensionLit":
2224
return lit.unit === "rem"
23-
? `${css.staticStringifier.value(lit)} (${lit.value * 16}px)`
24-
: css.staticStringifier.value(lit);
25+
? `${css.staticStringifier.value(lit, tokenReference)} (${lit.value * 16}px)`
26+
: css.staticStringifier.value(lit, tokenReference);
2527
default:
26-
return css.staticStringifier.value(lit);
28+
return css.staticStringifier.value(lit, tokenReference);
2729
}
2830
}
2931

docs/components/token-cell.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,30 @@ export interface TokenCellProps {
1919
resolvedValue: AST.ValueLit;
2020
}
2121

22+
function renderGradientWithTokens(gradient: AST.GradientLit) {
23+
return (
24+
<span>
25+
{gradient.stops.map((stop, index) => (
26+
<Fragment key={index}>
27+
{stop.color.kind === "TokenLit" ? (
28+
<TokenLink id={stop.color.identifier} />
29+
) : (
30+
stop.color.value
31+
)}{" "}
32+
{(stop.position.value * 100).toFixed(1)}%{index < gradient.stops.length - 1 ? ", " : ""}
33+
</Fragment>
34+
))}
35+
</span>
36+
);
37+
}
38+
2239
export function TokenCell(props: TokenCellProps) {
2340
const { isExpanded, values, resolvedValue } = props;
2441

42+
const isGradientWithTokens =
43+
resolvedValue.kind === "GradientLit" &&
44+
resolvedValue.stops.some((stop) => stop.color.kind === "TokenLit");
45+
2546
return (
2647
<div className="flex justify-between" aria-expanded={isExpanded}>
2748
<div className="flex flex-col gap-1">
@@ -30,7 +51,9 @@ export function TokenCell(props: TokenCellProps) {
3051
<Fragment key={item.ref}>
3152
<div className="flex items-center gap-2">
3253
<TypeIndicator value={resolvedValue} />{" "}
33-
{item.ref.startsWith("$") ? (
54+
{index === values.length - 1 && isGradientWithTokens ? (
55+
renderGradientWithTokens(resolvedValue as AST.GradientLit)
56+
) : item.ref.startsWith("$") ? (
3457
<TokenLink id={item.ref} description={item.description} />
3558
) : (
3659
item.ref
@@ -46,7 +69,9 @@ export function TokenCell(props: TokenCellProps) {
4669
) : (
4770
<div className="flex items-center gap-2">
4871
<TypeIndicator value={resolvedValue} />{" "}
49-
{values[0].ref.startsWith("$") ? (
72+
{isGradientWithTokens ? (
73+
renderGradientWithTokens(resolvedValue as AST.GradientLit)
74+
) : values[0].ref.startsWith("$") ? (
5075
<TokenLink id={values[0].ref} description={values[0].description} />
5176
) : (
5277
values[0].ref

docs/components/type-indicator.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ import { IconLayers, IconRuler, IconSpline } from "./icons";
55
// Gradient를 CSS linear-gradient로 변환하는 유틸리티 함수
66
function gradientToCss(gradient: AST.GradientLit): string {
77
const stops = gradient.stops
8-
.map((stop) => `${stop.color.value} ${(stop.position.value * 100).toFixed(1)}%`)
8+
.map((stop) => {
9+
const color =
10+
stop.color.kind === "ColorHexLit"
11+
? stop.color.value
12+
: `var(--seed-${stop.color.identifier.replace(/\$/g, "").replace(/\./g, "-")})`;
13+
return `${color} ${(stop.position.value * 100).toFixed(1)}%`;
14+
})
915
.join(", ");
1016
return `linear-gradient(to right, ${stops})`;
1117
}
1218

1319
// Gradient 정보를 텍스트로 변환하는 함수
1420
function gradientToText(gradient: AST.GradientLit): string {
1521
const stops = gradient.stops
16-
.map((stop) => `${stop.color.value} at ${(stop.position.value * 100).toFixed(1)}%`)
22+
.map((stop) => {
23+
const color = stop.color.kind === "ColorHexLit" ? stop.color.value : stop.color.identifier;
24+
return `${color} at ${(stop.position.value * 100).toFixed(1)}%`;
25+
})
1726
.join(", ");
1827
return `Gradient: ${stops}`;
1928
}

0 commit comments

Comments
 (0)