-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(wc): Add v9-compatible themes #25660
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
Changes from 5 commits
c202364
32f5de1
182880e
0bb5c9f
59b529e
e8aa93d
4cfb168
9f3bcc0
8c9a0f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <div id="switches-container"> | ||
| <label for="theme-switch">Theme</label> | ||
| <select id="theme-switch" name="theme"> | ||
| <option value="web-light" selected>Web Light</option> | ||
| <option value="web-dark">Web Dark</option> | ||
| <option value="teams-light">Teams Light</option> | ||
| <option value="teams-dark">Teams Dark</option> | ||
| </select> | ||
| </div> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| import { addons } from '@storybook/addons'; | ||
| import { DOCS_RENDERED } from '@storybook/core-events'; | ||
| import * as Fluent from '../src/index-rollup'; | ||
| import webcomponentsTheme from './theme'; | ||
| import { switchTheme } from '../public/theme-switch'; | ||
|
|
||
| Fluent; | ||
|
|
||
| function changeTheme(e) { | ||
| switchTheme(e.target.value); | ||
| } | ||
|
|
||
| document.getElementById('theme-switch').addEventListener('change', changeTheme, false); | ||
| switchTheme('web-light'); | ||
|
|
||
| export const parameters = { | ||
| layout: 'fullscreen', | ||
| controls: { expanded: true }, | ||
|
|
@@ -14,36 +20,11 @@ export const parameters = { | |
| }, | ||
| options: { | ||
| storySort: { | ||
| order: [ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed legacy |
||
| 'Getting Started', | ||
| ['Overview', 'Installation', 'Styling'], | ||
| 'Components', | ||
| 'Integrations', | ||
| ['Introduction'], | ||
| 'Design System', | ||
| ['Design Tokens', 'Color Explorer', 'High Contrast'], | ||
| 'Resources', | ||
| ['Browser Support', 'FAQ', 'License', 'Security'], | ||
| '*', | ||
| ], | ||
| order: [], | ||
| method: 'alphabetical', | ||
| }, | ||
| }, | ||
| docs: { | ||
| theme: webcomponentsTheme, // override the default Storybook theme with a custom fluent theme | ||
| }, | ||
| }; | ||
|
|
||
| addons.getChannel().addListener(DOCS_RENDERED, name => { | ||
| if (name.toLowerCase().includes('accordion') || name.toLowerCase().includes('card')) { | ||
| fillColor.setValueFor(document.body, neutralLayer2); | ||
| } else { | ||
| fillColor.setValueFor(document.body, neutralLayer1); | ||
| } | ||
|
|
||
| if (name.toLowerCase().includes('color-explorer')) { | ||
| document.body.classList.add('custom-fullscreen'); | ||
| } else { | ||
| document.body.classList.remove('custom-fullscreen'); | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,10 +72,10 @@ | |
| "mocha": "7.2.0" | ||
| }, | ||
| "dependencies": { | ||
| "@microsoft/fast-colors": "^5.3.0", | ||
| "@microsoft/fast-element": "^1.11.0", | ||
| "@microsoft/fast-foundation": "^2.47.0", | ||
| "@microsoft/fast-web-utilities": "^5.4.0", | ||
| "@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", | ||
|
||
| "tslib": "^1.13.0" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { teamsDarkTheme, teamsLightTheme, webDarkTheme, webLightTheme } from '@fluentui/react-theme'; | ||
| import { setTheme } from '../src/theme'; | ||
|
|
||
| const themes = { | ||
| 'web-light': webLightTheme, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, there are no theme exports from web components.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, storybook only for now.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 'web-dark': webDarkTheme, | ||
| 'teams-light': teamsLightTheme, | ||
| 'teams-dark': teamsDarkTheme, | ||
| }; | ||
|
|
||
| export function switchTheme(themeName: keyof typeof themes) { | ||
| setTheme(themes[themeName]); | ||
| } | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './design-tokens'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| export { setTheme } from './set-theme'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { Theme } from '@fluentui/react-theme'; | ||
| import * as tokens from './design-tokens'; | ||
|
|
||
| /** | ||
| * Sets the theme tokens on defaultNode. | ||
| * @param theme Flat object of theme token values. | ||
| */ | ||
| export const setTheme = (theme: Theme) => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only |
||
| for (const t of Object.keys(tokens)) { | ||
miroslavstastny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tokens[t].withDefault(theme[t]); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { DesignToken } from '@microsoft/fast-foundation'; | ||
| import * as tokens from '../theme/design-tokens'; | ||
|
|
||
| DesignToken.registerDefaultStyleTarget(); | ||
|
|
||
| export default { | ||
| title: 'Theme/Tokens', | ||
| }; | ||
|
|
||
| export const Tokens = () => ` | ||
| <div> | ||
| <h3>Theme Tokens</h3> | ||
| <p>Debug story which uses theme tokens to style the element below.</p> | ||
| <div style=" | ||
| font-family: ${tokens.fontFamilyBase.createCSS()}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nicholasrice What do you think about adding a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I don't think we need
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| font-size: ${tokens.fontSizeBase300.createCSS()}; | ||
| background: var(${tokens.colorBrandBackground.cssCustomProperty}); | ||
| color: ${tokens.colorNeutralForegroundOnBrand.createCSS()}; | ||
| border: ${tokens.strokeWidthThicker.createCSS()} solid ${tokens.colorNeutralStroke1.createCSS()}; | ||
| padding: ${tokens.spacingVerticalS.createCSS()} ${tokens.spacingHorizontalM.createCSS()}; | ||
| box-shadow: ${tokens.shadow28.createCSS()}; | ||
| ">colorNeutralForegroundOnBrand on colorBrandBackground with shadow28</div> | ||
| </div> | ||
| `; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1604,17 +1604,17 @@ | |
| minimatch "^3.0.4" | ||
| strip-json-comments "^3.1.1" | ||
|
|
||
| "@floating-ui/core@^1.0.0": | ||
| version "1.0.0" | ||
| resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.0.0.tgz#ec1d31f54c72dd0460276e2149e59bd13c0f01f6" | ||
| integrity sha512-sm3nW0hHAxTv3gRDdCH8rNVQxijF+qPFo5gAeXCErRjKC7Qc28lIQ3R9Vd7Gw+KgwfA7RhRydDFuGeI0peGq7A== | ||
| "@floating-ui/core@^1.0.1": | ||
| version "1.0.1" | ||
| resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.0.1.tgz#00e64d74e911602c8533957af0cce5af6b2e93c8" | ||
| integrity sha512-bO37brCPfteXQfFY0DyNDGB3+IMe4j150KFQcgJ5aBP295p9nBGeHEs/p0czrRbtlHq4Px/yoPXO/+dOCcF4uA== | ||
|
|
||
| "@floating-ui/dom@^1.0.0": | ||
| version "1.0.0" | ||
| resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.0.0.tgz#66923a56755b6cb7a5958ecf25fe293912672d65" | ||
| integrity sha512-PMqJvY5Fae8HVQgUqM+lidprS6p9LSvB0AUhCdYKqr3YCaV+WaWCeVNBtXPRY2YIdrgcsL2+vd5F07FxgihHUw== | ||
| "@floating-ui/dom@^1.0.0", "@floating-ui/dom@^1.0.3": | ||
| version "1.0.4" | ||
| resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.0.4.tgz#cc0f2a03db7193b1b932b90d09c5c81235682a60" | ||
| integrity sha512-maYJRv+sAXTy4K9mzdv0JPyNW5YPVHrqtY90tEdI6XNpuLOP26Ci2pfwPsKBA/Wh4Z3FX5sUrtUFTdMYj9v+ug== | ||
| dependencies: | ||
| "@floating-ui/core" "^1.0.0" | ||
| "@floating-ui/core" "^1.0.1" | ||
|
|
||
| "@fluent-blocks/[email protected]": | ||
| version "9.2.0" | ||
|
|
@@ -3011,30 +3011,31 @@ | |
| eslint-plugin-react "7.24.0" | ||
| eslint-plugin-security "1.4.0" | ||
|
|
||
| "@microsoft/fast-colors@^5.3.0": | ||
| version "5.3.1" | ||
| resolved "https://registry.yarnpkg.com/@microsoft/fast-colors/-/fast-colors-5.3.1.tgz#defc59874176e42316be7e6d24c31885ead8ca56" | ||
| integrity sha512-72RZXVfCbwQzvo5sXXkuLXLT7rMeYaSf5r/6ewQiv/trBtqpWRm4DEH2EilHw/iWTBKOXs1qZNQndgUMa5n4LA== | ||
|
|
||
| "@microsoft/fast-element@^1.10.4", "@microsoft/fast-element@^1.11.0": | ||
| "@microsoft/fast-element@^1.10.4": | ||
| version "1.11.0" | ||
| resolved "https://registry.yarnpkg.com/@microsoft/fast-element/-/fast-element-1.11.0.tgz#494f6c87057bcbb42406982d68a92887d6b5acb1" | ||
| integrity sha512-VKJYMkS5zgzHHb66sY7AFpYv6IfFhXrjQcAyNgi2ivD65My1XOhtjfKez5ELcLFRJfgZNAxvI8kE69apXERTkw== | ||
|
|
||
| "@microsoft/fast-foundation@^2.47.0": | ||
| version "2.47.0" | ||
| resolved "https://registry.yarnpkg.com/@microsoft/fast-foundation/-/fast-foundation-2.47.0.tgz#a4cc8c5277e21d080215f5adcaed4266a8dd8a8e" | ||
| integrity sha512-EyFuioaZQ9ngjUNRQi8R3dIPPsaNQdUOS+tP0G7b1MJRhXmQWIitBM6IeveQA6ZvXG6H21dqgrfEWlsYrUZ2sw== | ||
| "@microsoft/fast-element@^2.0.0-beta.17": | ||
| version "2.0.0-beta.17" | ||
| resolved "https://registry.yarnpkg.com/@microsoft/fast-element/-/fast-element-2.0.0-beta.17.tgz#46f9b1feaf57e0cb841d31a80574537257b2239f" | ||
| integrity sha512-R9NLnH0rh/btfBIdDicHGblw4uk4U7TNTnfpZ25W5IC52cWg7DLr0ky5GujH7wXge8F4ze/Z8anABzhC9eHYrA== | ||
|
|
||
| "@microsoft/fast-foundation@^3.0.0-alpha.21": | ||
| version "3.0.0-alpha.21" | ||
| resolved "https://registry.yarnpkg.com/@microsoft/fast-foundation/-/fast-foundation-3.0.0-alpha.21.tgz#b867b3483d9e2ed496b301e6a6c4017adfa333f4" | ||
| integrity sha512-hKY2aI7OI54SN+h2ayJVh4CLD8dcbCuaOWihdiUTBnwNVgl/xANazO3q+Cs2P/5gHHOy2lIgJOZvsK9ilBsCQQ== | ||
| dependencies: | ||
| "@microsoft/fast-element" "^1.11.0" | ||
| "@microsoft/fast-web-utilities" "^5.4.1" | ||
| "@floating-ui/dom" "^1.0.3" | ||
| "@microsoft/fast-element" "^2.0.0-beta.17" | ||
| "@microsoft/fast-web-utilities" "^6.0.0" | ||
| tabbable "^5.2.0" | ||
| tslib "^1.13.0" | ||
| tslib "^2.4.0" | ||
|
|
||
| "@microsoft/fast-web-utilities@^5.4.0", "@microsoft/fast-web-utilities@^5.4.1": | ||
| version "5.4.1" | ||
| resolved "https://registry.yarnpkg.com/@microsoft/fast-web-utilities/-/fast-web-utilities-5.4.1.tgz#8e3082ee2ff2b5467f17e7cb1fb01b0e4906b71f" | ||
| integrity sha512-ReWYncndjV3c8D8iq9tp7NcFNc1vbVHvcBFPME2nNFKNbS1XCesYZGlIlf3ot5EmuOXPlrzUHOWzQ2vFpIkqDg== | ||
| "@microsoft/fast-web-utilities@^6.0.0": | ||
| version "6.0.0" | ||
| resolved "https://registry.yarnpkg.com/@microsoft/fast-web-utilities/-/fast-web-utilities-6.0.0.tgz#7678c2b2cd12aeef785f4e2288da93a4db9e38a6" | ||
| integrity sha512-ckCA4Xn91ja1Qz+jhGGL1Q3ZeuRpA5VvYcRA7GzA1NP545sl14bwz3tbHCq8jIk+PL7mkSaIveGMYuJB2L4Izg== | ||
| dependencies: | ||
| exenv-es6 "^1.1.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.
good opportunity to leverage here our theme picker (storybook addon) , later