mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-16 18:52:12 +03:00
c649f85a1c
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
49 lines
1005 B
TypeScript
49 lines
1005 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
import Icon from "@/lib/components/ui/Icon/Icon";
|
|
import { IconSize } from "@/lib/types/Icons";
|
|
|
|
type CopyButtonProps = {
|
|
handleCopy: () => void;
|
|
size: IconSize;
|
|
};
|
|
|
|
export const CopyButton = ({
|
|
handleCopy,
|
|
size,
|
|
}: CopyButtonProps): JSX.Element => {
|
|
const [isCopied, setIsCopied] = useState(false);
|
|
|
|
const handleClick = () => {
|
|
handleCopy();
|
|
setIsCopied(true);
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (isCopied) {
|
|
const timer = setTimeout(() => {
|
|
setIsCopied(false);
|
|
}, 2000);
|
|
|
|
return () => {
|
|
clearTimeout(timer);
|
|
};
|
|
}
|
|
}, [isCopied]);
|
|
|
|
return (
|
|
<button
|
|
className="text-gray-500 hover:text-gray-700 transition"
|
|
onClick={handleClick}
|
|
title={isCopied ? "Copied!" : "Copy to clipboard"}
|
|
>
|
|
<Icon
|
|
name={isCopied ? "checkCircle" : "copy"}
|
|
color={isCopied ? "primary" : "black"}
|
|
size={size}
|
|
handleHover={true}
|
|
/>
|
|
</button>
|
|
);
|
|
};
|