mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-09 22:04:47 +00:00
fix #180: Added copy button
Used ref to point to parent div and got inner text of the div and write it to the clipboard.
This commit is contained in:
parent
2d6fb98130
commit
8530226edb
2 changed files with 361 additions and 245 deletions
33
surfsense_web/components/copy-button.tsx
Normal file
33
surfsense_web/components/copy-button.tsx
Normal file
|
@ -0,0 +1,33 @@
|
|||
"use client";
|
||||
import { useState } from "react";
|
||||
import type { RefObject } from "react";
|
||||
import { Button } from "./ui/button";
|
||||
import { Copy, CopyCheck } from "lucide-react";
|
||||
|
||||
export default function CopyButton({
|
||||
ref,
|
||||
}: {
|
||||
ref: RefObject<HTMLDivElement | null>;
|
||||
}) {
|
||||
const [copy, setCopy] = useState(false);
|
||||
|
||||
const handleClick = () => {
|
||||
if (ref.current) {
|
||||
const text = ref.current.innerText;
|
||||
navigator.clipboard.writeText(text);
|
||||
|
||||
setCopy(true);
|
||||
setTimeout(() => {
|
||||
setCopy(false);
|
||||
}, 500);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full flex justify-end">
|
||||
<Button variant="ghost" onClick={handleClick}>
|
||||
{copy ? <CopyCheck /> : <Copy />}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue