Jiarenxiang | 38dcb05 | 2025-03-13 16:40:09 +0800 | [diff] [blame] | 1 | import * as React from 'react'; |
| 2 | import { Tooltip } from 'antd'; |
| 3 | import classNames from 'classnames'; |
| 4 | import * as AntdIcons from '@ant-design/icons'; |
| 5 | import type { ThemeType } from './index'; |
| 6 | import styles from './style.less'; |
| 7 | |
| 8 | const allIcons: { |
| 9 | [key: string]: any; |
| 10 | } = AntdIcons; |
| 11 | |
| 12 | export interface CopyableIconProps { |
| 13 | name: string; |
| 14 | isNew: boolean; |
| 15 | theme: ThemeType; |
| 16 | justCopied: string | null; |
| 17 | onSelect: (type: string, text: string) => any; |
| 18 | } |
| 19 | |
| 20 | const CopyableIcon: React.FC<CopyableIconProps> = ({ |
| 21 | name, |
| 22 | justCopied, |
| 23 | onSelect, |
| 24 | theme, |
| 25 | }) => { |
| 26 | const className = classNames({ |
| 27 | copied: justCopied === name, |
| 28 | [theme]: !!theme, |
| 29 | |
| 30 | }); |
| 31 | return ( |
| 32 | <li className={className} |
| 33 | onClick={() => { |
| 34 | if (onSelect) { |
| 35 | onSelect(theme, name); |
| 36 | } |
| 37 | }}> |
| 38 | <Tooltip title={name}> |
| 39 | {React.createElement(allIcons[name], { className: styles.anticon })} |
| 40 | </Tooltip> |
| 41 | {/* <span className={styles.anticonClass}> |
| 42 | <Badge dot={isNew}>{name}</Badge> |
| 43 | </span> */} |
| 44 | </li> |
| 45 | ); |
| 46 | }; |
| 47 | |
| 48 | export default CopyableIcon; |