mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
2cdf586291
* chore: fix lint * chore: fix lint * test: fix 16 * fix: lint
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import * as React from 'react';
|
|
import CopyToClipboard from 'react-copy-to-clipboard';
|
|
import classNames from 'classnames';
|
|
import * as AntdIcons from '@ant-design/icons';
|
|
import { Badge, message } from 'antd';
|
|
import type { 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,
|
|
});
|
|
const onCopy = (text: string, result: boolean) => {
|
|
if (result) {
|
|
onCopied(name, text);
|
|
} else {
|
|
message.error('Copy icon name failed, please try again.');
|
|
}
|
|
};
|
|
return (
|
|
<CopyToClipboard text={`<${name} />`} onCopy={onCopy}>
|
|
<li className={className}>
|
|
{React.createElement(allIcons[name])}
|
|
<span className="anticon-class">
|
|
<Badge dot={isNew}>{name}</Badge>
|
|
</span>
|
|
</li>
|
|
</CopyToClipboard>
|
|
);
|
|
};
|
|
|
|
export default CopyableIcon;
|