mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix: remove mui theme provider (#2055)
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { useEffect, ComponentType } from 'react';
|
||||
import { ThemeProvider, useTheme } from 'next-themes';
|
||||
import '@blocksuite/editor/themes/affine.css';
|
||||
import '../src/theme/global.css';
|
||||
|
||||
import {
|
||||
AffineCssVariables,
|
||||
AffineMuiThemeProvider,
|
||||
getTheme,
|
||||
muiThemes,
|
||||
} from '@affine/component';
|
||||
import '@affine/component/theme/global.css';
|
||||
import '@affine/component/theme/theme.css';
|
||||
import { useDarkMode } from 'storybook-dark-mode';
|
||||
import { GlobalStyles } from '@mui/material';
|
||||
import kebabCase from 'kebab-case';
|
||||
|
||||
export const parameters = {
|
||||
actions: { argTypesRegex: '^on[A-Z].*' },
|
||||
controls: {
|
||||
@@ -21,35 +15,22 @@ export const parameters = {
|
||||
},
|
||||
};
|
||||
|
||||
export const decorators = [
|
||||
(Story: React.ComponentType) => {
|
||||
const isDark = useDarkMode();
|
||||
const Component = () => {
|
||||
const isDark = useDarkMode();
|
||||
const theme = useTheme();
|
||||
useEffect(() => {
|
||||
theme.setTheme(isDark ? 'dark' : 'light');
|
||||
}, [isDark]);
|
||||
return null;
|
||||
};
|
||||
|
||||
const theme = useMemo(
|
||||
() => getTheme(isDark ? 'dark' : 'light', 'page'),
|
||||
[isDark]
|
||||
);
|
||||
export const decorators = [
|
||||
(Story: ComponentType) => {
|
||||
return (
|
||||
<AffineMuiThemeProvider theme={muiThemes}>
|
||||
<GlobalStyles
|
||||
styles={{
|
||||
':root': {
|
||||
...Object.entries(theme).reduce((variables, [key, value]) => {
|
||||
variables[
|
||||
`--affine-${kebabCase(key)}` as keyof AffineCssVariables
|
||||
] = value;
|
||||
return variables;
|
||||
}, {} as AffineCssVariables),
|
||||
},
|
||||
html: {
|
||||
fontFamily: theme.fontFamily,
|
||||
fontSize: theme.fontBase,
|
||||
lineHeight: theme.lineHeight,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<ThemeProvider>
|
||||
<Component />
|
||||
<Story />
|
||||
</AffineMuiThemeProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useTheme } from '@mui/material';
|
||||
import { useTheme } from 'next-themes';
|
||||
import type { FC } from 'react';
|
||||
|
||||
import { InternalLottie } from '../internal-lottie';
|
||||
@@ -16,8 +16,8 @@ export const AffineLoading: FC<AffineLoadingProps> = ({
|
||||
autoplay = false,
|
||||
autoReverse = false,
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const isDark = theme.palette.mode === 'dark';
|
||||
const { theme } = useTheme();
|
||||
const isDark = theme === 'dark';
|
||||
return (
|
||||
<InternalLottie
|
||||
key={isDark ? 'dark' : 'light'}
|
||||
|
||||
@@ -48,7 +48,7 @@ export const StyledCard = styled('div')<{
|
||||
...displayFlex('flex-start', 'flex-start'),
|
||||
marginBottom: '24px',
|
||||
transition: 'background .2s',
|
||||
background: theme.palette.mode === 'light' ? '#FFF' : '#2C2C2C',
|
||||
background: 'var(--affine-background-primary-color)',
|
||||
position: 'relative',
|
||||
':hover': {
|
||||
background: 'var(--affine-hover-color)',
|
||||
|
||||
32
packages/component/src/theme/theme.css.ts
Normal file
32
packages/component/src/theme/theme.css.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { AffineCssVariables } from '@affine/component';
|
||||
import { globalStyle } from '@vanilla-extract/css';
|
||||
import kebabCase from 'kebab-case';
|
||||
|
||||
import { darkTheme, lightTheme } from '../styles/theme';
|
||||
|
||||
globalStyle('body', {
|
||||
color: 'var(--affine-text-primary-color)',
|
||||
fontFamily: 'var(--affine-font-family)',
|
||||
fontSize: 'var(--affine-font-base)',
|
||||
lineHeight: 'var(--affine-font-height)',
|
||||
});
|
||||
|
||||
globalStyle('html', {
|
||||
vars: {
|
||||
...Object.entries(lightTheme).reduce((variables, [key, value]) => {
|
||||
variables[`--affine-${kebabCase(key)}` as keyof AffineCssVariables] =
|
||||
value;
|
||||
return variables;
|
||||
}, {} as AffineCssVariables),
|
||||
},
|
||||
});
|
||||
|
||||
globalStyle('html[data-theme="dark"]', {
|
||||
vars: {
|
||||
...Object.entries(darkTheme).reduce((variables, [key, value]) => {
|
||||
variables[`--affine-${kebabCase(key)}` as keyof AffineCssVariables] =
|
||||
value;
|
||||
return variables;
|
||||
}, {} as AffineCssVariables),
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user