首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用样式字典将设计令牌对象转换为SCSS属性?

如何使用样式字典将设计令牌对象转换为SCSS属性?
EN

Stack Overflow用户
提问于 2022-06-02 12:15:21
回答 1查看 575关注 0票数 4

我有一个与这个线程完全相同的问题:get scss from design tokens json file using style dictionary。这个线程中提到的答案是很好的,但是是否有一种方法来指定某种设置,以便样式字典自动地将样式对象转换为在所述线程中的答案中提到的方式?

我基本上是想转换

代码语言:javascript
复制
"Display-2xl": {
    "Regular": {
      "value": {
        "fontFamily": "{fontFamilies.inter.value}",
        "fontWeight": "{fontWeights.inter-0.value}",
        "fontSize": "$fontSize.10",
      },
      "type": "typography"
    },
}

代码语言:javascript
复制
"Display-2xl": {
    "Regular": {
      "type": "typography",
      "fontFamily": {
        "value": "{fontFamilies.inter.value}"
      },
      "fontWeight": {
        "value": "{fontWeights.inter-0.value}"
      },
      "fontSize": {
        "value": "{fontSize.10}"
      }
    }
  }

通过添加某种格式/转换。我怎样才能做到这一点?

我的config.json对象:

代码语言:javascript
复制
const StyleDictionary = require("style-dictionary").extend({
  source: ["./tokens.json"],
  platforms: {
    scss: {
      transformGroup: "scss",
      buildPath: "src/tokens/",
      files: [
        {
          destination: "_colors.scss",
          format: "scss/variables",
          filter: {
            type: "color",
          },
        },
        {
          destination: "_shadows.scss",
          format: "scss/variables",
          filter: {
            type: "boxShadow",
          },
        },
        {
          destination: "_fontFamilies.scss",
          format: "scss/variables",
          filter: {
            type: "fontFamilies",
          },
        },
        {
          destination: "_lineHeights.scss",
          format: "scss/variables",
          filter: {
            type: "lineHeights",
          },
        },
        {
          destination: "_fontWeights.scss",
          format: "scss/variables",
          filter: {
            type: "fontWeights",
          },
        },
        {
          destination: "_fontSizes.scss",
          format: "scss/variables",
          filter: {
            type: "fontSizes",
          },
        },
        {
          destination: "_letterSpacing.scss",
          format: "scss/variables",
          filter: {
            type: "letterSpacing",
          },
        },
        {
          destination: "_paragraphSpacing.scss",
          format: "scss/variables",
          filter: {
            type: "paragraphSpacing",
          },
        },
        {
          destination: "_typography.scss",
          format: "scss/variables",
          filter: {
            type: "typography",
          },
        },
        {
          destination: "_textCase.scss",
          format: "scss/variables",
          filter: {
            type: "textCase",
          },
        },
        {
          destination: "_textDecoration.scss",
          format: "scss/variables",
          filter: {
            type: "textDecoration",
          },
        },
      ],
    },
  },
});

StyleDictionary.buildAllPlatforms();
EN

回答 1

Stack Overflow用户

发布于 2022-06-10 18:01:45

这个问题在我看来是毫无意义的,有关的解决办法已在连结的网站上提及:

代码语言:javascript
复制
  "Display-2xl": {
    " ": { // Has to be a space. This comment also will break json
     value: "PARENT VALUE"
    },
    "Regular": {
      "type": "typography",
      "fontFamily": {
        "value": "{fontFamilies.inter.value}"
      },
      "fontWeight": {
        "value": "{fontWeights.inter-0.value}"
      },
      "fontSize": {
        "value": "{fontSize.10}"
      }
    }
  }

除此之外,json代表一个配置,必须创建,但是从一种json配置格式到另一种json配置格式的转换可能不是框架的一部分,关于这一点,这个问题可能有点误导。

尽管如此,这两种配置都可以使用,并且应该具有相同的结果。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72476128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档