How to add theme and global style for Documentation-only MDX
See original GitHub issueI’m having trouble applying theme and global styles from styled-components for Documentation-only MDX. I followed the instruction written here to create a Documentation-only MDX. The problems is that since I don’t use <Story></Story> to wrap around my components, I can’t seem to apply the global styles using decorators.
Here is what I have to set decorators:
export const decorators = [
Story => (
<ThemeProvider theme={theme}>
<GlobalStyle />
<div style={{ backgroundColor: "#000" }}>
<Story />
</div>
</ThemeProvider>
),
];
and here is an example of my component in MDX:
<Canvas>
<Heading variant="h2">H2 Heading</Heading>
</Canvas>
The global styles does get applied if I write:
<Canvas>
<Story name="h2">
<Heading variant="h2">H2 Heading</Heading>
</Story>
</Canvas>
Is there anyway to apply the theme and global style without having the <Story> tag?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Allow MDX theming #12817 - storybookjs/storybook - GitHub
This would allow for fewer side effects from the global styles and ... #346 Make mdx docs readable for dark theme by applying...
Read more >Styling MDX Content - Theme UI
The theme.styles object combined with useThemeStylesWithMdx hook is the primary way to style content in MDX documents. This allows you to add typographic ......
Read more >Creating your themes - Docz
The themeConfig allows you to customize fonts, colors, spaces, styles properties and other project global variables. // src/gatsby-theme-docz/index.js import ...
Read more >Style Components Rendered By MDX with Theme UI in Gatsby
Theme UI provides a wrapper around the MDXProvider so you can add styling to components that are rendered in your MDX documents.
Read more >MDX Format - Storybook - JS.ORG
MDX Format. MDX is the syntax Storybook Docs uses to capture long-form Markdown documentation and stories in one file. You can also write...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For those who might be wondering how it is achieved at the end, here is my example:
Sure. You can export parameters globally from
.storybook/preview.js
https://storybook.js.org/docs/react/writing-stories/parameters#global-parameters