aboutsummaryrefslogtreecommitdiffstats
path: root/.storybook/preview.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-09-19 15:47:08 +0200
committerArmand Philippot <git@armandphilippot.com>2023-09-19 19:16:58 +0200
commit03331c44276ec56e9f235e4d5ee75030455a753f (patch)
treeb9248a7db3090e02bf38fe573f2ea973ed8a1561 /.storybook/preview.tsx
parent2faf2e34331703b3bdea3eb487cb8799c8d65377 (diff)
build(deps): bump all dependencies
* MDX type has changed so some components props had to be updated * Since Storybook now supports TS, I renamed the main/preview files
Diffstat (limited to '.storybook/preview.tsx')
-rw-r--r--.storybook/preview.tsx66
1 files changed, 66 insertions, 0 deletions
diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx
new file mode 100644
index 0000000..2b7a466
--- /dev/null
+++ b/.storybook/preview.tsx
@@ -0,0 +1,66 @@
+import type { Decorator, Preview } from '@storybook/react';
+import { ThemeProvider, useTheme } from 'next-themes';
+import { FC, ReactNode, 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 '../src/styles/globals.scss';
+
+type ThemeWrapperProps = {
+ children: ReactNode;
+};
+
+// Create a component that listens for theme change.
+export const ThemeWrapper: FC<ThemeWrapperProps> = ({ children }) => {
+ const { setTheme } = useTheme();
+ const theme = useDarkMode() ? 'dark' : 'light';
+
+ useEffect(() => {
+ setTheme(theme);
+ }, [theme, setTheme]);
+
+ return <>{children}</>;
+};
+
+const withAllProviders: Decorator = (Story) => {
+ return (
+ <IntlProvider locale="en">
+ <ThemeProvider
+ defaultTheme="system"
+ enableColorScheme={true}
+ enableSystem={true}
+ >
+ <ThemeWrapper>
+ <Story />
+ </ThemeWrapper>
+ </ThemeProvider>
+ </IntlProvider>
+ );
+};
+
+const preview: Preview = {
+ decorators: [withAllProviders],
+ parameters: {
+ actions: { argTypesRegex: '^on[A-Z].*' },
+ controls: {
+ matchers: {
+ color: /(background|color)$/i,
+ date: /Date$/,
+ },
+ },
+ darkMode: {
+ // Override the default dark theme
+ dark: { ...dark },
+ // Override the default light theme
+ light: { ...light },
+ stylePreview: true,
+ },
+ docs: {
+ container: DocsContainer,
+ },
+ },
+};
+
+export default preview;