mirror of
https://github.com/hanzoai/o11y-components.git
synced 2026-10-30 14:54:15 +00:00
* refactor(storybook): add design tokens doc & improve menu organization * fix(turbo): generate components using new structure * refactor(sidebar): change from experimental to old components
37 lines
865 B
TypeScript
37 lines
865 B
TypeScript
import { CheckCheck, Copy } from '@signozhq/icons';
|
|
import { useState } from 'react';
|
|
|
|
interface CopyButtonProps {
|
|
text: string;
|
|
className?: string;
|
|
}
|
|
|
|
export function CopyButton({ text, className = '' }: CopyButtonProps) {
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
const handleCopy = async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2000);
|
|
} catch (err) {
|
|
console.error('Failed to copy:', err);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={handleCopy}
|
|
className={`inline-flex items-center justify-center rounded px-2 py-1 text-xs transition-colors hover:bg-l2-background ${className}`}
|
|
title={`Copy ${text}`}
|
|
>
|
|
{copied ? (
|
|
<CheckCheck className="text-l2-foreground" />
|
|
) : (
|
|
<Copy className="text-l2-foreground" />
|
|
)}
|
|
</button>
|
|
);
|
|
}
|