Is using a theme with components rendered in MDX files possible? #25134
Unanswered
aldrichdev
asked this question in
Help
Replies: 1 comment 1 reply
-
Things I found while researching this problem:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
If I render a basic MUI component in an
.mdx
file like this:Where
Typography
is Material UI's component anddisplaySmDesktop
is a custom typography defined in my theme that works outside of.mdx
files..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
.mdx
file, 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.).mdx
page 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
.mdx
files do not usepreview.tsx
like stories do, so myThemeProvider
wrapper isn't getting applied, therefore no theme context?Additional information
I am using MUI themes and Emotion.
Storybook version: 7.2.3
main.ts
This 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