2024-10-24 10:38:45 +03:00
|
|
|
import { getOrCreateI18n, I18nextProvider } from '@affine/i18n';
|
|
|
|
import { ThemeProvider } from 'next-themes';
|
|
|
|
import type { ComponentType } from 'react';
|
2024-09-19 10:18:19 +03:00
|
|
|
import '../src/theme';
|
2024-10-24 10:38:45 +03:00
|
|
|
import './polyfill';
|
2023-12-04 11:32:19 +03:00
|
|
|
import './preview.css';
|
|
|
|
|
2024-10-22 06:15:33 +03:00
|
|
|
import type { Preview } from '@storybook/react';
|
2024-10-24 10:38:45 +03:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { ConfirmModalProvider } from '../src/ui/modal/confirm-modal';
|
|
|
|
|
2024-08-21 09:04:39 +03:00
|
|
|
import { setupGlobal } from '@affine/env/global';
|
2024-10-24 10:38:45 +03:00
|
|
|
import { useTheme as useNextTheme } from 'next-themes';
|
2024-08-21 09:04:39 +03:00
|
|
|
|
|
|
|
setupGlobal();
|
2023-12-04 11:32:19 +03:00
|
|
|
|
|
|
|
export const parameters: Preview = {
|
|
|
|
argTypes: {
|
|
|
|
param: {
|
|
|
|
table: { category: 'Group' },
|
|
|
|
},
|
|
|
|
},
|
2024-09-03 18:18:23 +03:00
|
|
|
};
|
|
|
|
export const globalTypes = {
|
|
|
|
theme: {
|
|
|
|
description: 'Global theme for components',
|
|
|
|
defaultValue: 'light',
|
|
|
|
toolbar: {
|
|
|
|
title: 'theme',
|
|
|
|
icon: 'circlehollow',
|
|
|
|
dynamic: true,
|
|
|
|
items: [
|
|
|
|
{ value: 'light', title: 'Light', icon: 'sun' },
|
|
|
|
{ value: 'dark', title: 'Dark', icon: 'moon' },
|
|
|
|
],
|
2023-12-04 11:32:19 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-10-22 06:15:33 +03:00
|
|
|
const ThemeToggle = ({ context }) => {
|
2024-09-03 18:18:23 +03:00
|
|
|
const { theme } = context.globals;
|
2024-10-22 06:15:33 +03:00
|
|
|
const { setTheme } = useNextTheme();
|
2023-12-04 11:32:19 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-10-22 06:15:33 +03:00
|
|
|
setTheme(theme);
|
2024-09-03 18:18:23 +03:00
|
|
|
}, [theme]);
|
2024-10-22 06:15:33 +03:00
|
|
|
|
|
|
|
return null;
|
2023-12-04 11:32:19 +03:00
|
|
|
};
|
|
|
|
|
2024-10-24 10:38:45 +03:00
|
|
|
const i18n = getOrCreateI18n();
|
|
|
|
|
2023-12-04 11:32:19 +03:00
|
|
|
export const decorators = [
|
|
|
|
(Story: ComponentType, context) => {
|
|
|
|
return (
|
|
|
|
<ThemeProvider themes={['dark', 'light']} enableSystem={true}>
|
2024-10-22 06:15:33 +03:00
|
|
|
<ThemeToggle context={context} />
|
2024-10-24 10:38:45 +03:00
|
|
|
<I18nextProvider i18n={i18n}>
|
|
|
|
<ConfirmModalProvider>
|
|
|
|
<Story {...context} />
|
|
|
|
</ConfirmModalProvider>
|
|
|
|
</I18nextProvider>
|
2023-12-04 11:32:19 +03:00
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
];
|
2024-08-16 14:42:24 +03:00
|
|
|
export const tags = ['autodocs'];
|