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

Feature request: Support of variables #248

Open
annerchrt opened this issue Jun 28, 2023 · 22 comments
Open

Feature request: Support of variables #248

annerchrt opened this issue Jun 28, 2023 · 22 comments

Comments

@annerchrt
Copy link

Hey there! As you probably know, Figma introduced variables. Will the plugin support the export of these variables in the near future?

@lukasoppermann
Copy link
Owner

Hey, there are many plugins that export tokens already. Figma even has a sample plugin that exports tokens: https://github.com/figma/plugin-samples/tree/master/variables-import-export

I don't really see what value the plugin could bring over those other plugins.

@caoimghgin
Copy link

@lukasoppermann I actually like the plugin you wrote best. Simple, fast. Very modifiable. I'd add a feature or two (and push up as a PR for such things), but it's my go-to solution, and I prefer small apps I can string together to make the big thing I want to have.

QUESTION: Do you see any inherent value in the addition of Variables in Figma or supporting them for export of tokens? I'm not finding the value add particularly obvious at the moment.

@StephanLoewe
Copy link

I would like to see it too. As of right now, it's the most comprehensive solution, where I can export Font-Styles, and Color-Styles, all at the same time, and convert in Style Dictionary in a single file.

@annerchrt
Copy link
Author

+1, @StephanLoewe ! It would be convenient to have all exports in one click. Also, the sample plugin by Figma only works with the Enterprise Plan, as far as I know.

@lukasoppermann
Copy link
Owner

lukasoppermann commented Jul 7, 2023

Hey, I am investigating it. I do understand the benefit of getting variables exported in the same manner as the other tokens.

This feature will only be added to the w3c export though. For anybody who is not on w3c tokens yet, this package I am also working on may help: https://github.com/lukasoppermann/style-dictionary-utils

@StephanLoewe
Copy link

That's great news! I think building the feature only on the w3c export is fair enough. I was wondering why Style Dictionary still doesn't support it yet. Didn't realize you build "style-dictionary-utils". Will definetly try it out to implement in the build process.

@lukasoppermann lukasoppermann mentioned this issue Jul 11, 2023
1 task
@lukasoppermann
Copy link
Owner

Hey folks, so the beta for variables is out. Please let me know if it works for you.

Note it only works in w3c standard tokens

@marcuzgabriel
Copy link

marcuzgabriel commented Jul 18, 2023

Hey @lukasoppermann. I have created an internal plugin for a a rather big project that has an extensive variables setup with Figma already. Derived variables / ALIAS namings etc. that has to be distributed out to different Github repositories with the click of a button. I gladly show you how it works if it can provide any value towards your quest of supporting variables.

...And by the way: looking at your PR (#249) it surely looks like we went for the same approach 🥇.

@lukasoppermann
Copy link
Owner

Hey @marcuzgabriel,

thanks, but the PR you point to is already the implementation.

The complex part is not the variables itself, but adding it into a complex plugin like this was. But since it is done now, it should be all fine.

@MikolajKakol
Copy link

Hi, great work it really inspired me to dive a bit into style-drirectory. I tried it on my project and it didn't produce entirely valid output. In Figma, I have two collections primitives and tokens.

image

I don't know much about style-dictionary. However, as you see in tokens it tries to reference {Primitives.Primary/04} but in primitives the letter case is different. I also tried to run this json:

➜  style_dictionary style-dictionary build

flutter

Property Reference Errors:
Reference doesn't exist: tokens.light.bg.pressed.value tries to reference Primitives.Primary/04, which is not defined
Reference doesn't exist: tokens.light.bg.primary.value tries to reference Primitives.Primary/05, which is not defined

So I'm guessing there is something off.

@exhtml
Copy link

exhtml commented Jul 27, 2023

Hi folks! Same problem than @MikolajKakol over here. I was testing the plugin exporting only Figma Variables and seems that something doesn't get properly transformed between Variable Collection names. In my case I have my collections like these and they get exported as shown in the image:

image

As I've said I'm only exporting Figma Variables:

image

I've tried different configurations of settings with no luck:

image

Thank you very much for your work!

@exhtml
Copy link

exhtml commented Jul 28, 2023

Hi! following from the previous post, I've fixed the references to the correct collection names/nesting and executed the transformation. What I've seen is that Primitive Collection values get transformed propertly (as tokens are of "type": "color", but the Semantic Collection ones don't get transformed and are missing, as they are of "type": "alias" in the JSON.

If I change the type to "color" they get properly transformed, but they get the computed value:

--primitive-color-mode-1-colors-red-600: rgb(218, 41,28);
--semantic-color-light-brand-tiba-red-tr-600: rgb(218, 41,28);

wouldn't be nice if the references could be kept? like this:

--primitive-color-mode-1-colors-red-600: rgb(218, 41,28);
--semantic-color-light-brand-tiba-red-tr-600: var(--primitive-color-mode-1-colors-red-600);

:)

@exhtml
Copy link

exhtml commented Jul 28, 2023

Another thing I've seen is that variables of type "size" doesn't get converted unless you add this type to the StyleDictionary.registerFilter in transformTokens.js. It should be included I guess.

Edit: I see that in reality what should be fixed is that sizing variables should be exported as "type": "dimension", that is the correct syntax already included in StyleDictionary.registerFilter

@lukasoppermann
Copy link
Owner

Okay, here are some updates: https://github.com/lukasoppermann/design-tokens/releases/tag/v6.8.4

Please let me know how this is working for you.

@exhtml
Copy link

exhtml commented Jul 31, 2023

Hi Lukas! Thanks for your answer and the updates. I've tested it (only exporting 'Figma Variables') but the plugin freezes when clicking on 'Save & Export'. It throws an error in the console:
Cannot read properties of undefined (reading 'value').
Let me know if I can help providing more information.

Thank you very much for your time!

@dj-kmuldoon
Copy link

Hello! I believe I have a solution for 'Cannot read properties of undefined (reading 'value') issue.

Screenshot 2023-08-03 at 8 00 15 AM

Simply check if the value is a string (not an object). If true, then it's a variable.

@dj-kmuldoon
Copy link

I think we'd be safe to drop 'Mode 1' from the path via export. If the length of Variable collection modes === 1, no need to include 'Mode 1' (or whatever it is named) in the path. Else, we need it to point to dark/light/contrast modes. Besides, StyleDictionary wouldn't be able to naturally link if we did not drop 'Mode 1' since the alias ref doesn't include it on output.

@dj-kmuldoon
Copy link

Screenshot 2023-08-03 at 8 18 20 AM

@dj-kmuldoon
Copy link

Lastly, should we consider appending 'Variables' to the top much like we do for 'Styles' (color, gradient, font, typography, etc). This feels a bit scattered to me (My variable collections are 'palette, contextual, definitive'). Seems we'd want that to be 'variables/palette', etc.
Screenshot 2023-08-03 at 8 22 01 AM

@OmarJalilo
Copy link

I added a new discussion here

@lukasoppermann
Copy link
Owner

Sorry to come back to this so late.

Hello! I believe I have a solution for 'Cannot read properties of undefined (reading 'value') issue.

@dj-kmuldoon is this still an issue?

@dj-kmuldoon
Copy link

@lukasoppermann Suspect not, if nobody else is reporting. I've forked off and have since forgotten about the solution.

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

No branches or pull requests

9 participants