Skip to content

Commit

Permalink
feat: new withFluentProvider decorator for converged Provider (#16869)
Browse files Browse the repository at this point in the history
* feat: new withFluentProvider decorator for converged Provider

* Change files

* add missing deps

* Update packages/storybook/src/decorators/withFluentProvider.tsx

* Update packages/storybook/src/decorators/withFluentProvider.tsx
  • Loading branch information
layershifter authored Feb 8, 2021
1 parent b6e11cb commit e6a1c49
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix mergeThemes() to avoid object's mutation",
"packageName": "@fluentui/react-theme",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion packages/react-theme/src/utils/mergeThemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { merge } from '@fluentui/utilities';
import { PartialTheme, Theme } from '../types';

export function mergeThemes(a: Theme, b: PartialTheme | Theme): Theme {
return merge(a, b) as Theme;
return merge({}, a, b) as Theme;
}
2 changes: 2 additions & 0 deletions packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
},
"dependencies": {
"@fluentui/react": "^8.0.0-beta.49",
"@fluentui/react-provider": "^0.1.2",
"@fluentui/react-theme": "^0.3.0",
"@fluentui/react-theme-provider": "^1.0.0-beta.20",
"@fluentui/theme": "^2.0.0-beta.13",
"@storybook/addon-knobs": "^5.3.8",
Expand Down
1 change: 1 addition & 0 deletions packages/storybook/src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './withFluentProvider';
export * from './withKeytipLayer';
export * from './withStrictMode';
export * from './withCompatThemeProvider';
20 changes: 20 additions & 0 deletions packages/storybook/src/decorators/withFluentProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { makeDecorator } from '@storybook/addons';
import { FluentProvider } from '@fluentui/react-provider';
import * as React from 'react';

import { useFluentTheme } from '../knobs/useFluentTheme';

const ProviderWrapper: React.FunctionComponent = props => {
const { theme } = useFluentTheme();

return <FluentProvider theme={theme}>{props.children}</FluentProvider>;
};

export const withFluentProvider = makeDecorator({
name: 'withFluentProvider',
parameterName: 'theme',
skipIfNoParametersOrOptions: false,
wrapper: (storyFn, context) => {
return <ProviderWrapper>{storyFn(context)}</ProviderWrapper>;
},
});
26 changes: 26 additions & 0 deletions packages/storybook/src/knobs/useFluentTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
webLightTheme,
webDarkTheme,
webHighContrastTheme,
teamsLightTheme,
teamsDarkTheme,
teamsHighContrastTheme,
Theme,
} from '@fluentui/react-theme';
import { select } from '@storybook/addon-knobs';

const themeSelectorLabel = 'Theme';

const themeOptions = [
{ label: 'Web Light', theme: webLightTheme },
{ label: 'Web Dark', theme: webDarkTheme },
{ label: 'Web High Contrast', theme: webHighContrastTheme },
{ label: 'Teams Light', theme: teamsLightTheme },
{ label: 'Teams Dark', theme: teamsDarkTheme },
{ label: 'Teams High Contrast', theme: teamsHighContrastTheme },
];

export const useFluentTheme = (): { label: string; theme: Theme } =>
// Casting any here due to issue: https://github.com/storybookjs/storybook/issues/9751
// eslint-disable-next-line @typescript-eslint/no-explicit-any
select(themeSelectorLabel, themeOptions as any, themeOptions[0] as any);

0 comments on commit e6a1c49

Please sign in to comment.