Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composite tokens support for compose. #1272

Open
chinmaym14 opened this issue Jul 10, 2024 · 1 comment
Open

Composite tokens support for compose. #1272

chinmaym14 opened this issue Jul 10, 2024 · 1 comment

Comments

@chinmaym14
Copy link

chinmaym14 commented Jul 10, 2024

Hello,
Below is the style json.

{
  "label": {
    "xsmall": {
      "$type": "typography",
      "$value": {
        "fontFamily": "{font.family.brand}",
        "fontSize": "{font.size.xs}",
        "fontWeight": "{font.weight.regular}",
        "letterSpacing": "4%",
        "lineHeight": "{font.lineHeight.xs}",
        "textTransform": "uppercase",
        "textDecoration": "none"
      }
    }
}

How can i convert this to constants in kotlin? Currently i am using below config file

{
  "source": [
    "tokens/*.json"
  ],
  "preprocessors": ["tokens-studio"],
  "platforms": {
    "js": {
      "buildPath": "build/js/",
      "transformGroup": "scss",
      "files": [
        {
          "destination": "colorpalette.js",
          "format": "javascript/es6"
        }
      ]
    },
    "iOS": {
      "buildPath": "build/ios/",
      "prefix": "",
      "transformGroup": "ios-swift",
      "files": [
        {
          "destination": "colorpalette.swift",
          "format": "ios-swift/any.swift",
          "options": {
            "outputReferences": true
          },
          "className": "colorPalette"
        },
        {
          "destination": "enum.swift",
          "format": "ios-swift/enum.swift"
        }
      ]
    },
    "compose": {
     "transforms": [
        "attribute/cti", "ts/typography/compose/shorthand"
      ],
      "transformGroup": "compose",
      "basePxFontSize": 1,
      "buildPath": "build/compose/",
      "files": [
        {
          "destination": "StyleDictionaryNumber.kt",
          "format": "compose/object",
          "options": {
            "className": "StyleDictionaryNumber",
            "packageName": "StyleDictionaryNumber",
            "outputReferences": true
          },
          "filter": {
            "$type": "number"
          }
        },
        {
          "destination": "StyleDictionaryString.kt",
          "format": "compose/object",
          "options": {
            "className": "StyleDictionaryString",
            "packageName": "StyleDictionaryString",
            "outputReferences": true
          },
          "filter": {
            "$type": "string"
          }
        },
        {
          "destination": "StyleDictionaryColorColor.kt",
          "format": "compose/object",
          "options": {
            "className": "StyleDictionaryColorColor",
            "packageName": "StyleDictionaryColorColor",
            "outputReferences": true
          },
          "filter": {
            "$type": "color"
          }
        },
        {
          "destination": "StyleDictionaryDimension.kt",
          "format": "compose/object",
          "options": {
            "className": "StyleDictionaryDimensio",
            "packageName": "StyleDictionaryDimension",
            "outputReferences": true
          },
          "filter": {
            "$type": "dimension"
          }
        },
        {
          "destination": "StyleDictionaryTypography.kt",
          "format": "compose/object",
          "options": {
            "className": "StyleDictionaryTypography",
            "packageName": "StyleDictionaryTypography",
            "outputReferences": true
          },
          "filter": {
            "$type": "typography"
          }
        }
      ]
    }
  }
}

But i am getting [object Object] as value in output. How can i resolve this?

@jorenbroekema
Copy link
Collaborator

jorenbroekema commented Jul 12, 2024

https://v4.styledictionary.com/reference/config/#expand you should probably use Style Dictionary's expand utility to expand composite tokens into separate tokens for each property. This can be done both on a global level or on a per platform basis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants