fix: theme error, close #1557 (#1558)

Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: daoyoucloud/tachybase#1558
This commit is contained in:
sealday 2024-09-23 16:28:48 +08:00
parent 588a02fedc
commit eff5bc3890
3 changed files with 8 additions and 7 deletions

View File

@ -14,8 +14,8 @@ const defaultTheme: ThemeConfig = {
// UI 配置组件 // UI 配置组件
colorSettings: '#2196f3', colorSettings: '#2196f3',
colorBgSettingsHover: 'rgba(241, 139, 98, 0.06)', colorBgSettingsHover: 'rgba(33,150,243, 0.06)',
colorBorderSettingsHover: 'rgba(241, 139, 98, 0.3)', colorBorderSettingsHover: 'rgba(33,150,243, 0.3)',
motionUnit: 0.03, motionUnit: 0.03,
motion: !process.env.__E2E__, motion: !process.env.__E2E__,
}, },

View File

@ -1,4 +1,4 @@
import React, { createContext, useCallback, useMemo, useRef } from 'react'; import React, { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react';
import { theme as antdTheme, ConfigProvider } from 'antd'; import { theme as antdTheme, ConfigProvider } from 'antd';
import _ from 'lodash'; import _ from 'lodash';
@ -29,11 +29,11 @@ const GlobalThemeContext = createContext<GlobalThemeContextProps>(null);
GlobalThemeContext.displayName = 'GlobalThemeContext'; GlobalThemeContext.displayName = 'GlobalThemeContext';
export const useGlobalTheme = () => { export const useGlobalTheme = () => {
return React.useContext(GlobalThemeContext) || ({ theme: {}, isDarkTheme: false } as GlobalThemeContextProps); return useContext(GlobalThemeContext) || ({ theme: {}, isDarkTheme: false } as GlobalThemeContextProps);
}; };
export const GlobalThemeProvider = ({ children, theme: themeFromProps }) => { export const GlobalThemeProvider = ({ children, theme: themeFromProps }) => {
const [theme, setTheme] = React.useState<ThemeConfig>(themeFromProps || defaultTheme); const [theme, setTheme] = useState<ThemeConfig>(themeFromProps || defaultTheme);
const currentSettingThemeRef = useRef<ThemeConfig>(null); const currentSettingThemeRef = useRef<ThemeConfig>(null);
const currentEditingThemeRef = useRef<ThemeItem>(null); const currentEditingThemeRef = useRef<ThemeItem>(null);
@ -82,7 +82,9 @@ export const GlobalThemeProvider = ({ children, theme: themeFromProps }) => {
return ( return (
<GlobalThemeContext.Provider value={value}> <GlobalThemeContext.Provider value={value}>
<ConfigProvider theme={defaultTheme}>
<ConfigProvider theme={theme}>{children}</ConfigProvider> <ConfigProvider theme={theme}>{children}</ConfigProvider>
</ConfigProvider>
</GlobalThemeContext.Provider> </GlobalThemeContext.Provider>
); );
}; };

View File

@ -33,6 +33,5 @@ export interface ThemeConfig extends _ThemeConfig {
} }
declare module 'antd-style' { declare module 'antd-style' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CustomToken extends TachybaseToken {} export interface CustomToken extends TachybaseToken {}
} }