-
Notifications
You must be signed in to change notification settings - Fork 69
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
[BD-46] feat: refactoring design tokens folders structure #2069
[BD-46] feat: refactoring design tokens folders structure #2069
Conversation
Thanks for the pull request, @PKulkoRaccoonGang! When this pull request is ready, tag your edX technical lead. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## alpha #2069 +/- ##
=======================================
Coverage 90.77% 90.77%
=======================================
Files 213 213
Lines 3501 3501
Branches 843 843
=======================================
Hits 3178 3178
Misses 315 315
Partials 8 8 ☔ View full report in Codecov by Sentry. |
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.
Looking good! I left a few comments; biggest feedback is that it looks like the new token files may be missing type
attributes (and possibly other things?) that were in the original tokens.
tokens/sass-helpers.js
Outdated
@@ -14,7 +14,7 @@ const chroma = require('chroma-js'); | |||
* @return chroma-js color instance (one of dark or light variants) | |||
*/ | |||
function colorYiq(color, light, dark, threshold) { | |||
const defaultsFile = fs.readFileSync(path.resolve(__dirname, 'src', 'global', 'other.json'), 'utf8'); | |||
const defaultsFile = fs.readFileSync(path.resolve(__dirname, 'src', 'themes/light/global', 'other.json'), 'utf8'); |
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.
[curious] Is everything in the other.json
file specific to the light theme variant? Or are some of the properties, possibly like theme-interval
, and yiq-contrasted-threshold
.
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.
yes, theme-interval
and yiq-contrasted-threshold
are not theme-specific, moved the to the core
tokens
tokens/sass-helpers.js
Outdated
@@ -14,7 +14,7 @@ const chroma = require('chroma-js'); | |||
* @return chroma-js color instance (one of dark or light variants) | |||
*/ | |||
function colorYiq(color, light, dark, threshold) { | |||
const defaultsFile = fs.readFileSync(path.resolve(__dirname, 'src', 'global', 'other.json'), 'utf8'); | |||
const defaultsFile = fs.readFileSync(path.resolve(__dirname, 'src', 'themes/light/global', 'other.json'), 'utf8'); |
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.
[question] If/when we have a dark theme variant, I wonder if there is a way we might be able to future proof this colorYiq
helper function to support multiple theme variants later on (e.g., pulling from themes/dark/global/other.json
to generate a dark.css
output)?
The approach we're opting to take here is to have a light.css
and dark.css
output file, which would be generated by running the StyleDictionary.buildAllPlatforms()
twice: once with the light theme variant tokens, and again with the dark theme variant tokens. If there's a way to pass in the current theme variant being used into the colorYiq
that might be one approach to take here. Open to other ideas of course!
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.
Makes sense, I've modified our functions to check whether token belongs to any theme and take theme's colors instead (defaults to light
)
{ | ||
"elevation": { | ||
"annotation": { | ||
"box-shadow": { |
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.
It looks like the type
attribute in these tokens might have gotten lost somehow (in the original, now-deleted Annotation.json, the type
attributes are there. I wonder if it may be related to the issues we ran into trying to get alpha
brought in sync with master
that caused us to essentially rewrite the git history for the alpha
branch... It may be worth a check to see if there might be anything else missing in addition to the type
? It does look like this may be an issue in many of the files.
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.
yeah, great catch! we were missing a lot of them... I've added all the missed types, I don't think we're missing anything else
…e in color-yiq function
// find whether token belongs to any theme based on its location | ||
// split full path by '/', check if 'themes' directory is a part of the path, if it is - the next nested | ||
// directory is the theme name, otherwise use 'light' theme | ||
const pathParts = token.filePath.split('/'); | ||
const themePartIndex = pathParts.findIndex(item => item === 'themes'); | ||
const themeVariant = themePartIndex === -1 ? 'light' : pathParts[themePartIndex + 1]; |
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 approach seems reasonable. I'm not sure of an alternative way to pass a theme variant into a custom style-dictionary
transform to avoid needing to parse file paths.
For example, if build-tokens.js
did something like...
const getStyleDictionaryConfig = (themeVariant) => {
const { buildDir, source: tokensSource } = program.opts();
const source = tokensSource ? [tokensSource] : [];
// Could we pass `themeVariant` arg into the config/transform somehow?
const config = {
include: [path.resolve(__dirname, 'src/**/*.json')],
// ...
};
return config;
};
const THEME_VARIANTS = ['light'];
THEME_VARIANTS.forEach((themeVariant) => {
const config = getStyleDictionaryConfig(themeVariant);
StyleDictionary.extend(config).buildAllPlatforms();
});
But, I think what you have works just as well for now :)
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.
Hmm, I think we can do something like this, but it will be more complicated. Currently we register our color transform outside of build-tokens.js
file and there is no way to let it know about the theme (style dictionary only passes a token
to the transform func, so it does not know anything about style dictionary config).
We could try to dynamically change the transform function in build-tokens.js
file, something like this
const THEME_VARIANTS = ['light'];
THEME_VARIANTS.forEach((themeVariant) => {
const config = getStyleDictionaryConfig(themeVariant);
StyleDictionary.registerTransform({
name: 'color/sass-color-functions',
transitive: true,
type: 'value',
matcher(token) {
return token.attributes.category === 'color' || token.value?.toString().startsWith('#');
},
transformer: (token) => colorTransform(token, themeVariant) // pass themeVariant to transform function,
});
StyleDictionary.extend(config).buildAllPlatforms();
});
Hopefully re-registering transform doesn't break anything 😅
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.
actually, nevermind... I just saw that you could define transforms directly in the config
object without using registerTransform
method, so we could just use that
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.
Ah, yeah, that should theoretically also work! I defer to you if we want to roll with what you have now in this PR to get this PR merged and treat that refactor as a fast-follow or if we want to try to get that change into this PR before merge.
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 will tackle this as a fast follow in #2014
tokens/sass-helpers.js
Outdated
* @param {String} [themeVariant] - theme variant name that will be used to find default contrast colors | ||
* @param {String} [light] - light color variant, defaults to 'yiq-text-light' | ||
* from ./src/themes/{themeVariant}/other.json | ||
* @param {String} [dark] - dark color variant, defaults to 'yiq-text-dark' | ||
* from ./src/themes/{themeVariant}/other.json |
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.
nit: ./src/themes/{themeVariant}/global/other.json
tokens/sass-helpers.js
Outdated
* @param {String} [light] - light color variant, defaults to 'yiq-text-light' | ||
* from ./src/themes/{themeVariant}/other.json | ||
* @param {String} [dark] - dark color variant, defaults to 'yiq-text-dark' | ||
* from ./src/themes/{themeVariant}/other.json |
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.
[clarification] I don't think the theme variants are necessarily defaulting to yiq-text-light
or yiq-text-dark
depending on the theme variant itself. That choice depends on the color
being modified (yiq-ified? 😅).
Should the JSDoc comment here just reference that the light
theme pulls both yiq light/dark values from the other.json
file in light
or dark
folder, respectively, without an explicit mention of yiq-text-light
or yiq-text-dark
here?
@PKulkoRaccoonGang 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
🎉 This PR is included in version 21.0.0-alpha.15 🎉 The release is available on: Your semantic-release bot 📦🚀 |
* feat: refactoring design tokens folders structure * fix: add missing "type" attribute to tokens and consider token's theme in color-yiq function * docs: update docstring for colorYiq function --------- Co-authored-by: Viktor Rusakov <[email protected]>
* feat: refactoring design tokens folders structure * fix: add missing "type" attribute to tokens and consider token's theme in color-yiq function * docs: update docstring for colorYiq function --------- Co-authored-by: Viktor Rusakov <[email protected]>
🎉 This PR is included in version 22.0.0-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 23.0.0-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
* feat: refactoring design tokens folders structure * fix: add missing "type" attribute to tokens and consider token's theme in color-yiq function * docs: update docstring for colorYiq function --------- Co-authored-by: Viktor Rusakov <[email protected]>
* feat: refactoring design tokens folders structure * fix: add missing "type" attribute to tokens and consider token's theme in color-yiq function * docs: update docstring for colorYiq function --------- Co-authored-by: Viktor Rusakov <[email protected]>
* feat: refactoring design tokens folders structure * fix: add missing "type" attribute to tokens and consider token's theme in color-yiq function * docs: update docstring for colorYiq function --------- Co-authored-by: Viktor Rusakov <[email protected]>
* feat: refactoring design tokens folders structure * fix: add missing "type" attribute to tokens and consider token's theme in color-yiq function * docs: update docstring for colorYiq function --------- Co-authored-by: Viktor Rusakov <[email protected]>
🎉 This PR is included in version 23.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Issue: #2017
Merge Checklist
example
app?wittjeff
andadamstankiewicz
as reviewers on this PR.Post-merge Checklist