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

feat: registers sd-transforms; includes refs in source-tokens-only output; resolves refs warnings #3219

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

adamstankiewicz
Copy link
Member

@adamstankiewicz adamstankiewicz commented Sep 7, 2024

Description

  1. Integrates style-dictionary with sd-transforms (GitHub) from Tokens Studio. Enables support for copying exported tokens from the Tokens Studio plugin in Figma and adding them to the Paragon tokens schema.
  2. Registers a custom transform group paragon-css to abstract away our custom transforms, sd-transforms, and the default CSS transforms. The previously excluded size/rem filter for the default CSS transforms is added back in.
  3. Resolves noisy warnings regarding missing output references in resulting token transforms, by now including the reference token(s) in the output. See screenshots below.
    • In Paragon, this use case applies when transforming light theme variant tokens that reference core tokens. Now, these handful referenced core tokens are included in the light theme CSS variables, although duplicative of their definitions in core.css; this is an acceptable tradeoff to remove noisy, disruptive warnings as it only expands the contents of output files by the number of referenced tokens.
    • In brand packages (e.g., @edx/elm-theme), this use case applies when either core and/or light tokens reference base, default Paragon tokens without redefining the base token within the brand package. Now, the referenced default Paragon token(s) are included in the brand package output.
  4. Adds build-tokens:watch NPM script to automatically execute the build-tokens CLI on file changes, enabling more rapid development when changing tokens and verifying output without having to manually re-run build-tokens yourself.

Deploy Preview

Resolves output references warning in build output

Related to (3) above. Paragon tokens output on left; brand package tokens output on right (see related @edx/elm-theme PR).

Before

image

After

image

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Netlify deploy preview, if applicable.
  • Does your change adhere to the documented style conventions?
  • Do any prop types have missing descriptions in the Props API tables in the documentation site (check deploy preview)?
  • Were your changes tested using all available themes (see theme switcher in the header of the deploy preview, under the "Settings" icon)?
  • Were your changes tested in the example app?
  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please request an a11y review for the PR in the #wg-paragon Open edX Slack channel.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

Copy link

codecov bot commented Sep 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.76%. Comparing base (029325a) to head (fbb084b).
Report is 1 commits behind head on Peter_Kulko/style-dictionary-v4.

Additional details and impacted files
@@                       Coverage Diff                        @@
##           Peter_Kulko/style-dictionary-v4    #3219   +/-   ##
================================================================
  Coverage                            93.76%   93.76%           
================================================================
  Files                                  229      229           
  Lines                                 3784     3784           
  Branches                               879      906   +27     
================================================================
  Hits                                  3548     3548           
+ Misses                                 232      229    -3     
- Partials                                 4        7    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adamstankiewicz adamstankiewicz force-pushed the ags/sd-transforms branch 5 times, most recently from 5289111 to 97c585b Compare September 7, 2024 14:10
@@ -82,7 +84,6 @@ async function buildTokensCommand(commandArgs) {
},
},
],
transforms: StyleDictionary.hooks.transformGroups.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'),
Copy link
Member Author

@adamstankiewicz adamstankiewicz Sep 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] abstracted into transformGroup: 'paragon-css', although the default CSS transform size/rem is now included, instead of filtered like here.

It seems the primary reason it was filtered out was due to tokens that defined a number while having a $type: "dimension" instead of $type: "number". Ensuring the number type keeps the number value with appending rem as expected, e.g.

--pgn-spacing-card-columns-count: 3;

@@ -36,26 +36,26 @@
--pgn-transition-base: all .2s ease-in-out; /* Generic transition for any property change */
--pgn-transition-progress-bar-bar-transition: width .6s ease;
--pgn-transition-progress-bar-bar-animation-timing: 1s linear infinite;
--pgn-transition-form-control: background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
--pgn-transition-form-input: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
--pgn-transition-form-control: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] sd-transforms includes a transform to add leading zeros where previously missing.

--pgn-typography-line-height-sm: 1.5; /* Small line height. */
--pgn-typography-line-height-lg: 1.5; /* Large line height. */
--pgn-typography-line-height-base: 1.5556; /* Basic line height. */
--pgn-typography-font-weight-display-4: var(--pgn-typography-font-weight-bold); /* Font weight of display level 4. */
--pgn-typography-font-weight-display-3: var(--pgn-typography-font-weight-bold); /* Font weight of display level 3. */
--pgn-typography-font-weight-display-2: var(--pgn-typography-font-weight-bold); /* Font weight of display level 2. */
--pgn-typography-font-weight-display-1: var(--pgn-typography-font-weight-bold); /* Font weight of display level 1. */
--pgn-typography-font-weight-table-th: bold; /* Table th font weight. */
--pgn-typography-font-weight-table-th: 700; /* Table th font weight. */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] sd-transforms changes bold to the corresponding, explicit font weight.

@adamstankiewicz adamstankiewicz marked this pull request as ready for review September 7, 2024 14:11
@@ -56,9 +57,14 @@ async function buildTokensCommand(commandArgs) {
source: tokensSource
? [`${tokensSource}/core/**/*.json`, `${tokensSource}/core/**/*.toml`]
: [],
preprocessors: ['tokens-studio'],
expand: {
typesMap: (await getTokensStudioTransforms()).expandTypesMap,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] See sd-transforms README for more information on expandTypesMap for expand.

Copy link
Member Author

@adamstankiewicz adamstankiewicz Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relates to #3222

@@ -15,7 +15,7 @@
},
"columns": {
"margin": { "source": "$card-columns-margin", "$value": "{spacing.card.spacer.y}" },
"count": { "source": "$card-columns-count", "$value": "3" },
"count": { "source": "$card-columns-count", "$value": "3", "$type": "number" },
Copy link
Member Author

@adamstankiewicz adamstankiewicz Sep 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] Bug fix around $type for a number value, as this token does not define a dimension type currently defined above.

@adamstankiewicz adamstankiewicz force-pushed the ags/sd-transforms branch 2 times, most recently from 4edbef8 to 644bb59 Compare September 7, 2024 21:56
Comment on lines -333 to -339
themes.forEach((themeVariant) => {
StyleDictionary.registerFilter({
name: `isThemeVariant.${themeVariant}`,
filter: token => token.filePath.includes(themeVariant),
});
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] Duplicate. Already defined in paragonFilters above.

@adamstankiewicz adamstankiewicz force-pushed the ags/sd-transforms branch 3 times, most recently from 27191be to e07b067 Compare September 7, 2024 23:05
@adamstankiewicz adamstankiewicz marked this pull request as draft September 7, 2024 23:33
@adamstankiewicz adamstankiewicz marked this pull request as ready for review September 8, 2024 12:42
@adamstankiewicz adamstankiewicz changed the title feat: registers Tokens Studio transforms; build-tokens:watch NPM script feat: registers sd-transforms; includes refs in source-tokens-only output; resolves refs warnings Sep 8, 2024
@@ -56,9 +57,14 @@ async function buildTokensCommand(commandArgs) {
source: tokensSource
? [`${tokensSource}/core/**/*.json`, `${tokensSource}/core/**/*.toml`]
: [],
preprocessors: ['pgn-annotate-token-extensions-with-references', 'tokens-studio'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] See docs on preprocessors. pgn-annotate-tokens-with-references is custom.

See sd-transforms README for more information on the tokens-studio preprocessor.

@@ -3,7 +3,7 @@
"$type": "dimension",
"breakpoint": {
"xs": {
"$value": "0",
"$value": "0px",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform] Ensures consistency in unit with other breakpoints.

Comment on lines +78 to +81
'org.openedx.paragon': {
...referencedToken.$extensions?.['org.openedx.paragon'],
[propertyName]: true,
},
Copy link
Member Author

@adamstankiewicz adamstankiewicz Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://tr.designtokens.org/format/#extensions for more details about $extensions. It's being used in this implementation to help include references tokens in build output, even if the original filtering doesn't apply.

E.g.,

{
  // token metadata like $value, etc.
  $extensions: {
    'org.openedx.paragon': {
      isReferencedBySourceToken: bool, // useful to include referenced non-source tokens alongside source-only tokens
      isReferencedByThemeVariant: bool, // useful to include referenced non-theme variant tokens alongside theme variant tokens
    },
  },
}

This is the "magic" behind suppressing the (intentional) previous output reference warnings during build.

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks great! I'd be a bit more confident if there were some tests for the new functions in utils.js, but I'm on the fence about that being a blocking requirement. There might be other things that have already landed in the design tokens branch that might be missing tests, and in that case I think making an issue to add tests and just adding this new functions to the list of tests to add could work.

tl;dr

  • Looks good!
  • Tests?
  • Should probably comb through all of the new design tokens functionality and see if there are untested places we should add tests (out of scope for this PR)

@adamstankiewicz
Copy link
Member Author

@brian-smith-tcril Thanks for the review! Agreed the lack of tests isn't ideal to ensure confidence in changes. However, as far as I can tell, there are no current tests for any of the logic defined in the tokens folder (inclusive of but not limited to the utils.js file), e.g. the base style-dictionary config, custom transforms/formatters, etc. Given this, I agree with the sentiment to tackle tests as a standalone issue/task separate from this PR.

@brian-smith-tcril
Copy link
Contributor

I made an issue for adding tests #3229, we can add to it as we find places where tests are missing.

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@adamstankiewicz adamstankiewicz merged commit daffd74 into Peter_Kulko/style-dictionary-v4 Sep 9, 2024
6 checks passed
@adamstankiewicz adamstankiewicz deleted the ags/sd-transforms branch September 9, 2024 18:58
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

Successfully merging this pull request may close these issues.

3 participants