-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-storybook-addon): make withFluentProvider decorator configurable to be used for VR tests #25162
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(react-storybook-addon): make withFluentProvider decorator configurable to be used for VR tests #25162
Conversation
📊 Bundle size reportUnchanged fixtures
|
|
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 d888f92:
|
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: 59cc34eefb165b3a052da500465178b109f3df01 (build) |
packages/react-components/react-storybook/src/decorators/withFluentVrTestVariants.tsx
Outdated
Show resolved
Hide resolved
| return <FluentProvider theme={teamsHighContrastTheme}>{storyFn(context)}</FluentProvider>; | ||
| } | ||
|
|
||
| return storyFn(context); |
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.
It seems that we have this new decorator that configures the provider but also withFluentProvider that is not configurable. Then let's just have one withFluentProvider that is configurable ?
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.
^ great call, lets do it ! #DRY
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.
Yeah I considered doing this but as it stands, the withFluentProvider decorator doesn’t just wrap a story function in FluentProvider, but it also wraps it in a container with custom styling. I wanted to avoid a bunch of Screener change churn that this would cause which is why I opted for a separate decorator.
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.
in that case we could remove the custom styling into its own decorator ?
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.
I wanted to avoid a bunch of Screener change churn
wondering what churn are you referring to ?
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.
Since an extra div with styling is essentially added to each story by the withFluentProvider decorator, when each story is converted to CSF , Screener will detect each one as "Changed". I was trying to avoid a bunch of unnecessary Screener changes when I refactor to CSF to simplify the review process and to not introduce random screener issues
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.
in that case we could remove the custom styling into its own decorator ?
With the way it's implemented right now, that would just seem redundant? Even if moved as a separate decorator, it would still need a FluentProvider regardless.
export const withFluentProvider = (StoryFn: () => JSX.Element, context: FluentStoryContext) => {
const { theme } = getActiveFluentTheme(context.globals);
return (
<FluentProvider theme={theme}>
<FluentExampleContainer theme={theme}>{StoryFn()}</FluentExampleContainer>
</FluentProvider>
);
};
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.
I'm not opposed to just reconfiguring the withFluentProvider so that it can accept theme and dir parameters and any screener changes (it adds padding and theme background) can just be communicated in the PR details - thoughts?
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.
I wonder if we could utilize the storybook context or globals a bit more, withFluentProvider could maybe have like mode configuration where the VR tests would configure a mode that would not inject padding and theme background ?
|
We have a The withFluentProvider in react-storybook-addon is what we use in the docsite storybook and also doesn't use |
packages/react-components/react-storybook/src/decorators/withFluentVrTestVariants.tsx
Outdated
Show resolved
Hide resolved
This reverts commit dcfcde3.
Perf Analysis (
|
| Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
|---|---|---|---|---|---|
| Avatar | mount | 1316 | 1320 | 5000 | |
| Button | mount | 944 | 947 | 5000 | |
| FluentProvider | mount | 1602 | 1572 | 5000 | |
| FluentProviderWithTheme | mount | 632 | 635 | 10 | |
| FluentProviderWithTheme | virtual-rerender | 591 | 598 | 10 | |
| FluentProviderWithTheme | virtual-rerender-with-unmount | 635 | 620 | 10 | |
| MakeStyles | mount | 1814 | 1884 | 50000 | |
| SpinButton | mount | 2526 | 2538 | 5000 |
| 3. `isVrTest` - when set to `true`, this removes injected padding and background theme that's automatically applied from rendered story. | ||
|
|
||
| ```js | ||
| import { TEAMS_HIGH_CONTRAST, WEB_DARK, WEB_LIGHT } from '@fluentui/react-storybook-addon'; |
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.
suggestion: hmm best API is no API or very limited API surface 🙌.
we don't need these tokens for sake of setting fluent theme.
We can instead leverage one or both of the following approaches:
- export only type that consumer can use to get proper intelissense for setting parameters
import type {Parameters} from '@fluentui/react-storybook-addon';
export const ButtonDarkMode = {
render: Button,
parameters: { fluentTheme: 'web-dark' } as Parameters
};- export function that will provide all the intellisense without need to do any manual work
import {parameters} from '@fluentui/react-storybook-addon';
export const ButtonDarkMode = {
render: Button,
// parameters function has all the proper TS annotations so we will get top DX
parameters: parameters({ fluentTheme: 'web-dark' })
};// this will be basically an identity function
export function parameters(options:FluentAddonParameters){
// possibly process default values here
return options;
}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.
These two options combined to provide TS typing via intellisense are definitely much better solutions than constant tokens! I've made the change to add a parameters function and have removed the constants in favor of exporting a FluentParameters type.
| export interface FluentParameters extends Parameters { | ||
| dir?: 'ltr' | 'rtl'; | ||
| fluentTheme?: ThemeIds; | ||
| isVrTest?: boolean; |
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.
suggestion: boolean flags doesn't scale well. what about
-isVrTest?: boolean;
+context?: 'vr-test' | 'default'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.
replaced with mode flag instead to prevent confusion with storybook context: b5f3788
Hotell
left a comment
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.
awesomeness 🤩
…urable to be used for VR tests (microsoft#25162)
Changes:
withFluentProviderdecorator and makes it configurable via storyparametersto be usable when writing different Visual Regression test variants in v9. This does NOT change any default behavior of the addon, it simply allows it to be configurable for VR tests.storiesOf.addmethod (called.addStory) to automatically includeRTL,Dark ModeandHigh Contrastvariants via thesetAddonmethod in thevr-tests-react-componentspackage.setAddonis already deprecated and set to be removed in storybook 7.0 and there's no real 1-to-1 replacement for it. This updated decorator implementation aims to replace that functionality and will add the ability to pass afluentThemeparameterto a story which will allow it to render as either Dark Mode, High Contrast (and more) and also adds adirparameter which can receive anrtlvalue to render a story in RTL mode.Parameter Options:
dir- determines whether to render story inltrorrtlmode. Default isundefined.fluentTheme- determines whether to render story theme inweb-light,web-dark,teams-high-contrast,teams-dark, orteams-light. Setting this parameter will disable ability to dynamically change the theme within story canvas or doc.mode- when set tovr-test, this removes injected padding and background theme that's automatically applied from rendered story. Default isdefault.Example Usage:
Issues:
Part of #25078