mirror of
https://github.com/mantinedev/next-app-template.git
synced 2025-11-09 20:12:02 +10:00
27 lines
950 B
TypeScript
27 lines
950 B
TypeScript
import '@mantine/core/styles.css';
|
|
|
|
import React, { useEffect } from 'react';
|
|
import { addons } from '@storybook/preview-api';
|
|
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';
|
|
import { MantineProvider, useMantineColorScheme } from '@mantine/core';
|
|
import { theme } from '../theme';
|
|
|
|
const channel = addons.getChannel();
|
|
|
|
function ColorSchemeWrapper({ children }: { children: React.ReactNode }) {
|
|
const { setColorScheme } = useMantineColorScheme();
|
|
const handleColorScheme = (value: boolean) => setColorScheme(value ? 'dark' : 'light');
|
|
|
|
useEffect(() => {
|
|
channel.on(DARK_MODE_EVENT_NAME, handleColorScheme);
|
|
return () => channel.off(DARK_MODE_EVENT_NAME, handleColorScheme);
|
|
}, [channel]);
|
|
|
|
return <>{children}</>;
|
|
}
|
|
|
|
export const decorators = [
|
|
(renderStory: any) => <ColorSchemeWrapper>{renderStory()}</ColorSchemeWrapper>,
|
|
(renderStory: any) => <MantineProvider theme={theme}>{renderStory()}</MantineProvider>,
|
|
];
|