[dyad] Added preview image and copy buttons - wrote 4 file(s)

This commit is contained in:
[dyad]
2026-01-20 12:09:52 +01:00
parent 9c1c4e1581
commit 4163372a17
4 changed files with 100 additions and 19 deletions

View File

@@ -0,0 +1,41 @@
"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Check, Copy } from "lucide-react";
import { toast } from "sonner";
interface CopyButtonProps {
textToCopy: string;
}
export function CopyButton({ textToCopy }: CopyButtonProps) {
const [isCopied, setIsCopied] = useState(false);
const handleCopy = () => {
if (!textToCopy || textToCopy === "Not found") return;
navigator.clipboard.writeText(textToCopy).then(() => {
setIsCopied(true);
toast.success("Copied to clipboard!");
setTimeout(() => {
setIsCopied(false);
}, 2000);
});
};
return (
<Button
variant="ghost"
size="icon"
onClick={handleCopy}
className="h-8 w-8"
>
{isCopied ? (
<Check className="h-4 w-4 text-green-500" />
) : (
<Copy className="h-4 w-4" />
)}
<span className="sr-only">Copy</span>
</Button>
);
}