diff options
Diffstat (limited to '.storybook')
| -rw-r--r-- | .storybook/main.js | 40 | ||||
| -rw-r--r-- | .storybook/main.ts | 47 | ||||
| -rw-r--r-- | .storybook/manager.ts (renamed from .storybook/manager.js) | 0 | ||||
| -rw-r--r-- | .storybook/preview.js | 56 | ||||
| -rw-r--r-- | .storybook/preview.tsx | 66 | ||||
| -rw-r--r-- | .storybook/themes/common.ts (renamed from .storybook/themes/common.js) | 0 | ||||
| -rw-r--r-- | .storybook/themes/dark.ts (renamed from .storybook/themes/dark.js) | 0 | ||||
| -rw-r--r-- | .storybook/themes/light.ts (renamed from .storybook/themes/light.js) | 0 |
8 files changed, 113 insertions, 96 deletions
diff --git a/.storybook/main.js b/.storybook/main.js deleted file mode 100644 index ca18e6b..0000000 --- a/.storybook/main.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @typedef {import('webpack').Configuration} WebpackConfig - */ - -const storybookConfig = { - stories: ['../src/**/*.stories.@(md|mdx|js|jsx|ts|tsx)'], - addons: [ - '@storybook/addon-links', - '@storybook/addon-essentials', - '@storybook/addon-interactions', - 'storybook-addon-next', - 'storybook-dark-mode', - ], - framework: '@storybook/react', - core: { - builder: 'webpack5', - }, - staticDirs: ['../public'], - /** - * @param {WebpackConfig} config - * @return {Promise<WebpackConfig>} - */ - webpackFinal: async (config) => { - // Use SVGR for SVG files. See: https://medium.com/@derek_19900/config-storybook-4-to-use-svgr-webpack-plugin-22cb1152f004 - const rules = config.module.rules; - const fileLoaderRule = rules.find((rule) => rule.test.test('.svg')); - fileLoaderRule.exclude = /\.svg$/; - rules.push({ - test: /\.svg$/, - use: [{ loader: '@svgr/webpack', options: { dimensions: false } }], - }); - - /** @type {import('next').NextConfig} */ - const nextConfig = require('../next.config'); - - return { ...config, ...nextConfig.webpack }; - }, -}; - -module.exports = storybookConfig; diff --git a/.storybook/main.ts b/.storybook/main.ts new file mode 100644 index 0000000..8257c59 --- /dev/null +++ b/.storybook/main.ts @@ -0,0 +1,47 @@ +import type { StorybookConfig } from '@storybook/nextjs'; +import { RuleSetRule } from 'webpack'; + +const config: StorybookConfig = { + stories: [ + '../src/**!(content)/*.mdx', + '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)', + ], + addons: [ + '@storybook/addon-links', + '@storybook/addon-essentials', + '@storybook/addon-interactions', + '@storybook/addon-onboarding', + 'storybook-dark-mode', + ], + framework: { + name: '@storybook/nextjs', + options: {}, + }, + docs: { + autodocs: 'tag', + }, + staticDirs: ['../public'], + webpackFinal: async (config) => { + // Use SVGR for SVG files. See: https://medium.com/@derek_19900/config-storybook-4-to-use-svgr-webpack-plugin-22cb1152f004 + const rules = config.module?.rules as RuleSetRule[]; + const fileLoaderRule = rules.find( + (rule) => rule?.test instanceof RegExp && rule.test.test('.svg') + ); + + if (fileLoaderRule) fileLoaderRule.exclude = /\.svg$/; + + rules.push({ + test: /\.svg$/, + use: [{ loader: '@svgr/webpack', options: { dimensions: false } }], + }); + + /** @type {import('next').NextConfig} */ + const nextConfig = require('../next.config'); + + return { + ...config, + ...nextConfig.webpack, + }; + }, +}; +export default config; diff --git a/.storybook/manager.js b/.storybook/manager.ts index 945c246..945c246 100644 --- a/.storybook/manager.js +++ b/.storybook/manager.ts diff --git a/.storybook/preview.js b/.storybook/preview.js deleted file mode 100644 index ce30b56..0000000 --- a/.storybook/preview.js +++ /dev/null @@ -1,56 +0,0 @@ -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 '../src/styles/globals.scss'; - -export const 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, - }, -}; - -// 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"> - <ThemeProvider - defaultTheme="system" - enableColorScheme={true} - enableSystem={true} - > - <ThemeWrapper> - <Story /> - </ThemeWrapper> - </ThemeProvider> - </IntlProvider> - ), -]; 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; diff --git a/.storybook/themes/common.js b/.storybook/themes/common.ts index 17619c2..17619c2 100644 --- a/.storybook/themes/common.js +++ b/.storybook/themes/common.ts diff --git a/.storybook/themes/dark.js b/.storybook/themes/dark.ts index e23703b..e23703b 100644 --- a/.storybook/themes/dark.js +++ b/.storybook/themes/dark.ts diff --git a/.storybook/themes/light.js b/.storybook/themes/light.ts index d445272..d445272 100644 --- a/.storybook/themes/light.js +++ b/.storybook/themes/light.ts |
