Skip to content

Commit

Permalink
feat: 多次主题切换时 css 变量保持合并状态
Browse files Browse the repository at this point in the history
  • Loading branch information
lucy-cl committed May 13, 2022
1 parent d2eeeff commit 4d7c66a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/themes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const themes: Themes = {
setTheme,
};
let currentThemeName = '';
let currentRawCss = {};

export function getTheme(name?: string) {
if (!name) {
Expand All @@ -74,14 +75,15 @@ export function setTheme(theme: string | Theme = defaultTheme, refreshChart: boo
newTheme = themeMap[theme].js;
currentThemeName = theme;
setThemeStyle(themeMap[theme].css);
currentRawCss = themeMap[theme].rawCSS;
// 打点
themeLog(theme);
} else if (typeof theme === 'object') {
// 传入对象,直接覆盖对应的key和css
newTheme = convertKey(theme);

// TODO 多次传入对象,css 每次都会在 current 的基础上直接处理,而不会集成前一次的结果。需要改进。
const newCSS = Object.assign({}, themeMap[currentThemeName].rawCSS, theme);
// 多次传入对象,css 会在 currentRawCss 的基础上处理
const newCSS = Object.assign({}, currentRawCss, theme);
setThemeStyle(convertCSS(newCSS));
// 打点
themeLog(newTheme.name || 'customTheme');
Expand Down

0 comments on commit 4d7c66a

Please sign in to comment.