Skip to content

Commit

Permalink
Refactor story decorators to enable use of useTheme (#43108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravicious authored Jun 18, 2024
1 parent db7baed commit bb64e01
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions web/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import React from 'react';
import { rest, setupWorker } from 'msw';
import { addDecorator, addParameters } from '@storybook/react';
import { addParameters } from '@storybook/react';
import {
darkTheme,
lightTheme,
Expand Down Expand Up @@ -48,7 +48,7 @@ if (typeof global.process === 'undefined') {
history.init();

// wrap each story with theme provider
const ThemeDecorator = (storyFn, meta) => {
const ThemeDecorator = (Story, meta) => {
let ThemeProvider;
let theme;

Expand All @@ -75,27 +75,29 @@ const ThemeDecorator = (storyFn, meta) => {

return (
<ThemeProvider theme={theme}>
<Box p={3}>{storyFn()}</Box>
<Box p={3}>
<Story />
</Box>
</ThemeProvider>
);
};

// wrap stories with an argument of {userContext: true} with user context provider
const UserDecorator = (storyFn, meta) => {
const UserDecorator = (Story, meta) => {
if (meta.args.userContext) {
const UserProvider = UserContextProvider;
return (
<UserProvider>
<Box p={3}>{storyFn()}</Box>
<Story />
</UserProvider>
);
}

return <Box p={3}>{storyFn()}</Box>;
return <Story />;
};

addDecorator(UserDecorator);
addDecorator(ThemeDecorator);
export const decorators = [UserDecorator, ThemeDecorator];

addParameters({
options: {
showPanel: false,
Expand Down

0 comments on commit bb64e01

Please sign in to comment.