Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(2377): registerTheme 时,需要和基础主题进行合并 #2416

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, lowerCase } from '@antv/util';
import { deepMix, get, lowerCase } from '@antv/util';
import { LooseObject, StyleSheet } from '../interface';

import { createThemeByStylesheet } from '../util/theme';
Expand All @@ -25,5 +25,5 @@ export function getTheme(theme?: string): LooseObject {
* @param value 具体的主题配置。
*/
export function registerTheme(theme: string, value: LooseObject) {
Themes[lowerCase(theme)] = value;
Themes[lowerCase(theme)] = deepMix({}, Themes.default, value);
}
16 changes: 16 additions & 0 deletions tests/bugs/2377-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { registerTheme, getTheme } from '../../src';
import { createDiv } from '../util/dom';
import { deepMix } from '@antv/util';

describe('2377', () => {
it('2377', () => {
// Step 1: 注册主题
registerTheme('newTheme', {
defaultColor: 'red',
});

expect(getTheme('newTheme')).toEqual(deepMix({}, getTheme('default'), {
defaultColor: 'red',
}));
});
});
6 changes: 4 additions & 2 deletions tests/unit/theme/index-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getTheme, registerTheme } from '../../../src';
import { deepMix } from '@antv/util';

describe('theme', () => {
test('theme API', () => {
const defaultTheme = getTheme('default');
expect(getTheme()).toEqual(getTheme('default'));

// 都是 default
Expand All @@ -10,7 +12,7 @@ describe('theme', () => {
registerTheme('default', {});
registerTheme('a', { a: 1 });

expect(getTheme('a')).toEqual({ a: 1 });
expect(getTheme('default')).toEqual({});
expect(getTheme('a')).toEqual(deepMix({}, defaultTheme, { a: 1 }));
expect(getTheme('default')).toEqual(defaultTheme);
});
});