Open rganko opened 1 year ago
Hey @rganko happy to accept a PR to deal with spaces. But I think it should be already working the way it does now, or do you experience a bug?
For the modes, the way you suggest is pretty uncommon. What we currently do is also not great. The best option would be to export one file per mode, but I am not sure if this is technically possible.
Mode should not be in the token name at all, as this breaks a lot of the magic of tokens, but for this we need multiple files e.g. dark.json
and light.json
with the same token (but different values) inside, e.g. tokens.bg
(no mode reference.)
I'd love to better understand why one particular mode is included in the referenced name rather that removing it entirely. For a user with multiple modes for component tokens, won't there only ever be one mode with correct references? While the rest would always be wrong?
I'm running into something very similar to the problem mentioned above, except my primitive and component token collections both have a matching set of modes and there's still only one mode ever included in the referenced primitive names. I was also was hoping for the proposed output @rganko provided, but removing the mode from the name entirely seems like it would be almost equally helpful. Is the current functionality, where 'mode 2' (whichever Figma mode is listed last) is included in referenced token names regardless of their mode, the intended functionality for the foreseeable future? (Assuming there aren't significant changes made in how Figma does things.)
I'm fine writing some extra code to work around some of this, I was assuming I'd have to be using the JSON structure to make some of this work (top level as collections, second level as modes) - but also having to strip out one particular mode name from all referenced primitives feels awfully bad to me. I'm trying to figure out if my structure is fundamentally incompatible with this plugin and standard use cases, or if we're just in a temporary weird spot because variables are relatively new and things are likely to keep changing.
To be clear we are on the same page here let's compere JSON structure we've got. Based on today's results from figma using Design Tokens plugin.
Note: For single mode every thing works great (thank you for your work).
In case of having another mode (light, dark), json structure seams to consider only last one from all of the modes that are available. See json below - token's path only considers dark
mode.
"primitives": {
"light": {
"white-01": {
"type": "color",
"value": "#ffffffff",
"blendMode": "normal"
}
},
"dark": {
"white-01": {
"type": "color",
"value": "#000000ff",
"blendMode": "normal"
}
}
},
"tokens": {
"header-bg": {
"type": "color",
"value": "{primitives.dark.white-01}"
}
}
}
It might look broken since there is no easy way to get primitives.light.white-01
. The fact that only last one of used aliases are considered seems to be not that obvious.
And now the questions:
primitives.dark.white-01
) ?@rganko I am not sure if you wrote the code above as an example only, but if it is not I feel like you can solve your problem by restructuring your Figma variable setup. I'd recommend using the global collection without any mode, there you define all of your colors (and more in general, any other basic value for your setup).
After this you can create a different collection, there you can add as many modes as you like and use the variables you defined in the primitives collection to set up the different modes.
This should solve your problem, plus, allow you to use better semantical variable names (in your example, "dark" mode has a variable called "white-01" which is set to the opposite of white!).
so you'll get to have something like:
{
"primitives": {
"colors": {
"white": "#fff",
"black": "#000"
}
},
"colors": {
"light": {
"primary": {
"type": "color",
"value": "{primitives.color.light}"
},
"secondary": {
"type": "color",
"value": "{primitives.color.dark}"
}
},
"dark": {
"primary": {
"type": "color",
"value": "{primitives.color.black}"
},
"secondary": {
"type": "color",
"value": "{primitives.color.light}"
}
}
},
"tokens": {
"light": {
"header-bg": {
"type": "color",
"value": "{primitives.primary}"
}
},
"dark": {
"header-bg": {
"type": "color",
"value": "{primitives.secondary}"
}
}
}
}
Having two modes for
primitives
collection ("Mode 1", "Mode 2"), I can see only one of defined modes for other collection, that uses primitives as reference.Current exported json output: