fix the default theme outlined

This commit is contained in:
HeskeyBaozi 2018-09-02 19:48:57 +08:00 committed by 偏右
parent 4ceeab77d1
commit 3859a60d3e
2 changed files with 24 additions and 16 deletions

View File

@ -3,7 +3,10 @@ import classNames from 'classnames';
import * as allIcons from '@ant-design/icons';
import ReactIcon from '@ant-design/icons-react';
import createFromIconfontCN from './IconFont';
import { svgBaseProps, withThemeSuffix } from './utils';
import {
svgBaseProps, withThemeSuffix,
removeTypeTheme, getThemeFromTypeName,
} from './utils';
import warning from '../_util/warning';
import { getTwoToneColor, setTwoToneColor } from './twoTonePrimaryColor';
@ -115,8 +118,15 @@ const Icon: React.SFC<IconProps> = (props) => {
if (typeof type === 'string') {
let computedType = type;
if (theme) {
computedType = withThemeSuffix(type, theme);
const alreadyHaveTheme = getThemeFromTypeName(type);
warning(!alreadyHaveTheme,
`This icon already has a theme '${alreadyHaveTheme}'.` +
` The prop 'theme' ${theme} will be ignored.`);
}
computedType = withThemeSuffix(
removeTypeTheme(type),
theme || 'outlined',
);
return (
<i className={classString} title={title} style={style} onClick={onClick}>
<ReactIcon

View File

@ -26,22 +26,20 @@ export function getThemeFromTypeName(type: string): ThemeType | null {
return result;
}
export function removeTypeTheme(type: string) {
return type.replace(fillTester, '').replace(outlineTester, '').replace(twoToneTester, '');
}
export function withThemeSuffix(type: string, theme: ThemeType) {
const alreadyHaveTheme = getThemeFromTypeName(type);
warning(!alreadyHaveTheme,
`This icon already has a theme '${alreadyHaveTheme}'.` +
` The prop 'theme' will be ignored.`);
let result = type;
if (!alreadyHaveTheme) {
if (theme === 'filled') {
result += '-fill';
} else if (theme === 'outlined') {
result += '-o';
} else if (theme === 'twoTone') {
result += '-twotone';
} else {
warning(false, `This icon '${type}' has unknown theme '${theme}'`);
}
if (theme === 'filled') {
result += '-fill';
} else if (theme === 'outlined') {
result += '-o';
} else if (theme === 'twoTone') {
result += '-twotone';
} else {
warning(false, `This icon '${type}' has unknown theme '${theme}'`);
}
return result;
}