-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcopy-page-markdown.tsx
More file actions
42 lines (37 loc) · 1.17 KB
/
copy-page-markdown.tsx
File metadata and controls
42 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use client';
import { useState } from 'react';
import { Copy, Check } from 'lucide-react';
interface CopyPageMarkdownProps {
content: string;
}
export function CopyPageMarkdown({ content }: CopyPageMarkdownProps) {
const [copied, setCopied] = useState(false);
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(content);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (error) {
console.error('Failed to copy:', error);
}
};
return (
<button
onClick={copyToClipboard}
className="inline-flex items-center gap-2 rounded-md border border-input bg-background px-3 py-2 text-sm font-medium ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
title="Copy entire page as Markdown"
>
{copied ? (
<>
<Check className="h-4 w-4" />
<span>Copied!</span>
</>
) : (
<>
<Copy className="h-4 w-4" />
<span>Copy as Markdown</span>
</>
)}
</button>
);
}