Skip to content

Commit c8a9896

Browse files
committed
feat: add simple CopyButton
1 parent 3c618cf commit c8a9896

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/components/CopyToClipboard.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
"use client"
22

3+
import { BsCopy } from "react-icons/bs"
4+
import { FaRegCheckCircle } from "react-icons/fa"
5+
36
import { cn } from "@/lib/utils/cn"
47

8+
import { Button, type ButtonProps } from "./ui/buttons/Button"
9+
510
import { useClipboard } from "@/hooks/useClipboard"
611

712
export type CopyToClipboardProps = {
@@ -27,4 +32,17 @@ const CopyToClipboard = ({
2732
)
2833
}
2934

35+
type CopyButtonProps = ButtonProps & {
36+
message: string
37+
}
38+
39+
export const CopyButton = ({ message, ...props }: CopyButtonProps) => {
40+
const { onCopy, hasCopied } = useClipboard({ timeout: 1500 })
41+
return (
42+
<Button variant="ghost" onClick={() => onCopy(message)} {...props}>
43+
{hasCopied ? <FaRegCheckCircle /> : <BsCopy />}
44+
</Button>
45+
)
46+
}
47+
3048
export default CopyToClipboard

0 commit comments

Comments
 (0)