AFFiNE/packages/frontend/component/.storybook/preview.tsx

58 lines
1.3 KiB
TypeScript
Raw Normal View History

import './polyfill';
import '../src/theme';
2023-12-04 11:32:19 +03:00
import './preview.css';
import { ThemeProvider } from 'next-themes';
2023-12-04 11:32:19 +03:00
import type { ComponentType } from 'react';
import type { Preview } from '@storybook/react';
import React, { useEffect } from 'react';
import { ConfirmModalProvider } from '../src/ui/modal/confirm-modal';
import { setupGlobal } from '@affine/env/global';
setupGlobal();
2023-12-04 11:32:19 +03:00
export const parameters: Preview = {
argTypes: {
param: {
table: { category: 'Group' },
},
},
};
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
},
},
};
const useTheme = context => {
const { theme } = context.globals;
2023-12-04 11:32:19 +03:00
useEffect(() => {
document.documentElement.setAttribute('data-theme', theme);
}, [theme]);
2023-12-04 11:32:19 +03:00
};
export const decorators = [
(Story: ComponentType, context) => {
useTheme(context);
2023-12-04 11:32:19 +03:00
return (
<ThemeProvider themes={['dark', 'light']} enableSystem={true}>
<ConfirmModalProvider>
<Story {...context} />
</ConfirmModalProvider>
2023-12-04 11:32:19 +03:00
</ThemeProvider>
);
},
];
export const tags = ['autodocs'];