refactor: unify theme (#1303)

This commit is contained in:
Himself65
2023-03-04 01:36:20 -06:00
committed by GitHub
parent fe0d78b2d6
commit 4e9f0c97a1
43 changed files with 779 additions and 543 deletions

View File

@@ -1,10 +1,17 @@
import { ThemeProvider as EmotionThemeProvider } from '@emotion/react';
import emotionStyled from '@emotion/styled';
import { CssBaseline } from '@mui/material';
import {
createTheme as createMuiTheme,
css,
keyframes,
styled,
ThemeProvider as MuiThemeProvider,
} from '@mui/material/styles';
import type { PropsWithChildren } from 'react';
import { useMemo } from 'react';
import { AffineTheme } from './types';
export { css, keyframes } from '@emotion/react';
export const styled = emotionStyled;
export { css, keyframes, styled };
export const ThemeProvider = ({
theme,
@@ -12,5 +19,11 @@ export const ThemeProvider = ({
}: PropsWithChildren<{
theme: AffineTheme;
}>) => {
return <EmotionThemeProvider theme={theme}>{children}</EmotionThemeProvider>;
const muiTheme = useMemo(() => createMuiTheme(theme), [theme]);
return (
<MuiThemeProvider theme={muiTheme}>
<CssBaseline />
{children}
</MuiThemeProvider>
);
};

View File

@@ -2,7 +2,7 @@ import '@emotion/react';
import type { EditorContainer } from '@blocksuite/editor';
import { AffineTheme, AffineThemeCSSVariables, ThemeMode } from './types';
import { AffineTheme, AffineThemeCSSVariables } from './types';
const basicFontFamily =
'apple-system, BlinkMacSystemFont,Helvetica Neue, Tahoma, PingFang SC, Microsoft Yahei, Arial,Hiragino Sans GB, sans-serif, Apple Color Emoji, Segoe UI Emoji,Segoe UI Symbol, Noto Color Emoji';
@@ -11,7 +11,9 @@ export const getLightTheme = (
editorMode: EditorContainer['mode']
): AffineTheme => {
return {
mode: 'light',
palette: {
mode: 'light',
},
editorMode,
colors: {
primaryColor: '#6880FF',
@@ -92,7 +94,9 @@ export const getDarkTheme = (
return {
...lightTheme,
mode: 'dark',
palette: {
mode: 'dark',
},
colors: {
primaryColor: '#6880FF',
pageBackground: '#2c2c2c',
@@ -143,11 +147,10 @@ export const getDarkTheme = (
};
export const globalThemeVariables: (
mode: ThemeMode,
theme: AffineTheme
) => AffineThemeCSSVariables = (mode, theme) => {
) => AffineThemeCSSVariables = theme => {
return {
'--affine-theme-mode': theme.mode,
'--affine-theme-mode': theme.palette.mode,
'--affine-editor-mode': theme.editorMode,
'--affine-primary-color': theme.colors.primaryColor,

View File

@@ -14,8 +14,10 @@ export type ThemeProviderValue = {
};
export interface AffineTheme {
mode: Theme;
editorMode: EditorContainer['mode'];
palette: {
mode: 'light' | 'dark';
};
colors: {
primaryColor: string;