image.png

    1. import React from 'react';
    2. import PropTypes from 'prop-types';
    3. import { Tooltip, message } from 'antd';
    4. import { CopyToClipboard } from 'react-copy-to-clipboard';
    5. import { CopyOutlined } from '@ant-design/icons';
    6. import classNames from 'classnames';
    7. const style = { fontSize: 14, color: '#999' };
    8. ClipBoard.propTypes = {
    9. value: PropTypes.string.isRequired,
    10. className: PropTypes.string,
    11. };
    12. function ClipBoard({ value, className }) {
    13. function onCopy() {
    14. message.destroy();
    15. message.success('复制成功');
    16. }
    17. const _class = classNames({
    18. [className]: Boolean(className),
    19. });
    20. return (
    21. <CopyToClipboard
    22. text={value}
    23. onCopy={onCopy}>
    24. <Tooltip title='复制'>
    25. <CopyOutlined className={_class} style={style} />
    26. </Tooltip>
    27. </CopyToClipboard>
    28. );
    29. }
    30. export default ClipBoard;