-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(fluent-accordion): Add screenshot tests (#28441)
* chore(fluent-accordion): Add screenshot tests * remove step * add basic support for scoped theming * rewrite the theme decorator to WC * change file * update the vr story to match component story
- Loading branch information
1 parent
a786737
commit efdb09b
Showing
6 changed files
with
161 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
apps/vr-tests-web-components/src/utilities/WCThemeDecorator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import * as React from 'react'; | ||
import { StoryContext } from '@storybook/addons'; | ||
import { ComponentStory } from '@storybook/react'; | ||
import { FASTElement, customElement, html, attr } from '@microsoft/fast-element'; | ||
import { DesignToken } from '@microsoft/fast-foundation'; | ||
import { teamsLightTheme, teamsDarkTheme, webLightTheme, webDarkTheme } from '@fluentui/tokens'; | ||
import { setThemeFor } from '@fluentui/web-components'; | ||
|
||
DesignToken.registerDefaultStyleTarget(); | ||
|
||
const themes = [ | ||
{ id: 'web-light', label: 'Web Light', theme: webLightTheme }, | ||
{ id: 'web-dark', label: 'Web Dark', theme: webDarkTheme }, | ||
{ id: 'teams-light', label: 'Teams Light', theme: teamsLightTheme }, | ||
{ id: 'teams-dark', label: 'Teams Dark', theme: teamsDarkTheme }, | ||
] as const; | ||
|
||
const defaultTheme = themes[0]; | ||
|
||
type ThemeId = typeof themes[number]['id']; | ||
|
||
interface WCStoryContext extends StoryContext { | ||
parameters: { | ||
dir?: 'ltr' | 'rtl'; | ||
fluentTheme?: ThemeId; | ||
}; | ||
} | ||
|
||
@customElement({ | ||
name: 'fast-theme-decorator', | ||
template: html`<slot></slot>`, | ||
styles: ` | ||
:host { | ||
display: block; | ||
color: var(--colorNeutralForeground2); | ||
background-color: var(--colorNeutralBackground2); | ||
font-family: var(--fontFamilyBase); | ||
} | ||
`, | ||
}) | ||
export class FASTThemeDecorator extends FASTElement { | ||
@attr({ | ||
attribute: 'fluent-theme', | ||
}) | ||
public fluentTheme: ThemeId = defaultTheme.id; | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
const theme = themes.find(value => value.id === this.fluentTheme)?.theme ?? defaultTheme.theme; | ||
setThemeFor(this, theme); | ||
} | ||
} | ||
|
||
export const WCThemeDecorator = (StoryFn: () => JSX.Element, context: WCStoryContext) => { | ||
const { dir = 'ltr', fluentTheme = defaultTheme.id } = context.parameters; | ||
|
||
return React.createElement('fast-theme-decorator', { dir, 'fluent-theme': fluentTheme }, StoryFn()); | ||
}; | ||
|
||
export const DARK_MODE = 'Dark Mode'; | ||
export const RTL = 'RTL'; | ||
|
||
type Variant = typeof DARK_MODE | typeof RTL; | ||
|
||
function getStoryName(story: ComponentStory<never>) { | ||
if (story.storyName) { | ||
return story.storyName; | ||
} | ||
|
||
return story.name.replace(/([a-z])([A-Z])/g, '$1 $2'); | ||
} | ||
|
||
export const getStoryVariant = (story: () => string | JSX.Element | JSX.Element[], variant: Variant) => { | ||
return { | ||
...story, | ||
render: story, | ||
storyName: `${getStoryName(story as ComponentStory<never>)} - ${variant}`, | ||
parameters: { | ||
...(variant === DARK_MODE && { fluentTheme: 'teams-dark' }), | ||
...(variant === RTL && { dir: 'rtl' }), | ||
}, | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-web-components-e7f611c9-b323-4f2d-aaed-519f0773c058.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "feat: Add support for scoped theming", | ||
"packageName": "@fluentui/web-components", | ||
"email": "miroslav.stastny@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './design-tokens.js'; | ||
export { setTheme } from './set-theme.js'; | ||
export { setTheme, setThemeFor } from './set-theme.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters