mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-14 16:19:15 +08:00
7b94e0bfb2
* refactor: replace deprecated React.SFC with React.FunctionComponent * refactoring: use typedef FC
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import * as React from 'react';
|
|
import CopyToClipboard from 'react-copy-to-clipboard';
|
|
import { Badge } from 'antd';
|
|
import classNames from 'classnames';
|
|
import * as AntdIcons from '@ant-design/icons';
|
|
import { ThemeType } from './index';
|
|
|
|
const allIcons: {
|
|
[key: string]: any;
|
|
} = AntdIcons;
|
|
|
|
export interface CopyableIconProps {
|
|
name: string;
|
|
isNew: boolean;
|
|
theme: ThemeType;
|
|
justCopied: string | null;
|
|
onCopied: (type: string, text: string) => any;
|
|
}
|
|
|
|
const CopyableIcon: React.FC<CopyableIconProps> = ({
|
|
name,
|
|
isNew,
|
|
justCopied,
|
|
onCopied,
|
|
theme,
|
|
}) => {
|
|
const className = classNames({
|
|
copied: justCopied === name,
|
|
[theme]: !!theme,
|
|
});
|
|
return (
|
|
<CopyToClipboard text={`<${name} />`} onCopy={(text: string) => onCopied(name, text)}>
|
|
<li className={className}>
|
|
{React.createElement(allIcons[name])}
|
|
<span className="anticon-class">
|
|
<Badge dot={isNew}>{name}</Badge>
|
|
</span>
|
|
</li>
|
|
</CopyToClipboard>
|
|
);
|
|
};
|
|
|
|
export default CopyableIcon;
|