diff --git a/__tests__/build.test.js b/__tests__/build.test.js index 5abb0b7..07766a6 100644 --- a/__tests__/build.test.js +++ b/__tests__/build.test.js @@ -18,7 +18,6 @@ describe('index.js', () => { expect(StyleDictionary.transform["shadow/css"]).toBeDefined(); expect(StyleDictionary.transform["font/css"]).toBeDefined(); expect(StyleDictionary.transform["fontFamily/css"]).toBeDefined(); - expect(StyleDictionary.transform["variables/css"]).toBeDefined(); expect(StyleDictionary.transform["fontWeight/number"]).toBeDefined(); expect(StyleDictionary.transform["gradient/css"]).toBeDefined(); expect(StyleDictionary.transform["cubicBezier/css"]).toBeDefined(); diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 3796f9d..6f0ace2 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -26,7 +26,6 @@ describe('index.ts', () => { expect(StyleDictionary.transform['shadow/css']).toBeDefined() expect(StyleDictionary.transform['font/css']).toBeDefined() expect(StyleDictionary.transform['fontFamily/css']).toBeDefined() - expect(StyleDictionary.transform['variables/css']).toBeDefined() expect(StyleDictionary.transform['fontWeight/number']).toBeDefined() expect(StyleDictionary.transform['gradient/css']).toBeDefined() expect(StyleDictionary.transform['cubicBezier/css']).toBeDefined() diff --git a/__tests__/transformer/variables-css.test.ts b/__tests__/transformer/variables-css.test.ts deleted file mode 100644 index 52f95ac..0000000 --- a/__tests__/transformer/variables-css.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import StyleDictionary from "style-dictionary"; -import { variablesCss } from "../../src/transformer/variables-css"; - -describe("Transformer: variablesCss", () => { - const items = [ - { - name: "red", - value: "#ff0000", - }, - { - name: "white", - value: "#ffffff", - }, - ] as StyleDictionary.TransformedToken[]; - - const options = { - cssVarPrefix: "PREFIX", - withValueFallback: true, - }; - - it("transforms names to CSS variable notation", () => { - expect( - items.map((item) => variablesCss.transformer(item, {})) - ).toStrictEqual(["var(--red)", "var(--white)"]); - }); - - it("adds prefix to CSS variable notation", () => { - expect( - items.map((item) => variablesCss.transformer(item, options)) - ).toStrictEqual([ - "var(--PREFIX-red, #ff0000)", - "var(--PREFIX-white, #ffffff)", - ]); - }); -}); diff --git a/src/index.ts b/src/index.ts index 2bd8b75..0d70f48 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,7 +38,6 @@ import { fontWeightToNumber } from './transformer/font-weight-to-number' import { gradientCss } from './transformer/gradient-css' import { namePathToDotNotation } from './transformer/name-path-to-dot-notation' import { shadowCss } from './transformer/shadow-css' -import { variablesCss } from './transformer/variables-css' /** * Parsers @@ -159,11 +158,6 @@ OrigialStyleDictionary.registerTransform({ name: 'border/css', ...borderCss }) - -OrigialStyleDictionary.registerTransform({ - name: 'variables/css', - ...variablesCss -}) /** * Transform groups * diff --git a/src/transformer/variables-css.ts b/src/transformer/variables-css.ts deleted file mode 100644 index a509b6c..0000000 --- a/src/transformer/variables-css.ts +++ /dev/null @@ -1,46 +0,0 @@ -import StyleDictionary from "style-dictionary"; - -interface CssOptions { - cssVarPrefix: string | null; - withValueFallback: boolean | null; -} - -/** - * getCssOptions - * @description get the css options from the options object - */ -function getCssOptions(options: StyleDictionary.Options): CssOptions { - return { - cssVarPrefix: options?.cssVarPrefix || null, - withValueFallback: options?.withValueFallback || null, - }; -} - -/** - * formatCssVariable - * @description format the css variable with prefix and fallback - */ -function formatCssVariable(name: string, value: string, options: CssOptions) { - const varPrefix = options.cssVarPrefix ? `${options.cssVarPrefix}-` : ""; - const fallback = options.withValueFallback ? `, ${value}` : ""; - return `var(--${varPrefix}${name}${fallback})`; -} - -/** - * variablesCss - * @description convert the `name` to a css variable - */ -export const variablesCss: StyleDictionary.Transform = { - type: `value`, - transitive: true, - transformer: ( - token: StyleDictionary.TransformedToken, - options: StyleDictionary.Options - ) => { - const { cssVarPrefix, withValueFallback } = getCssOptions(options); - return formatCssVariable(token.name, token.value, { - cssVarPrefix, - withValueFallback, - }); - }, -};