-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon-docs: Decorators for MDX and DocsPage #8526
Comments
I think you can do this already, though with a slightly less flexible mechanism. Let's suppose I want to wrap every docs page with a red border. It should be possible using something like this:
|
Just for documentation completeness purposes, the following is also an equivalent:
|
Super cool, I will try, thank you! |
The difference between the two is that my example will be applied to both DocsPage and MDX pages, whereas @atanasster 's will just be applied to DocsPage pages 😉 |
ah, yes - I missed that for .MDX |
I tried
Since i am using MDX and it doesn't seem to work with beta.9. |
@patricklafrance I was wrong. My snippet only works for DocsPage. The MDX compiler hard codes the container:
It needs to be updated to inject the mdxStoryNameToId into the context some other way. |
Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-beta.10 containing PR #8968 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
We should add this to the docs. |
@amcdnl it's currently documented here: https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#overwriting-docs-container @jonniebigodes i guess we should get this into the main docs site |
+1 — I was just searching for how to do exactly this |
How do we do this in storybook v7? The linked doc no longer exists. Attempting to define a container in either the My larger goal is to have some CSS variables defined that are defined in a component that leverages <Meta
title="Title"
parameters={{
docs: {
container: ({ children, context }) => (
<DocsContainer context={context}>
<style
dangerouslySetInnerHTML={{
__html: `
body {
background-color: red !important;
}
`,
}}
></style>
{children}
</DocsContainer>
),
},
}}
/> |
@pm0u Here's the link to the doc that allows to do this: Customize the docs container |
@Pegase745 Thanks - I eventually got this to work. It seems that my test case was not a good one, as the CSS was there in fact but a lower element has The initial issue I had with pulling in next/head here did persist, so I had to inject anything in the head separately from the means I was using in production. There was a couple of confounding issues here. |
All of the options using |
I did a super ugly hack for my own use case where I wanted to apply a React theme provider for some theme-based MDX docs. It does a few type casts but it works. const CustomDocsContainer = (props: any) => {
const children = props.children as React.ReactElement;
// check if children is of type MDXContent
const isMDXContent = (children.type as any).name === `MDXContent`;
if (isMDXContent) {
// get theme from globals
const theme = (props.context.store.userGlobals.globals.theme ||
`light`) as Theme;
return (
<ThemeProvider defaultTheme={theme} key="theme">
<DocsContainer {...props} />
</ThemeProvider>
);
}
return <DocsContainer {...props} />;
};
const preview: Preview = {
parameters: {
docs: {
container: CustomDocsContainer,
},
},
};
export default preview; |
Is your feature request related to a problem? Please describe.
I would like to be able to add custom widgets at the top of all my MDX pages.
Ideally, I would define those widgets once in some kind of container that would wrap all my MDX pages.
Describe the solution you'd like
It could be achieve by a decorator with the same behavior as the story decorator but for MDX and DocsPage.
Describe alternatives you've considered
The text was updated successfully, but these errors were encountered: