Skip to content

Commit 276854a

Browse files
committed
🚀 feat: insert copy option
1 parent 8351fd5 commit 276854a

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/components/features/ToolCard.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { motion } from 'framer-motion';
2-
import { Terminal } from 'lucide-react';
2+
import { Terminal, Clipboard } from 'lucide-react';
3+
import { useState } from 'react';
34

45
interface ToolCardProps {
56
name: string;
@@ -9,6 +10,17 @@ interface ToolCardProps {
910
}
1011

1112
export function ToolCard({ name, description, category, command }: ToolCardProps) {
13+
const [copied, setCopied] = useState(false);
14+
15+
const handleCopyClick = () => {
16+
navigator.clipboard.writeText(command)
17+
.then(() => {
18+
setCopied(true);
19+
setTimeout(() => setCopied(false), 2000); // Reset copied status after 2 seconds
20+
})
21+
.catch((error) => console.error('Failed to copy: ', error));
22+
};
23+
1224
return (
1325
<motion.div
1426
initial={{ opacity: 0, y: 20 }}
@@ -28,7 +40,20 @@ export function ToolCard({ name, description, category, command }: ToolCardProps
2840

2941
<div className="flex items-center justify-between mt-4">
3042
<span className="text-sm font-medium text-cornflower-blue">{category}</span>
31-
<code className="text-sm bg-gray-100 px-3 py-1 rounded text-gray-800">{command}</code>
43+
<div className="flex items-center gap-2">
44+
<code className="text-sm bg-gray-100 px-3 py-1 rounded text-gray-800">{command}</code>
45+
<button
46+
onClick={handleCopyClick}
47+
className="p-2 bg-cornflower-blue/20 rounded-full hover:bg-cornflower-blue/30 transition-all"
48+
aria-label="Copy command"
49+
>
50+
{copied ? (
51+
<span className="text-sm text-cornflower-blue">Copied!</span>
52+
) : (
53+
<Clipboard className="h-5 w-5 text-cornflower-blue" />
54+
)}
55+
</button>
56+
</div>
3257
</div>
3358
</motion.div>
3459
);

0 commit comments

Comments
 (0)