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

[web-components]: remove design token implementation in favor of platform solution #30002

Conversation

chrisdholt
Copy link
Member

Previous Behavior

Previous implementation (WC v2) leveraged the FAST Design token implementation which is helpful when you need to observe values which respond to one another.

New Behavior

With the shift to Fluent 2 tokens which are static and do not need to relate to one another, the implementation can be simplified. This PR removes the design token implementation in favor of platform CSS variables. The current proposal takes into account other long term goals of supporting things like tree shaking tokens, fallback/default values and or tokens, which is why the token names are strings and the variables are set within the components.

This is an initial example of what this could look like - open to feedback.

@fabricteam
Copy link
Collaborator

fabricteam commented Dec 5, 2023

📊 Bundle size report

🤖 This report was generated against 12da47698c9121c0345c2f0db481cbae7a91b66e

@@ -0,0 +1,7 @@
{
Copy link
Collaborator

@fabricteam fabricteam Dec 5, 2023

Choose a reason for hiding this comment

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

🕵 fluentui-web-components-v3 Open the Visual Regressions report to inspect the affected screenshots

Slider 2 screenshots
Image Name Diff(in Pixels) Image Type
Slider.Slider Steps Vertical.normal.chromium.png 1 Changed
Slider.Slider Steps.normal.chromium.png 1 Changed

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks okay to me but I let a WC Codeowner mark this as resolved after reviewing.

Copy link

size-auditor bot commented Dec 5, 2023

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 12da47698c9121c0345c2f0db481cbae7a91b66e (build)

Copy link

codesandbox-ci bot commented Dec 5, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 07cd8a4:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@@ -10,12 +9,12 @@ const tokenNames = Object.keys(tokens) as (keyof Theme)[];
*/
export const setTheme = (theme: Theme) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The great thing about this now, is that we don't need to use this function at all if we can set the tokens we care about in the HTML document directly, since everything uses platform. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

Was that needed previously?

procload
procload previously approved these changes Dec 12, 2023
Copy link
Contributor

@procload procload left a comment

Choose a reason for hiding this comment

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

Didn't realize the screenshots were included in this. Upon review there's a few that are quite different.

@procload procload dismissed their stale review December 12, 2023 18:07

Didn't see the screenshots failing...

color: var(${tokens.colorNeutralForegroundOnBrand});
border: var(${tokens.strokeWidthThicker}) solid var(${tokens.colorNeutralStroke1});
padding: var(${tokens.spacingVerticalS}) var(${tokens.spacingHorizontalM});
box-shadow: var(${tokens.shadow28});
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to grab named exports here?

export const shadow8Brand = '--shadow8Brand';
export const shadow16Brand = '--shadow16Brand';
export const shadow28Brand = '--shadow28Brand';
export const shadow64Brand = '--shadow64Brand';
Copy link
Member

@levithomason levithomason Dec 12, 2023

Choose a reason for hiding this comment

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

Let's discuss taking a common dep on @fluentui/tokens. We're nearly identical between this and that now:
https://github.com/microsoft/fluentui/blob/master/packages/tokens/src/tokens.ts

Obviously named exports over objects is a thing. That can be handled many ways to ensure minimal bundles.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm fine with generating this locally at build time for instance - I didn't want to block the improvement on that.

Copy link
Member

Choose a reason for hiding this comment

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

At least there should be a test to verify the tokens here match the tokens in @fluentui/tokens

Copy link
Member

@miroslavstastny miroslavstastny left a comment

Choose a reason for hiding this comment

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

I love the changes!
We just need to resolve the screenshot test and make sure we have a test/automation to keep WC with FUIR tokens in sync.

@chrisdholt chrisdholt force-pushed the users/chhol/remove-design-token-in-favor-of-platform-solution branch from b16b34d to e2a32fa Compare December 22, 2023 23:30
@mohamedmansour
Copy link
Contributor

@chrisdholt what is remaining for this to land, do you need any help?

@chrisdholt chrisdholt marked this pull request as ready for review January 30, 2024 19:41
@chrisdholt chrisdholt requested a review from a team as a code owner January 30, 2024 19:41
.nx/cache/lockfile.hash Outdated Show resolved Hide resolved
@chrisdholt chrisdholt merged commit 4909fe2 into microsoft:web-components-v3 Feb 8, 2024
26 of 30 checks passed
@chrisdholt chrisdholt deleted the users/chhol/remove-design-token-in-favor-of-platform-solution branch February 8, 2024 22:30
chrisdholt added a commit that referenced this pull request Apr 29, 2024
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 30, 2024
radium-v pushed a commit that referenced this pull request Apr 30, 2024
radium-v pushed a commit that referenced this pull request May 2, 2024
radium-v pushed a commit that referenced this pull request May 2, 2024
radium-v pushed a commit that referenced this pull request May 2, 2024
radium-v pushed a commit that referenced this pull request May 3, 2024
radium-v pushed a commit that referenced this pull request May 6, 2024
radium-v pushed a commit that referenced this pull request May 6, 2024
radium-v pushed a commit that referenced this pull request May 8, 2024
radium-v pushed a commit that referenced this pull request May 10, 2024
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.

8 participants