TypeScript
import { useState } from "react";
import { useAgentPrompt } from "./agentPrompt";
export default function CopyForAgent() {
const [copied, setCopied] = useState(false);
const PROMPT = useAgentPrompt();
const onCopy = async () => {
try {
await navigator.clipboard.writeText(PROMPT);
} catch {
const ta = document.createElement("textarea");
ta.value = PROMPT;
ta.style.position = "fixed";
ta.style.opacity = "0";
document.body.appendChild(ta);
ta.select();
try {
document.execCommand("copy");
} finally {
document.body.removeChild(ta);
}
}
setCopied(true);
window.setTimeout(() => setCopied(false), 1600);
};
return (
<div className="alc-copy-agent" data-nosnippet="">
<code className="alc-copy-agent__text" tabIndex={0} aria-label="Prompt for your coding agent">
{PROMPT}
</code>
<button
type="button"
onClick={onCopy}
className="alc-copy-agent__btn"
aria-label={copied ? "Copied to clipboard" : "Copy prompt to clipboard"}
title={copied ? "Copied" : "Copy prompt"}
>
{copied ? <CheckIcon /> : <CopyIcon />}
</button>
</div>
);
}
function CopyIcon() {
return (
<svg
aria-hidden
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<rect x="9" y="9" width="13" height="13" rx="2" />
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
</svg>
);
}
function CheckIcon() {
return (
<svg
aria-hidden
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2.25"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M20 6 9 17l-5-5" />
</svg>
);
}