peppa/apps/web/components/GuideCopy.tsx
2026-11-17 12:46:19 +05:00

27 lines
1.1 KiB
TypeScript

"use client";
import { useState } from "react";
import { Check, Copy } from "lucide-react";
/** PEP-190: a long text for an AI's instructions, in full, with a copy button. */
export function GuideCopy({ value, label, done }: { value: string; label: string; done: string }) {
const [copied, setCopied] = useState(false);
async function copy() {
try {
await navigator.clipboard.writeText(value);
setCopied(true);
setTimeout(() => setCopied(false), 2500);
} catch {
/* no clipboard access: the text is selectable, the person copies it by hand */
}
}
return (
<div className="flex flex-col gap-2">
<button type="button" onClick={() => void copy()} className="inline-flex w-fit items-center gap-1.5 rounded-md border bg-card px-2.5 py-2 text-sm font-medium hover:border-primary/60">
{copied ? <Check className="size-4 text-ok" /> : <Copy className="size-4" />} {copied ? done : label}
</button>
<pre className="m-0 overflow-x-auto whitespace-pre-wrap rounded-md border bg-muted px-3 py-2 text-sm leading-relaxed" data-guide-text>{value}</pre>
</div>
);
}