-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToolCopyButton.jsx
More file actions
53 lines (46 loc) · 1.23 KB
/
Copy pathToolCopyButton.jsx
File metadata and controls
53 lines (46 loc) · 1.23 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
43
44
45
46
47
48
49
50
51
52
53
import React, { useState, useCallback } from 'react';
import { Copy, Check } from 'lucide-react';
import { Button } from '../ui/Button';
import { cn } from '../../utils/cn';
/**
* Standardized copy button component with success feedback
*/
export function ToolCopyButton({
text,
onCopy,
disabled,
variant = 'ghost',
size = 'sm',
className,
}) {
const [copied, setCopied] = useState(false);
const isDisabled = disabled ?? !text;
const handleCopy = useCallback(async () => {
if (isDisabled) return;
try {
if (onCopy) {
await onCopy(text);
} else {
await navigator.clipboard.writeText(text);
}
// Show success feedback
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (error) {
console.error('Failed to copy text:', error);
}
}, [text, onCopy, isDisabled]);
return (
<Button
variant={variant}
size={size}
onClick={handleCopy}
disabled={isDisabled}
className={cn('h-7 gap-1.5 text-[11px] font-bold uppercase tracking-wider', className)}
>
{copied ? <Check className="h-3 w-3" /> : <Copy className="h-3 w-3" />}
{copied ? 'Copied' : 'Copy'}
</Button>
);
}
export default ToolCopyButton;