UNPKG

antd

Version:

An enterprise-class UI design language and React components implementation

42 lines (41 loc) 1.56 kB
"use client"; import * as React from 'react'; import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined"; import CheckOutlined from "@ant-design/icons/es/icons/CheckOutlined"; import CopyOutlined from "@ant-design/icons/es/icons/CopyOutlined"; import classNames from 'classnames'; import TransButton from '../../_util/transButton'; import Tooltip from '../../tooltip'; import { getNode, toList } from './util'; export default function CopyBtn(props) { 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 /*#__PURE__*/React.createElement(Tooltip, { key: "copy", title: copyTitle }, /*#__PURE__*/React.createElement(TransButton, { className: classNames(`${prefixCls}-copy`, { [`${prefixCls}-copy-success`]: copied, [`${prefixCls}-copy-icon-only`]: iconOnly }), onClick: onCopy, "aria-label": ariaLabel }, copied ? getNode(iconNodes[1], /*#__PURE__*/React.createElement(CheckOutlined, null), true) : getNode(iconNodes[0], loading ? /*#__PURE__*/React.createElement(LoadingOutlined, null) : /*#__PURE__*/React.createElement(CopyOutlined, null), true))); }