Created
March 17, 2022 08:18
-
-
Save fedek6/2414c46b8a561b7416475bffce750178 to your computer and use it in GitHub Desktop.
Sorybook with dark mode support for docs (using stitches, but this can be edited)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { DocsContainer as BaseContainer } from "@storybook/addon-docs/blocks"; | |
import { useDarkMode } from "storybook-dark-mode"; | |
import { themes } from "@storybook/theming"; | |
export const DocsContainer = ({ children, context }) => { | |
const dark = useDarkMode(); | |
return ( | |
<BaseContainer | |
context={{ | |
...context, | |
storyById: (id) => { | |
const storyContext = context.storyById(id); | |
return { | |
...storyContext, | |
parameters: { | |
...storyContext?.parameters, | |
docs: { | |
...storyContext?.parameters?.docs, | |
theme: dark ? themes.dark : themes.light, | |
}, | |
}, | |
}; | |
}, | |
}} | |
> | |
{children} | |
</BaseContainer> | |
); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { useDarkMode } from "storybook-dark-mode"; | |
import { themes } from "@storybook/theming"; | |
import { darkTheme } from "@retrolove-games/ui-themes"; | |
import { DocsContainer } from './DocsContainer'; | |
export const parameters = { | |
actions: { argTypesRegex: "^on[A-Z].*" }, | |
controls: { | |
matchers: { | |
color: /(background|color)$/i, | |
date: /Date$/, | |
}, | |
}, | |
viewMode: "docs", | |
docs: { | |
// theme: themes.dark, | |
container: DocsContainer, | |
}, | |
}; | |
export const decorators = [ | |
(Story) => ( | |
<div className={useDarkMode() ? darkTheme.className : "light"}> | |
<Story /> | |
</div> | |
), | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In StoryBook 7^, addon-docs has been moved into storybook and it seems context has changed for DocsContainer.
I updated import to this:
and the docs param: