Hi There,
I've been having some issue with using our custom MUI theme in stories. I've read through several of the existing threads on this issue but am still struggling to find a solution. This is how we initially used our theme in stories:
// preview.tsx
const preview: Preview = {
decorators: [
(Story) => (
<DefaultThemeProvider>
<Story />
</DefaultThemeProvider>
),
...
Where DefaultThemeProvider is exported from an internal dependency that contains a wrapped version of MUI
export const DefaultThemeProvider: FC<React.PropsWithChildren> = ({ children }) => (
<ThemeProvider theme={theme}>{children}</ThemeProvider>
);
This was working great. However, I added a component to storybook with the following dependency on MUI break points:
height: { md: "62vh", lg: "70vh", xl: "75vh" },
Unfortunately this component renders with no height applied.
I then tried using the @storybook/addon-styling add-on:
import { theme } from "@our-library";
import { withThemeFromJSXProvider } from "@storybook/addon-styling";
import { CssBaseline, ThemeProvider } from "@mui/material";
const preview: Preview = {
decorators: [
(Story) => (
<Story />
),
//@ts-ignore
withThemeFromJSXProvider({
themes: {
default: theme,
},
defaultTheme: "default",
Provider: ThemeProvider,
GlobalStyles: CssBaseline,
}),
],
...
This respects the height logic but our custom theme is not applied. Perhaps the TS error is a clue?
Types of property 'component' are incompatible.
Type 'unknown' is not assignable to type 'ComponentType<any> | undefined'.ts(2322)
Here are some of the relevant dependencies:
"@storybook/addon-styling": "1.3.4",
"storybook": "7.0.26",
"vite": "4.1.5",
Thanks in advance for your help!