mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 23:59:12 +08:00
73e541911b
* refactor: rewrite header by FunctionComponent * refactor: rewrite footer by FunctionComponent * fix: strong type * refactor: rewrite IconDisplay & PicSearcher & Category by FunctionComponent * style: formatting * pref: add useCallback/useMemo * refactor: use typescript refactor javascript * fix: remove string * fix: fix eslint
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
/* eslint-disable camelcase */
|
|
import React from 'react';
|
|
import AntdIcon, { createFromIconfontCN } from '@ant-design/icons';
|
|
import { withThemeSuffix, removeTypeTheme, getThemeFromTypeName } from './utils';
|
|
import warning from '../../../../components/_util/warning';
|
|
|
|
const IconFont = createFromIconfontCN({
|
|
scriptUrl: '//at.alicdn.com/t/font_1329669_t1u72b9zk8s.js',
|
|
});
|
|
|
|
interface IconProps {
|
|
type: string;
|
|
theme: string;
|
|
}
|
|
|
|
interface CreateIconfont {
|
|
createFromIconfontCN: typeof createFromIconfontCN;
|
|
}
|
|
|
|
const OldIcon: React.FC<IconProps> = props => {
|
|
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.`,
|
|
);
|
|
}
|
|
computedType = withThemeSuffix(removeTypeTheme(computedType), theme || 'outlined');
|
|
return <IconFont {...props} type={`icon-${computedType}`} />;
|
|
};
|
|
|
|
const Icon: React.FC<IconProps> & CreateIconfont = props =>
|
|
typeof props.type === 'string' ? <OldIcon {...props} /> : <AntdIcon {...props} />;
|
|
|
|
Icon.createFromIconfontCN = createFromIconfontCN;
|
|
|
|
export default Icon;
|