2024-03-23 09:33:25 +03:00
|
|
|
import './polyfill';
|
2024-09-19 10:18:19 +03:00
|
|
|
import '../src/theme';
|
2023-12-04 11:32:19 +03:00
|
|
|
import './preview.css';
|
2024-09-03 18:18:23 +03:00
|
|
|
import { ThemeProvider } from 'next-themes';
|
2023-12-04 11:32:19 +03:00
|
|
|
import type { ComponentType } from 'react';
|
|
|
|
|
|
|
|
import type { Preview } from '@storybook/react';
|
2024-09-03 18:18:23 +03:00
|
|
|
import React, { useEffect } from 'react';
|
2024-03-27 16:30:30 +03:00
|
|
|
import { ConfirmModalProvider } from '../src/ui/modal/confirm-modal';
|
2024-08-21 09:04:39 +03:00
|
|
|
import { setupGlobal } from '@affine/env/global';
|
|
|
|
|
|
|
|
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-09-03 18:18:23 +03:00
|
|
|
const useTheme = context => {
|
|
|
|
const { theme } = context.globals;
|
2023-12-04 11:32:19 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-09-03 18:18:23 +03:00
|
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
|
|
}, [theme]);
|
2023-12-04 11:32:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const decorators = [
|
|
|
|
(Story: ComponentType, context) => {
|
2024-09-03 18:18:23 +03:00
|
|
|
useTheme(context);
|
2023-12-04 11:32:19 +03:00
|
|
|
return (
|
|
|
|
<ThemeProvider themes={['dark', 'light']} enableSystem={true}>
|
2024-03-27 16:30:30 +03:00
|
|
|
<ConfirmModalProvider>
|
|
|
|
<Story {...context} />
|
|
|
|
</ConfirmModalProvider>
|
2023-12-04 11:32:19 +03:00
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
];
|
2024-08-16 14:42:24 +03:00
|
|
|
export const tags = ['autodocs'];
|