diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-22 17:39:39 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-22 17:39:39 +0200 |
| commit | 3ed7f185e82c0cc87c63b75dc8cddfecc5c608ce (patch) | |
| tree | b1b314cec900ebb3f671269f6fc9560242e90a0a /.storybook/preview.js | |
| parent | 321dae4a47594af83269fa560b375965d7f35763 (diff) | |
chore(storybook): use custom themes and add dark mode support
Diffstat (limited to '.storybook/preview.js')
| -rw-r--r-- | .storybook/preview.js | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/.storybook/preview.js b/.storybook/preview.js index e30927b..9df7514 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -1,6 +1,12 @@ -import '@styles/globals.scss'; import * as NextImage from 'next/image'; +import { ThemeProvider, useTheme } from 'next-themes'; +import { useEffect } from 'react'; import { IntlProvider } from 'react-intl'; +import { useDarkMode } from 'storybook-dark-mode'; +import { DocsContainer } from './overrides/docs-container'; +import dark from './themes/dark'; +import light from './themes/light'; +import '@styles/globals.scss'; const OriginalNextImage = NextImage.default; @@ -27,12 +33,42 @@ export const parameters = { date: /Date$/, }, }, + darkMode: { + // Override the default dark theme + dark: { ...dark }, + // Override the default light theme + light: { ...light }, + stylePreview: true, + }, + docs: { + container: DocsContainer, + }, +}; + +// Create a component that listens for theme change. +export const ThemeWrapper = (props) => { + const { setTheme } = useTheme(); + const theme = useDarkMode() ? 'dark' : 'light'; + + useEffect(() => { + setTheme(theme); + }, [theme, setTheme]); + + return <>{props.children}</>; }; export const decorators = [ (Story) => ( <IntlProvider locale="en"> - <Story /> + <ThemeProvider + defaultTheme="system" + enableColorScheme={true} + enableSystem={true} + > + <ThemeWrapper> + <Story /> + </ThemeWrapper> + </ThemeProvider> </IntlProvider> ), ]; |
