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

fix(generate tokens): prefix tokens with a t_ #11002

Merged
merged 5 commits into from
Sep 18, 2024

Conversation

tlabaj
Copy link
Contributor

@tlabaj tlabaj commented Sep 13, 2024

What: Closes #10985

A issue was noticed that react-token created chart token exports that differed by one uppercase character. example
export { chart_global_label_Margin } from './chart_global_label_Margin'; export { chart_global_label_margin } from './chart_global_label_margin';

To test pull down this branch, build and look at the react-tokens dist directory.

eg. of token before change
image

after change

image

@thatblindgeye could we write code mod for this?

@patternfly-build
Copy link
Contributor

patternfly-build commented Sep 13, 2024

@tlabaj tlabaj marked this pull request as draft September 13, 2024 19:19
Copy link
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

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

LGTM! I did have to do a search and replace for @patternfly/react-tokens/dist/esm/global_ with @patternfly/react-tokens/dist/esm/t_global_ in react-core/src and react-charts/src to get the build to work but the t_* tokens look to have all generated correctly 👍

@@ -10,7 +10,7 @@ const version = 'v6';

// Helpers
const formatCustomPropertyName = (key) =>
key.replace(`--pf-${version}-`, '').replace('--pf-t--', '').replace(/-+/g, '_');
key.replace(`--pf-${version}-`, '').replace('--pf-t--', 't_').replace(/-+/g, '_');
Copy link
Member

@dlabrecq dlabrecq Sep 16, 2024

Choose a reason for hiding this comment

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

I'm curious why the version has been removed?

Copy link
Member

@dlabrecq dlabrecq Sep 16, 2024

Choose a reason for hiding this comment

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

I built this branch locally and react-tokens still generates duplicates. The only difference now is one file is prefixed with "t_".

For example:
packages/react-tokens/dist/esm/chart_global_label_Margin.js
packages/react-tokens/dist/esm/t_chart_global_label_margin.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dlabrecq the packages/react-tokens/dist/esm/chart_global_label_Margin.js is the variable.
the packages/react-tokens/dist/esm/t_chart_global_label_margin.js is the token.

@mcoker can add more context from a css perspective as to why they are named the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @dlabrecq. The original bug is because the PF CSS has variables named very similarly like these two - --pf-v6-chart-global--label--Margin and --pf-t--chart--global--label--margin. The react-tokens package parses the PF CSS, finds all of our variables, and creates a react-token for each one with a name based based off of what the CSS variable name is. Most of the PF CSS vars fit into 4 categories:

  • Components - --pf-v6-c-[component] creates a react token like c_[component]
  • Layouts - --pf-v6-l-[layout], creates l_[layout]
  • Charts - --pf-v6-chart-[color/global/axis/bar/etc], creates chart_[color/global/axis/bar/etc]
  • Tokens, aka global vars - --pf-t--[color/global/chart/etc], creates [color/global/chart/etc]_

So for the vars reference above, --pf-v6-chart-global--label--Margin and --pf-t--chart--global--label--margin, the resulting tokens are chart_global_label_Margin and chart_global_label_margin. There are a bunch of ways we could address that, but since the CSS token vars (--pf-t--[...]) are always prefixed with -t--, prefixing the react token filename with t_[...] solves this problem and follows the format of other prefixed vars/tokens in PF (--pf-v6-c and --pf-v6-l).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. I didn't realize we wanted to expose both tokens and variables in this package

Copy link
Member

@evwilkin evwilkin left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the notes on testing and the additional context from @mcoker

@dlabaj
Copy link
Contributor

dlabaj commented Sep 17, 2024

@tlabaj Can you link the org PR and then we can merge this.

@dlabaj dlabaj merged commit 0dac6b8 into patternfly:main Sep 18, 2024
13 checks passed
@patternfly-build
Copy link
Contributor

Your changes have been released in:

  • @patternfly/react-charts@8.0.0-prerelease.9
  • @patternfly/react-code-editor@6.0.0-prerelease.12
  • @patternfly/react-core@6.0.0-prerelease.12
  • @patternfly/react-docs@7.0.0-prerelease.20
  • @patternfly/react-drag-drop@6.0.0-prerelease.12
  • @patternfly/react-integration@6.0.0-prerelease.5
  • demo-app-ts@6.0.0-prerelease.14
  • @patternfly/react-table@6.0.0-prerelease.12
  • @patternfly/react-templates@6.0.0-prerelease.12
  • @patternfly/react-tokens@6.0.0-prerelease.4

Thanks for your contribution! 🎉

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.

generateTokens script should prfeix tokens with t
6 participants