// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { clsx } from "clsx"; import { useEffect, useRef, useState } from "react"; import { Button } from "./button"; import "./copybutton.less"; type CopyButtonProps = { title: string; className?: string; onClick: (e: React.MouseEvent) => void; }; const CopyButton = ({ title, className, onClick }: CopyButtonProps) => { const [isCopied, setIsCopied] = useState(false); const timeoutRef = useRef(null); const handleOnClick = (e: React.MouseEvent) => { if (isCopied) { return; } setIsCopied(true); if (timeoutRef.current) { clearTimeout(timeoutRef.current); } timeoutRef.current = setTimeout(() => { setIsCopied(false); timeoutRef.current = null; }, 2000); if (onClick) { onClick(e); } }; useEffect(() => { return () => { if (timeoutRef.current) { clearTimeout(timeoutRef.current); } }; }, []); return ( ); }; export { CopyButton };