UNPKG

knk

Version:

react components based on react

31 lines 816 B
import React from 'react'; import PropTypes from 'prop-types'; import { Button, Modal } from 'antd'; var CopyText = function CopyText(props) { var text = props.text, cb = props.cb; var handleCopy = function handleCopy() { var input = document.createElement('textarea'); input.value = text; document.body.appendChild(input); input.select(); document.execCommand('copy'); document.body.removeChild(input); if (cb) { cb(); return; } Modal.success({ title: '已复制', content: '文本已成功复制到剪贴板!' }); }; return /*#__PURE__*/React.createElement(Button, { onClick: handleCopy }, "\u590D\u5236\u6587\u672C"); }; CopyText.propTypes = { text: PropTypes.string.isRequired, cb: PropTypes.func }; export default CopyText;