diff --git a/packages/export-variables-rest-api/src/__tests__/tokenUtils.spec.ts b/packages/export-variables-rest-api/src/__tests__/tokenUtils.spec.ts index 57efa63..3db1d12 100644 --- a/packages/export-variables-rest-api/src/__tests__/tokenUtils.spec.ts +++ b/packages/export-variables-rest-api/src/__tests__/tokenUtils.spec.ts @@ -67,6 +67,18 @@ describe("generateCssFromJson", () => { --prefix-c-withReferenceValue: var(--prefix-a-with6DigitHex);` ); }); + + test("generates css with rgbaFormat when provided", () => { + const generatedCss = generateCssFromJson( + JSON.stringify(sampleValidColorToken), + { rgbaFormat: true } + ); + expect(generatedCss).toEqual( + `--a-with6DigitHex: rgb(18, 52, 86); +--b-withAlphaHex: rgba(18, 52, 86, 0.47); +--c-withReferenceValue: var(--a-with6DigitHex);` + ); + }); }); describe("number tokens", () => { diff --git a/packages/export-variables-rest-api/src/tokenUtils.ts b/packages/export-variables-rest-api/src/tokenUtils.ts index 1d366a8..7951196 100644 --- a/packages/export-variables-rest-api/src/tokenUtils.ts +++ b/packages/export-variables-rest-api/src/tokenUtils.ts @@ -61,7 +61,7 @@ export function parseTokenObject(tokenObj: object) { return parseResult; } -type CssGenOption = { prefix?: string }; +type CssGenOption = { prefix?: string; rgbaFormat?: boolean }; export function generateCssFromJson( inputJson: string, option: CssGenOption = {} @@ -78,7 +78,7 @@ export function generateCssFromJson( if ($type === "color") { const css = formatCssLine( formatCssVarDeclaration(keys, prefix), - formatCssVarColorValue($value, prefix, true) + formatCssVarColorValue($value, prefix, option.rgbaFormat) ); // console.debug("new color css", keys, css); allCss.push(css);