2019-08-13 14:07:17 +08:00
|
|
|
/* eslint-disable camelcase */
|
|
|
|
import React from 'react';
|
|
|
|
import AntdIcon, { createFromIconfontCN } from '@ant-design/icons';
|
2019-12-31 11:54:39 +08:00
|
|
|
import { withThemeSuffix, removeTypeTheme, getThemeFromTypeName } from './utils';
|
2022-05-10 15:43:29 +08:00
|
|
|
import warning from '../../../../components/_util/warning';
|
2019-08-13 14:07:17 +08:00
|
|
|
|
|
|
|
const IconFont = createFromIconfontCN({
|
|
|
|
scriptUrl: '//at.alicdn.com/t/font_1329669_t1u72b9zk8s.js',
|
|
|
|
});
|
|
|
|
|
2022-08-05 13:45:46 +08:00
|
|
|
interface IconProps {
|
|
|
|
type: string;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CreateIconfont {
|
|
|
|
createFromIconfontCN: typeof createFromIconfontCN;
|
|
|
|
}
|
|
|
|
|
|
|
|
const OldIcon: React.FC<IconProps> = props => {
|
2019-08-13 14:07:17 +08:00
|
|
|
const { type, theme } = props;
|
|
|
|
let computedType = type;
|
|
|
|
if (theme) {
|
|
|
|
const themeInName = getThemeFromTypeName(type);
|
|
|
|
warning(
|
|
|
|
!themeInName || theme === themeInName,
|
|
|
|
'Icon',
|
|
|
|
`The icon name '${type}' already specify a theme '${themeInName}',` +
|
|
|
|
` the 'theme' prop '${theme}' will be ignored.`,
|
|
|
|
);
|
|
|
|
}
|
2019-12-31 11:54:39 +08:00
|
|
|
computedType = withThemeSuffix(removeTypeTheme(computedType), theme || 'outlined');
|
2019-08-13 14:07:17 +08:00
|
|
|
return <IconFont {...props} type={`icon-${computedType}`} />;
|
|
|
|
};
|
|
|
|
|
2022-08-05 13:45:46 +08:00
|
|
|
const Icon: React.FC<IconProps> & CreateIconfont = props =>
|
|
|
|
typeof props.type === 'string' ? <OldIcon {...props} /> : <AntdIcon {...props} />;
|
2019-08-13 14:07:17 +08:00
|
|
|
|
|
|
|
Icon.createFromIconfontCN = createFromIconfontCN;
|
|
|
|
|
|
|
|
export default Icon;
|