-
Notifications
You must be signed in to change notification settings - Fork 567
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
feat: add support for !default in SCSS variables format #359
feat: add support for !default in SCSS variables format #359
Conversation
For any token definition that includes the property `themeable: true`, a `!default` will now be added in the scss/variables format. GitHub issue amzn#307
f0e837e
to
12b7754
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR! I really like the idea. I would like to hear what others think about themeable
as the property name. It makes sense to me, but would like to hear other opinions and to also think about how this might be used in other platforms like Android and iOS.
to_ret_prop += (prop.attributes.category==='asset' ? '"'+prop.value+'"' : prop.value); | ||
|
||
if (prop.themeable === true) { | ||
to_ret_prop += ' !default'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function, variablesWithPrefix, is used to generate less and CSS variables as well. Would this addition break those formats? We might need to rethink this function...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. I assumed it was just shared between the different Sass formatters so that's my bad.
It would definitely break both of those other formats without some more work. I could add an additional argument to this function to output Sass-specific properties like !default
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a stab at updating the variablesWithPrefix
function to encapsulate the logic around prefixes, comment formats and !default
. Let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey all, I'm working on adding a custom transform for my DS for this feature and found an edge case with my stuff that I thought I would share because It looks like you might run into the same issue here with the current code. The edge case is when I have this:
// token json file
"content-padding": {
"comment": "The padding around the main content icon and message in the Alert component.",
"value": "{space.m.value} {space.m.value} {space.m.value} {space.misc-a.value}",
"type": "settings",
"themable": true
},
It outputs this:
$sprk-alert-content-padding: 16px !default 16px !default 16px !default 24px !default; // The padding around the main content icon and message in the Alert component.
The !default
gets repeated unless we check for that case and make sure not to repeat it. Thought this might be helpful to y'all! Hope you are having a great week!
themeableScss = formatter(themeableDictionary); | ||
|
||
expect(themeableScss).toMatch("#EF5350 !default;"); | ||
return done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need return done();
here, that is used if the test has some asynchronous code which we do for testing scss/less validity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know! I should have looked more closely at what that was for in the other test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Awesome! Thank you so much for reviewing this. |
+1 for this feature. I'm just getting started w/style dictionary. Good to see @jmmcduffie making it better. Nice work! |
Thanks, @kevinmpowell! I'll be curious to hear what you think of Style Dictionary. |
I think this is a really good direction and important functionality. However, I have two concerns:
Thoughts? |
Your concerns make a ton of sense, @chazzmoney. My hope for this new property was exactly what you suggested in your first point, that other platforms would be able to use the same data with a different implementation. By giving it an open-ended name, my thought was that it would not be viewed as a single-format property and allow new use cases to arise. But I totally get your worry about moving forward without knowing if that will really happen. And I also don't disagree that a better understanding of that would add value to this PR. Do you think that we could still provide that value by doing just enough research to validate that another format could use this? My concern in lumping them together would be that we bloat the scope of this change. And if we determine that it truly is a single-format property, we can course-correct my implementation into something more appropriate. |
For those who are looking for someplace to help out - if you know if there are tags for defaults in the main library formats, we would love to have them added to this. |
We added this PR to the 3.0 branch targeting the next major release (later this year) because it is adding something to the core token object itself. Before releasing 3.0 we want to see how this flag can work in other built-in formats and write some documentation about it. |
Issue #, if available: #307
Description of changes:
This addresses the feature request made in #307 in one way. For my use case I'd like to make some variables "themeable" with
!default
but not all. For example, base colors should be immutable but the default text color could be configurable by the consumer of the design tokens.I chose the key "themeable" because of seeing that language in the design systems community (for example with the Lightning Design System or from Brad Frost). And that way other formats could implement their own version of what theme-ability is.
This doesn't address setting
!default
on all variables through the configuration, but it should be easy enough to add that to what I've implemented.Thanks in advance for considering this PR!
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.