UNPKG

ds-markdown

Version:

> 🚀 React Markdown 打字动画组件,提供现代聊天界面效果

24 lines 1.05 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { CopyIcon } from '../Icon/index.js'; import { useConfig } from '../../context/ConfigProvider/index.js'; import SuccessButton from '../ui/SuccessButton/index.js'; const CopyButton = ({ codeContent, style, className }) => { const { locale } = useConfig(); const handleCopy = async () => { try { await navigator.clipboard.writeText(codeContent || ''); return true; } catch (err) { // 降级方案:使用传统方法 const textArea = document.createElement('textarea'); textArea.value = codeContent || ''; textArea.select(); document.execCommand('copy'); return true; } }; return (_jsx(SuccessButton, { onClick: handleCopy, icon: _jsx(CopyIcon, { size: 24 }), executeText: locale.codeBlock.copied || 'copied', style: style, className: className, children: locale.codeBlock.copy || 'copy' })); }; export default CopyButton; //# sourceMappingURL=index.js.map