Is using a theme with components rendered in MDX files possible? #25134
Replies: 2 comments 1 reply
-
Things I found while researching this problem:
|
Beta Was this translation helpful? Give feedback.
-
|
I was able to finally find this little tidbit on the autodocs page https://storybook.js.org/docs/writing-docs/autodocs#customize-the-docs-container This is working as expected for me in all pages, autodocs and custom MDX |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
If I render a basic MUI component in an
.mdxfile like this:Where
Typographyis Material UI's component anddisplaySmDesktopis a custom typography defined in my theme that works outside of.mdxfiles..Is it expected that none of the typography styles are applied? That is the behavior I am seeing.
I have the same problem if I render a custom component in an
.mdxfile, except in that case, when I try to access a custom property of the theme, it is undefined. However, if the component is called from a story, then it works.It looks like the only way I can render a component is to use a
Canvas, but with this approach there are two significant issues:Canvas, I can only have it execute a pre-defined story, therefore I need to set up stories for everything I want in advance. If I want a heading that is styled using a custom typography in my theme, that's a different story for every possible heading in a document! (I could use basic CSS, but I am trying to use a custom typography as it uses style tokens.).mdxpage seems to make those canvases load very slowly, specifically when you switch from one theme to another in the switcher (fonts load VERY slowly). I do not think documentation pages were intended to have 30+ canvases on a single page?I think the issue is probably that
.mdxfiles do not usepreview.tsxlike stories do, so myThemeProviderwrapper isn't getting applied, therefore no theme context?Additional information
I am using MUI themes and Emotion.
Storybook version: 7.2.3
main.tsThis question may be a duplicate of #17190, I am not really sure. That question has gone unanswered for almost 2 years and there was no way for me to bump it, so I created a new question.
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions