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(wc): Add v9-compatible themes #25660

Merged

Conversation

miroslavstastny
Copy link
Member

Add themes compatible with @fluentui/react-components@9

In v9, there are currently 4 basic themes:

  1. Light,
  2. Dark,
  3. Teams Dark,
  4. Teams High Contrast.

Each of the themes is a function of a brand ramp. As an example Web Light Theme is the Light Theme created with Web brand ramp and Teams Light Theme is the Light Theme created with Teams brand ramp.

This PR proposed how Web Components can have a theme compatible with React.

@@ -14,36 +20,11 @@ export const parameters = {
},
options: {
storySort: {
order: [
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed legacy

"@microsoft/fast-element": "^2.0.0-beta.17",
"@microsoft/fast-foundation": "^3.0.0-alpha.21",
"@microsoft/fast-web-utilities": "^6.0.0",
"@fluentui/react-theme": "^9.1.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

This adds dependency on a react-theme package 💣
There is nothing React related in that package besides two things:

  1. It has react in the package name.
  2. It adds react as a peer dependency.

If we decide to go this way, we should do one of the following things:

  • Rename react-theme to theme, get rid of the peer dependency (might be breaking change for FUIRv9).
  • Hoist the tokens from react-theme to theme, re-export in react-theme.
  • Use token pipeline to generate the same theme files for web-components.

Copy link
Contributor

Choose a reason for hiding this comment

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

ideally we should use same fluent tokens and themes in all web experiences, thus

if react-theme doesn't contain anything react specific besides the peerDep

  • deprecate react-theme on npm
  • rename react-theme to react (removal of peer Deps )
    • having react-theme with re-exports of theme adds unnecessary maintenance

might be breaking change for FUIRv9

from react-components api POV there will be no breaking change. once someone installs new feature bump of react-components they will get theme instead of react-theme in they node_modules

Copy link
Member

@levithomason levithomason Nov 15, 2022

Choose a reason for hiding this comment

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

If there is no use of React in react-theme why can't we just create a theme package and use that directly in react-components and get rid of the react-theme all together?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what @Hotell is proposing (+ npm deprecation). I was not sure whether we would consider it a breaking change or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree that the change is not breaking.

Copy link
Contributor

Choose a reason for hiding this comment

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

Was just chatting with @chrisdholt today and we'd definitely love to have a shared, library-agnostic theme package that we can base both React and Web Components on. Sounds like folks here arrived at the same conclusion. +1 from me.

Copy link
Member

Choose a reason for hiding this comment

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

+1 lets start from here


const { create } = DesignToken;

export const borderRadiusNone = create<string>('borderRadiusNone');
Copy link
Member Author

Choose a reason for hiding this comment

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

No default values here. Each theme has its own values.

@@ -0,0 +1,383 @@
import { DesignToken } from '@microsoft/fast-foundation';
Copy link
Member Author

Choose a reason for hiding this comment

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

This files should be generated by the token pipeline.

@@ -0,0 +1,2 @@
export * from './design-tokens';
Copy link
Member Author

Choose a reason for hiding this comment

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

I need to add bundle-size / tree-shaking tests. After that we might reconsider the way how we export and consume tokens.

* Sets the theme tokens on defaultNode.
* @param theme Flat object of theme token values.
*/
export const setTheme = (theme: Theme) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Only defaultNode (global) for now.
If agreed, we will add setValueFor version for scoped theming.

import { setTheme } from '../src/theme';

const themes = {
'web-light': webLightTheme,
Copy link
Member Author

Choose a reason for hiding this comment

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

For now, there are no theme exports from web components.
If we decide to go this way, we need to discuss the export contract.

Copy link
Member

Choose a reason for hiding this comment

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

Is this for Storybook only? Named exports are treeshakable but an object is not, so all themes will always be included here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, storybook only for now.
Once we know the packages structure, we will decide whether partners will import the theme directly from theme package or web-components will re-export the themes and how.

Copy link
Member

Choose a reason for hiding this comment

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

We can discuss later - may be ideal to export from the package though given we’re using DesignToken.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 14, 2022

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 8c9a0f3:

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

@size-auditor
Copy link

size-auditor bot commented Nov 14, 2022

Asset size changes

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

Baseline commit: 7f15428e8fb2c3cfbfe8e555978bfa66f74f8fd8 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Nov 14, 2022

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-combobox
Combobox (including child components)
75.85 kB
24.632 kB
76.135 kB
24.738 kB
285 B
106 B
react-combobox
Dropdown (including child components)
75.579 kB
24.594 kB
75.864 kB
24.699 kB
285 B
105 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
189.603 kB
52.909 kB
189.888 kB
53.022 kB
285 B
113 B
react-menu
Menu (including children components)
116.78 kB
36.112 kB
117.055 kB
36.238 kB
275 B
126 B
react-menu
Menu (including selectable components)
119.849 kB
36.635 kB
120.124 kB
36.75 kB
275 B
115 B
react-popover
Popover
103.342 kB
31.82 kB
103.624 kB
31.927 kB
282 B
107 B
react-positioning
usePositioning
19.724 kB
7.415 kB
20.009 kB
7.532 kB
285 B
117 B
react-tooltip
Tooltip
41.718 kB
14.687 kB
41.993 kB
14.799 kB
275 B
112 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
global-context
createContext
533 B
341 B
global-context
createContextSelector
554 B
348 B
priority-overflow
createOverflowManager
3.153 kB
1.299 kB
react-accordion
Accordion (including children components)
79.243 kB
24.436 kB
react-alert
Alert
84.688 kB
21.233 kB
react-avatar
Avatar
48.874 kB
13.864 kB
react-avatar
AvatarGroup
14.996 kB
6.013 kB
react-avatar
AvatarGroupItem
63.452 kB
17.959 kB
react-badge
Badge
22.646 kB
7.228 kB
react-badge
CounterBadge
23.536 kB
7.512 kB
react-badge
PresenceBadge
24.096 kB
7.09 kB
react-button
Button
36.849 kB
9.907 kB
react-button
CompoundButton
43.874 kB
11.123 kB
react-button
MenuButton
39.543 kB
10.807 kB
react-button
SplitButton
46.989 kB
12.192 kB
react-button
ToggleButton
52.716 kB
11.381 kB
react-card
Card - All
67.664 kB
19.635 kB
react-card
Card
63.346 kB
18.539 kB
react-card
CardFooter
8.607 kB
3.622 kB
react-card
CardHeader
9.65 kB
3.962 kB
react-card
CardPreview
8.708 kB
3.678 kB
react-components
react-components: Button, FluentProvider & webLightTheme
62.94 kB
17.663 kB
react-components
react-components: FluentProvider & webLightTheme
33.446 kB
11.033 kB
react-dialog
Dialog (including children components)
83.147 kB
24.799 kB
react-divider
Divider
16.505 kB
5.925 kB
react-image
Image
10.826 kB
4.286 kB
react-infobutton
InfoButton
7.742 kB
3.265 kB
react-input
Input
24.428 kB
7.899 kB
react-label
Label
9.384 kB
3.883 kB
react-link
Link
11.852 kB
4.888 kB
react-overflow
hooks only
11.004 kB
4.188 kB
react-persona
Persona
53.992 kB
15.25 kB
react-portal
Portal
10.628 kB
3.899 kB
react-portal-compat
PortalCompatProvider
5.857 kB
1.978 kB
react-progress
Progress
13.131 kB
5.039 kB
react-provider
FluentProvider
15.807 kB
5.909 kB
react-radio
Radio
36.436 kB
12.126 kB
react-radio
RadioGroup
14.294 kB
5.723 kB
react-select
Select
23.255 kB
7.954 kB
react-slider
Slider
31.978 kB
10.149 kB
react-spinbutton
SpinButton
45.826 kB
12.858 kB
react-spinner
Spinner
20.023 kB
6.461 kB
react-switch
Switch
33.388 kB
10.578 kB
react-text
Text - Default
11.828 kB
4.627 kB
react-text
Text - Wrappers
15.138 kB
5.064 kB
react-textarea
Textarea
25.687 kB
8.331 kB
react-theme
Single theme token import
69 B
89 B
react-theme
Teams: all themes
29.65 kB
6.444 kB
react-theme
Teams: Light theme
17.486 kB
5.057 kB
react-utilities
SSRProvider
180 B
159 B
🤖 This report was generated against 7f15428e8fb2c3cfbfe8e555978bfa66f74f8fd8

@Hotell
Copy link
Contributor

Hotell commented Nov 15, 2022

you have dep dupes. make sure to run npx yarn-deduplicate --strategy fewer

@@ -0,0 +1,9 @@
<div id="switches-container">
Copy link
Contributor

Choose a reason for hiding this comment

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

good opportunity to leverage here our theme picker (storybook addon) , later

packages/web-components/src/theme/set-theme.ts Outdated Show resolved Hide resolved
"@microsoft/fast-element": "^2.0.0-beta.17",
"@microsoft/fast-foundation": "^3.0.0-alpha.21",
"@microsoft/fast-web-utilities": "^6.0.0",
"@fluentui/react-theme": "^9.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally we should use same fluent tokens and themes in all web experiences, thus

if react-theme doesn't contain anything react specific besides the peerDep

  • deprecate react-theme on npm
  • rename react-theme to react (removal of peer Deps )
    • having react-theme with re-exports of theme adds unnecessary maintenance

might be breaking change for FUIRv9

from react-components api POV there will be no breaking change. once someone installs new feature bump of react-components they will get theme instead of react-theme in they node_modules

@miroslavstastny
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

<h3>Theme Tokens</h3>
<p>Debug story which uses theme tokens to style the element below.</p>
<div style="
font-family: ${tokens.fontFamilyBase.createCSS()};
Copy link
Contributor

@EisenbergEffect EisenbergEffect Dec 1, 2022

Choose a reason for hiding this comment

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

@nicholasrice What do you think about adding a toString() and valueOf() implementation to CSSDesignToken? That would make this syntax nicer if used outside of a FAST html or css template.

Copy link
Contributor

Choose a reason for hiding this comment

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

toString() seems fine to me. Can you elaborate more on valueOf()? It's not clear to me what that would return.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I don't think we need valueOf(). I just checked and the JavaScript runtime prefers toString() for string conversions over valueOf(). Since we don't need to convert to a numerical type of some non-string type we should be fine with toString().

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, I didn't realize that was an object prototype method. I think adding toString() to CSSDesignToken makes sense.

@miroslavstastny
Copy link
Member Author

As agreed offline, tokens were hoisted from @fluentui/react-theme to @fluentui/tokens.
To unblock component work, I suggest to go with this PR and fix non-blocking issues in follow-up PRs.

@miroslavstastny miroslavstastny marked this pull request as ready for review December 21, 2022 13:14
@miroslavstastny miroslavstastny requested a review from a team as a code owner December 21, 2022 13:14
Copy link
Member

@ling1726 ling1726 left a comment

Choose a reason for hiding this comment

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

Approving for v-build related changes

Copy link
Member

@chrisdholt chrisdholt left a comment

Choose a reason for hiding this comment

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

Let’s move this through and we can adjust iterate as needed (such as exports, etc). Thanks @miroslavstastny!

@miroslavstastny miroslavstastny merged commit 6de62a4 into microsoft:web-components-v3 Dec 21, 2022
Hotell pushed a commit to Hotell/fluentui that referenced this pull request Feb 9, 2023
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
Hotell pushed a commit to Hotell/fluentui that referenced this pull request Feb 9, 2023
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
Hotell pushed a commit to Hotell/fluentui that referenced this pull request Feb 9, 2023
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
chrisdholt pushed a commit that referenced this pull request Apr 29, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 30, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request Apr 30, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 2, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 2, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 2, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 3, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 6, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 6, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 8, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
radium-v pushed a commit that referenced this pull request May 10, 2024
* bump FAST dependencies

* Add theme tokens (from react-theme)

* Add theme switcher to storybook

* deduplicate packages

* fix yarn.lock

* Replace @fluentui/react-theme with @fluentui/tokens

* change file

* address PR comments
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.

None yet

9 participants