-
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
Changes from 8 commits
0157f8f
d00208f
c797198
bda9ea4
dcfcde3
794bd7f
f306846
fb87708
7bf1873
ed168ee
d3765ac
1f26987
66c95ef
ab22cd5
060d696
18c3e6d
14847d9
20091d7
e840ba7
21eba2e
81de523
b5f3788
4842eb9
8317329
55836b6
1559515
d888f92
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './withFluentProvider'; | ||
| export * from './withStrictMode'; | ||
| export * from './withFluentVrTestVariants'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import * as React from 'react'; | ||
| import { FluentProvider } from '@fluentui/react-provider'; | ||
| import { teamsHighContrastTheme, webDarkTheme, webLightTheme } from '@fluentui/react-theme'; | ||
| import { makeDecorator } from '@storybook/addons'; | ||
| import type { StoryContext } from '@storybook/addons'; | ||
|
|
||
| export const DARK_MODE = 'DarkMode'; | ||
| export const HIGH_CONTRAST = 'HighContrast'; | ||
| export const RTL = 'Rtl'; | ||
|
|
||
| // MakeDecoratorOptions is not an exported interface by storybook so had to include necessary options | ||
| interface AssertedMakeDecoratorOptions { | ||
| name: string; | ||
| parameterName: string; | ||
| skipIfNoParametersOrOptions?: boolean; | ||
| wrapper: ( | ||
| storyFn: (context: StoryContext) => React.ReactNode, | ||
| context: StoryContext, | ||
| settings: { | ||
| parameters: typeof DARK_MODE | typeof HIGH_CONTRAST | typeof RTL; | ||
| }, | ||
| ) => React.ReactNode; | ||
| } | ||
|
|
||
| type AssertedMakeDecorator = ({ | ||
| name, | ||
| parameterName, | ||
| skipIfNoParametersOrOptions, | ||
| wrapper, | ||
| }: AssertedMakeDecoratorOptions) => () => React.ReactNode; | ||
|
|
||
| export const withFluentVrTestVariants = ((makeDecorator as unknown) as AssertedMakeDecorator)({ | ||
TristanWatanabe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name: 'withFluentVrTestVariants.', | ||
| parameterName: 'vrTestVariant', | ||
| skipIfNoParametersOrOptions: true, | ||
| wrapper: (storyFn, context, { parameters }) => { | ||
| if (parameters === RTL) { | ||
| return ( | ||
| <FluentProvider dir={'rtl'} theme={webLightTheme}> | ||
| {storyFn(context)} | ||
| </FluentProvider> | ||
| ); | ||
| } | ||
|
|
||
| if (parameters === DARK_MODE) { | ||
| return <FluentProvider theme={webDarkTheme}>{storyFn(context)}</FluentProvider>; | ||
| } | ||
|
|
||
| if (parameters === HIGH_CONTRAST) { | ||
| return <FluentProvider theme={teamsHighContrastTheme}>{storyFn(context)}</FluentProvider>; | ||
| } | ||
|
|
||
| return storyFn(context); | ||
|
||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| export { withFluentProvider, withStrictMode } from './decorators/index'; | ||
| export { | ||
| withFluentProvider, | ||
| withStrictMode, | ||
| withFluentVrTestVariants, | ||
| DARK_MODE, | ||
| HIGH_CONTRAST, | ||
| RTL, | ||
| } from './decorators/index'; | ||
TristanWatanabe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.