Skip to content

Commit 4a0dc2b

Browse files
committed
simplify copy text
1 parent b64f113 commit 4a0dc2b

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/app/index.jsx

+9-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Suspense, lazy, useState } from 'react'
1+
import { Suspense, lazy } from 'react'
22

33
import comma from '../assets/comma.svg'
44
import qdlPorts from '../assets/qdl-ports.svg'
@@ -14,29 +14,14 @@ const PRODUCT_ID = '9008'
1414
const DETACH_SCRIPT = 'for d in /sys/bus/usb/drivers/qcserial/*-*; do [ -e "$d" ] && echo -n "$(basename $d)" | sudo tee /sys/bus/usb/drivers/qcserial/unbind > /dev/null; done';
1515

1616
function CopyText({ children: text }) {
17-
const [copied, setCopied] = useState(false)
18-
const handleCopy = () => {
19-
setCopied(true)
20-
setTimeout(() => {
21-
setCopied(false)
22-
}, 1000)
23-
}
24-
25-
return <div className="relative w-full">
26-
<pre className="font-mono text-sm px-4 py-6">
27-
{text}
28-
</pre>
29-
<div className="absolute top-2 right-2">
30-
<button
31-
onClick={() => {
32-
void navigator.clipboard.writeText(text);
33-
handleCopy();
34-
}}
35-
className={`bg-${copied ? 'green' : 'blue'}-500 text-white px-1 py-1 rounded-md ml-2 text-sm`}
36-
>
37-
Copy
38-
</button>
39-
</div>
17+
return <div className="relative text-sm">
18+
<pre className="font-mono pt-12">{text}</pre>
19+
<button
20+
onClick={() => navigator.clipboard.writeText(text)}
21+
className={"absolute top-2 right-2 bg-blue-600 hover:bg-blue-500 active:bg-blue-300 transition-colors text-white p-1 rounded-md"}
22+
>
23+
Copy
24+
</button>
4025
</div>;
4126
}
4227

0 commit comments

Comments
 (0)