Browse Source

fix: warning on conflicting theme of Icon

fix #12441
pull/12460/head
Wei Zhu 6 years ago
parent
commit
335f821aec
  1. 23
      components/icon/__tests__/index.test.js
  2. 8
      components/icon/index.tsx

23
components/icon/__tests__/index.test.js

@ -102,6 +102,29 @@ describe('Icon', () => {
}).not.toThrow();
});
describe('warning on conflicting theme', () => {
let errorSpy;
beforeEach(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterEach(() => {
errorSpy.mockRestore();
});
it('does not warn', () => {
mount(<Icon type="clock-circle-o" theme="outlined" />);
expect(errorSpy).not.toBeCalled();
});
it('warns', () => {
mount(<Icon type="clock-circle-o" theme="filled" />);
expect(errorSpy).toBeCalledWith(
"Warning: The icon name 'clock-circle-o' already specify a theme 'outlined', the 'theme' prop 'filled' will be ignored."
);
});
});
describe('`component` prop', () => {
it('can access to svg defs if has children', () => {
const wrapper = render(

8
components/icon/index.tsx

@ -121,10 +121,10 @@ const Icon: React.SFC<IconProps> = (props) => {
if (typeof type === 'string') {
let computedType = type;
if (theme) {
const alreadyHaveTheme = getThemeFromTypeName(type);
warning(!alreadyHaveTheme,
`This icon already has a theme '${alreadyHaveTheme}'.` +
` The prop 'theme' ${theme} will be ignored.`);
const themeInName = getThemeFromTypeName(type);
warning(!themeInName || theme === themeInName,
`The icon name '${type}' already specify a theme '${themeInName}',` +
` the 'theme' prop '${theme}' will be ignored.`);
}
computedType = withThemeSuffix(
removeTypeTheme(type),

Loading…
Cancel
Save