标签: style-dictionary

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

我有与此线程完全相同的问题:使用样式字典从设计令牌 json 文件中获取 scss。这个线程中提到的答案很好,但是有没有办法指定一些设置,以便样式字典自动将样式对象转换为上述线程中答案中提到的方式?

我基本上想转换

"Display-2xl": {
    "Regular": {
      "value": {
        "fontFamily": "{fontFamilies.inter.value}",
        "fontWeight": "{fontWeights.inter-0.value}",
        "fontSize": "$fontSize.10",
      },
      "type": "typography"
    },
}
Run Code Online (Sandbox Code Playgroud)

"Display-2xl": {
    "Regular": {
      "type": "typography",
      "fontFamily": {
        "value": "{fontFamilies.inter.value}"
      },
      "fontWeight": {
        "value": "{fontWeights.inter-0.value}"
      },
      "fontSize": {
        "value": "{fontSize.10}"
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

通过添加一些格式/转换。我怎样才能实现这个目标?

我的 config.json 对象:

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",
          },
        },
        { …
Run Code Online (Sandbox Code Playgroud)

json sass reactjs style-dictionary design-tokens

5
推荐指数
1
解决办法
1394
查看次数

如何将 json 转换为 style-dictionary 中的 css 类?

我有以下button.json

{
  "component": {
  "button": {
    "padding": { "value": "{size.padding.medium.value}" },
    "font-size": { "value": 2 },
    "text-align": { "value": "center" },
  
    "primary": {
      "background-color": { "value": "hsl(10, 80, 50)" },
      "color": { "value": "{color.font.inverse.value}" }
    },
  
    "secondary": {
      "background-color": { "value": "{color.background.primary.value}" },
      "color": { "value": "{color.font.link.value}" }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用亚马逊样式字典生成样式标记。我想要生成的是 json 中的完整 sass css。

例如:

.component-button {

    padding: " ";
    font-size: " ";

    & .primary {
        background-color: "",
        color: ""
    }
}
Run Code Online (Sandbox Code Playgroud)

css json styles token style-dictionary

1
推荐指数
1
解决办法
2204
查看次数

标签 统计

json ×2

style-dictionary ×2

css ×1

design-tokens ×1

reactjs ×1

sass ×1

styles ×1

token ×1