mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 17:19:11 +08:00
14a1e6bd51
* feat: tsconfig enable strict * feat: add no-explicit-any * feat: strict * feat: as THEME * feat: 优化 keys 类型写法 * feat: demo remove any * feat: as number * feat: this any * feat: add eslint * feat: cascader * feat: props any * feat: remove any * feat: remove any * feat: any 提示错误 * feat: remove any * feat: add eslint * feat: 允许 T = any 存在 * feat: color funciton * feat: 恢复 lint * feat: merge master * feat: as ReactElement * feat: type
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import * as React from 'react';
|
|
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
|
|
import CheckOutlined from '@ant-design/icons/CheckOutlined';
|
|
import CopyOutlined from '@ant-design/icons/CopyOutlined';
|
|
import classNames from 'classnames';
|
|
|
|
import type { CopyConfig } from '.';
|
|
import TransButton from '../../_util/transButton';
|
|
import { type Locale } from '../../locale';
|
|
import Tooltip from '../../tooltip';
|
|
import { getNode, toList } from './util';
|
|
|
|
export interface CopyBtnProps extends Omit<CopyConfig, 'onCopy'> {
|
|
prefixCls: string;
|
|
copied: boolean;
|
|
locale: Locale['Text'];
|
|
onCopy: React.MouseEventHandler<HTMLDivElement>;
|
|
iconOnly: boolean;
|
|
loading: boolean;
|
|
}
|
|
|
|
export default function CopyBtn(props: CopyBtnProps) {
|
|
const { prefixCls, copied, locale = {}, onCopy, iconOnly, tooltips, icon, loading } = props;
|
|
|
|
const tooltipNodes = toList(tooltips);
|
|
const iconNodes = toList(icon);
|
|
|
|
const { copied: copiedText, copy: copyText } = locale;
|
|
|
|
const copyTitle = copied
|
|
? getNode(tooltipNodes[1], copiedText)
|
|
: getNode(tooltipNodes[0], copyText);
|
|
const systemStr = copied ? copiedText : copyText;
|
|
const ariaLabel = typeof copyTitle === 'string' ? copyTitle : systemStr;
|
|
|
|
return (
|
|
<Tooltip key="copy" title={copyTitle}>
|
|
<TransButton
|
|
className={classNames(`${prefixCls}-copy`, {
|
|
[`${prefixCls}-copy-success`]: copied,
|
|
[`${prefixCls}-copy-icon-only`]: iconOnly,
|
|
})}
|
|
onClick={onCopy as any}
|
|
aria-label={ariaLabel}
|
|
>
|
|
{copied
|
|
? getNode(iconNodes[1], <CheckOutlined />, true)
|
|
: getNode(iconNodes[0], loading ? <LoadingOutlined /> : <CopyOutlined />, true)}
|
|
</TransButton>
|
|
</Tooltip>
|
|
);
|
|
}
|