forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy-button.tsx
More file actions
41 lines (37 loc) · 1.13 KB
/
Copy pathcopy-button.tsx
File metadata and controls
41 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// <CopyButton> — minimal clipboard button used by <Snippet>.
// Lives on the client so it can access navigator.clipboard.
"use client";
import React, { useState } from "react";
export function CopyButton({ text }: { text: string }) {
const [copied, setCopied] = useState(false);
return (
<button
type="button"
onClick={async (e) => {
e.preventDefault();
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 1500);
} catch {
// noop — clipboard blocked by browser
}
}}
aria-label={copied ? "Copied" : "Copy code"}
style={{
padding: "2px 8px",
fontSize: "10px",
lineHeight: 1.2,
border: "1px solid var(--border)",
borderRadius: "4px",
background: copied ? "var(--accent-light)" : "var(--bg-surface)",
color: copied ? "var(--accent)" : "var(--text-muted)",
cursor: "pointer",
fontFamily: "inherit",
transition: "background 120ms, color 120ms",
}}
>
{copied ? "Copied" : "Copy"}
</button>
);
}