-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Need a clear description on how to make it work with Style Dictionary #703
Need a clear description on how to make it work with Style Dictionary #703
Comments
I'm documenting this partly for my own reference. Based on https://github.com/six7/figma-tokens-example, it seems the workflow is: # Install deps
npm i -D token-transformer style-dictionary
# export the Figma Tokens' plugin data to a file (e.g. `tokens.json`)
# If one is using themes or Token Sets, I think all of them need to be
# checked before the export occurs
# Transform that JSON file into a tokens JSON file
# that Style Dictionary will understand
token-transformer tokens.json tokens/input.json
# Create a `config.json` file for Style Dictionary
# where that `input.json` file is one of the globs
# that will be consumed by Style Dictionary.
# Also specify one or more platforms
# (e.g. `css` is used below, but others exist)
cat > config.json EOF
{
"source": [
"tokens/input.json"
],
"platforms": {
"css": {
"transformGroup": "css",
"buildPath": "build/",
"files": [
{
"destination": "css/variables.css",
"format": "css/variables"
}
]
}
}
}
EOF
# Run Style Dictionary to create the CSS files
style-dictionary build --config config.json
# View the output
cat build/css/variables.css |
Thanks, @jam-awake , I tried with scss :
So seems that style-dictionary just copy-paste tokens from |
For the shadow properties you need to transform We'll be adding a style dictionary config soon that should help, I'll link it in this issue once we have it! In the meantime here are the transformers I'm using for the things you mentioned:
|
I have a question about how to use Let's assume I have 3 token sets: Per # 1. only input/output files specified
token-transformer tokens.json output.json
# 2. specify all sets only
token-transformer tokens.json output.json global,dark,light
# 3. specify all sets with global excluded
token-transformer tokens.json output.json global,dark,light global
# 4. specify global+{theme} set, outputting to {theme}.json
token-transformer tokens.json dark.json global,dark
token-transformer tokens.json light.json global,light
# 5. specify global+{theme} set with global excluded, outputting to {theme}.json
token-transformer tokens.json dark.json global,dark global
token-transformer tokens.json light.json global,light global Which of these 5 (assuming there aren't any others) is correct? |
4, 5 would be correct for what you want to do. The others include both dark and light as sources (the equivalent of ticking all checkboxes in Figma Tokens) The others would work, but would not produce the result you're after (as light would override dark and thus only out put that) |
@six7 Thanks for your help. So in my case, I decided to go with another approach. Also, @six7 do you have any specs for token values produced by the Figma plugin. For example for |
Hello @AndriiMatkivskyiSecurrency 👋 I'm interesting in your custom transformer. Is it possible for you to share it ? 🙏 I'm too struggling a bit with FigmaTokens "types" that not match the "CTI" structure used by StyleDictionary. For example, the equivalent of this FigmaTokens export : {
"core": {
"m": {
"value": "16",
"type": "fontSizes"
},
"red": {
"value": "#f00",
"type": "color"
}
}
} would be in StyleDictionnay : {
"size" : {
"core": {
"font": {
"m": {
"value": "16"
}
}
}
},
"color": {
"core": {
"red": {
"value": "#f00"
}
}
}
} @six7 , do you have any news about your "style dictionary config" ? 🙏 |
@csaunier It also changes the category of some of the tokens, again to align with StyleDictionary.registerTransform({
name: "attribute/figma_cti",
type: "attribute",
matcher: (token) => true,
transformer: function (token) {
const attrNames = ["type", "item", "subitem", "state"];
const originalAttrs = token.attributes || {};
const generatedAttrs = {};
if (["borderRadius", "borderWidth", "spacing", "fontSizes", "dimension"].includes(token.original.type)) {
generatedAttrs["category"] = "size";
} else if ("typography" == token.original.type) {
generatedAttrs["category"] = "font";
} else if ("opacity" == token.original.type) {
generatedAttrs["category"] = "opacity";
} else if ("transparent" == token.original.type) {
generatedAttrs["category"] = "transparent";
} else {
generatedAttrs["category"] = token.original.type;
}
for (let i = 0; i < token.path.length && i < attrNames.length; i++) {
generatedAttrs[attrNames[i]] = token.path[i];
}
return Object.assign(generatedAttrs, originalAttrs);
},
}); |
@six7 Any updates on this? |
We're about to release this 👍 |
Hey @six7 , any update on this? We can definitely use it to clean up our codebase a bit, to get rid of some fixes like @amatkivskiy his solution |
Closing this as sd-transforms now supports most features token-transformer has supported. Added a page to our docs. |
Describe the bug
I really like this plugin and the ability to export all the tokens. Our design team also wants to use it for our new Design System.
And as I developer I really want to have a way to convert Figma Tokens's json into a code so it can be used directly in the Flutter app code. So I found that [Style Dictionary can do the trick and generate whatever platform code we need.
Also, I found that
token-transformer
was implemented to migrate from FT json format to Style Dictionary json format. And I used it but unfortunately, Style Dictionary generates invalid Flutter code.To Reproduce
Steps to reproduce the behavior:
Figma Tokens
pluginLoad
andApply default preset
tokens.json
token-transformer
intooutput.json
(usingtoken-transformer exported_tokens.json output.json global,light,dark,theme
)style-dictionary
lib/uniqe/style_dictionary.dart
I've uploaded all the related jsons and files here https://gist.github.com/AndriiMatkivskyiSecurrency/be0b2ad78ed5dc15eb6f0d89117eea47
Expected behavior
Mentioned way of working with Figma Tokens and Style Dictionary should work or at least it will be really great to have a clear guide on what should be done to make this work.
Screenshots or Screencasts
Figma file (optional)
I just created a new file and switch to plugin
JSON (optional)
I've attached a link to GithubGist
The text was updated successfully, but these errors were encountered: