mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 09:22:38 +03:00
2db3c933fa
- move to `component/ui` - add `AFFiNEDatePicker` & `BlocksuiteDatePicker` story - inline mode support - responsive support <picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/toeverything/AFFiNE/assets/39363750/320bef49-380f-40a2-b3b2-4b74dd2d8da4"> <img alt="" src="https://github.com/toeverything/AFFiNE/assets/39363750/fc9e7808-02fe-49a1-aa78-aea254fb1f9d"> </picture>
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import '../src/theme/global.css';
|
|
import './preview.css';
|
|
import { ThemeProvider, useTheme } from 'next-themes';
|
|
import type { ComponentType } from 'react';
|
|
import { useEffect } from 'react';
|
|
import { useDarkMode } from 'storybook-dark-mode';
|
|
|
|
import type { Preview } from '@storybook/react';
|
|
import React from 'react';
|
|
|
|
export const parameters: Preview = {
|
|
argTypes: {
|
|
param: {
|
|
table: { category: 'Group' },
|
|
},
|
|
},
|
|
globalTypes: {
|
|
theme: {
|
|
description: 'Global theme for components',
|
|
defaultValue: 'light',
|
|
toolbar: {
|
|
title: 'Theme',
|
|
icon: 'circlehollow',
|
|
items: ['light', 'dark'],
|
|
dynamicTitle: true,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const ThemeChange = () => {
|
|
const isDark = useDarkMode();
|
|
const theme = useTheme();
|
|
if (theme.resolvedTheme === 'dark' && !isDark) {
|
|
theme.setTheme('light');
|
|
} else if (theme.resolvedTheme === 'light' && isDark) {
|
|
theme.setTheme('dark');
|
|
}
|
|
return null;
|
|
};
|
|
|
|
const Component = () => {
|
|
const isDark = useDarkMode();
|
|
const theme = useTheme();
|
|
useEffect(() => {
|
|
theme.setTheme(isDark ? 'dark' : 'light');
|
|
}, [isDark]);
|
|
return null;
|
|
};
|
|
|
|
export const decorators = [
|
|
(Story: ComponentType, context) => {
|
|
return (
|
|
<ThemeProvider themes={['dark', 'light']} enableSystem={true}>
|
|
<ThemeChange />
|
|
<Component />
|
|
<Story {...context} />
|
|
</ThemeProvider>
|
|
);
|
|
},
|
|
];
|