Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.3 KB
Raw Blame
import { useEffect, useState } from 'react';
import { useCopyToClipboard } from 'react-use';
import { Color } from '@signozhq/design-tokens';
import { Button } from 'antd';
import { useIsDarkMode } from 'hooks/useDarkMode';
import { CircleCheck, Link2 } from '@signozhq/icons';

import './CopyToClipboard.styles.scss';

function CopyToClipboard({ textToCopy }: { textToCopy: string }): JSX.Element {
	const [state, copyToClipboard] = useCopyToClipboard();
	const [success, setSuccess] = useState(false);
	const isDarkMode = useIsDarkMode();

	useEffect(() => {
		let timer: string | number | NodeJS.Timeout | undefined;
		if (state.value) {
			setSuccess(true);
			timer = setTimeout(() => setSuccess(false), 1000);
		}

		return (): void => clearTimeout(timer);
	}, [state]);

	if (success) {
		return (
			<Button
				type="text"
				icon={<CircleCheck size={16} color={Color.BG_FOREST_400} />}
				className="copy-to-clipboard copy-to-clipboard--success"
			>
				Copied
			</Button>
		);
	}

	return (
		<Button
			type="text"
			icon={
				<Link2
					size={16}
					color={isDarkMode ? Color.BG_VANILLA_400 : Color.TEXT_INK_400}
				/>
			}
			onClick={(): void => copyToClipboard(textToCopy)}
			className="copy-to-clipboard"
		>
			Copy link
		</Button>
	);
}

export default CopyToClipboard;