From 3ed7f185e82c0cc87c63b75dc8cddfecc5c608ce Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sun, 22 May 2022 17:39:39 +0200 Subject: chore(storybook): use custom themes and add dark mode support --- .storybook/preview.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to '.storybook/preview.js') 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) => ( - + + + + + ), ]; -- cgit v1.2.3