20 lines
827 B
TypeScript
20 lines
827 B
TypeScript
import { App, Button } from 'antd';
|
|
import { CopyOutlined } from '@ant-design/icons';
|
|
|
|
/** 直接复制表单或预览原文,保留换行和空行,不从页面排版提取文本。 */
|
|
export function CopyTextButton({ getText, label }: {
|
|
getText: () => string | null | undefined;
|
|
label: string;
|
|
}) {
|
|
const { message } = App.useApp();
|
|
return <Button type="text" icon={<CopyOutlined />} aria-label={label} title={label}
|
|
onClick={async () => {
|
|
const text = getText();
|
|
if (!text) { message.info('暂无可复制的内容'); return; }
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
message.success('已复制,换行格式已保留');
|
|
} catch { message.error('复制失败,请选中文本后复制'); }
|
|
}} />;
|
|
}
|