You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

6 years ago
import * as React from 'react';
import CopyToClipboard from 'react-copy-to-clipboard';
import { Icon as AntdIcon, Badge } from 'antd';
import { ThemeType, IconProps } from 'antd/es/icon';
import classNames from 'classnames';
const Icon: React.SFC<IconProps> = AntdIcon;
6 years ago
export interface CopyableIconProps {
type: string;
theme: ThemeType;
isNew: boolean;
justCopied: string | null;
onCopied: (type: string, text: string) => any;
6 years ago
}
const CopyableIcon: React.SFC<CopyableIconProps> = ({
6 years ago
type,
theme,
isNew,
justCopied,
onCopied,
6 years ago
}) => {
const className = classNames({
copied: justCopied === type,
outlined: theme === 'twoTone',
});
6 years ago
return (
<CopyToClipboard
6 years ago
text={
theme === 'outlined'
? `<Icon type="${type}" />`
: `<Icon type="${type}" theme="${theme}" />`
}
onCopy={(text: string) => onCopied(type, text)}
6 years ago
>
<li className={className}>
6 years ago
<Icon type={type} theme={theme} />
6 years ago
<span className="anticon-class">
6 years ago
<Badge dot={isNew}>{type}</Badge>
6 years ago
</span>
</li>
</CopyToClipboard>
);
};
export default CopyableIcon;