cg / hackerproducts
63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.
Quick jump: page.tsxpage.tsxglobals.cssschema.sqlpackage.json
root / src / components / CopyCodeButton.tsx
src/components/CopyCodeButton.tsx · 24 lines · 511 B← back to folder
| 1 | "use client"; |
| 2 | |
| 3 | import { useState } from "react"; |
| 4 | |
| 5 | export function CopyCodeButton({ content }: { content: string }) { |
| 6 | const [copied, setCopied] = useState(false); |
| 7 | |
| 8 | async function copy() { |
| 9 | try { |
| 10 | await navigator.clipboard.writeText(content); |
| 11 | setCopied(true); |
| 12 | setTimeout(() => setCopied(false), 1800); |
| 13 | } catch { |
| 14 | // ignore |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | return ( |
| 19 | <button type="button" className="link-button" onClick={() => void copy()}> |
| 20 | {copied ? "copied" : "copy"} |
| 21 | </button> |
| 22 | ); |
| 23 | } |
| 24 |