CopyBtn.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use client";
  2. import * as React from 'react';
  3. import CheckOutlined from "@ant-design/icons/es/icons/CheckOutlined";
  4. import CopyOutlined from "@ant-design/icons/es/icons/CopyOutlined";
  5. import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
  6. import classNames from 'classnames';
  7. import Tooltip from '../../tooltip';
  8. import { getNode, toList } from './util';
  9. const CopyBtn = ({
  10. prefixCls,
  11. copied,
  12. locale,
  13. iconOnly,
  14. tooltips,
  15. icon,
  16. tabIndex,
  17. onCopy,
  18. loading: btnLoading
  19. }) => {
  20. const tooltipNodes = toList(tooltips);
  21. const iconNodes = toList(icon);
  22. const {
  23. copied: copiedText,
  24. copy: copyText
  25. } = locale !== null && locale !== void 0 ? locale : {};
  26. const systemStr = copied ? copiedText : copyText;
  27. const copyTitle = getNode(tooltipNodes[copied ? 1 : 0], systemStr);
  28. const ariaLabel = typeof copyTitle === 'string' ? copyTitle : systemStr;
  29. return /*#__PURE__*/React.createElement(Tooltip, {
  30. title: copyTitle
  31. }, /*#__PURE__*/React.createElement("button", {
  32. type: "button",
  33. className: classNames(`${prefixCls}-copy`, {
  34. [`${prefixCls}-copy-success`]: copied,
  35. [`${prefixCls}-copy-icon-only`]: iconOnly
  36. }),
  37. onClick: onCopy,
  38. "aria-label": ariaLabel,
  39. tabIndex: tabIndex
  40. }, copied ? getNode(iconNodes[1], /*#__PURE__*/React.createElement(CheckOutlined, null), true) : getNode(iconNodes[0], btnLoading ? /*#__PURE__*/React.createElement(LoadingOutlined, null) : /*#__PURE__*/React.createElement(CopyOutlined, null), true)));
  41. };
  42. export default CopyBtn;