openreplay/frontend/app/components/ui/CopyButton/CopyButton.js
2025-01-14 12:48:11 +01:00

29 lines
654 B
JavaScript

import React from 'react'
import { useState } from 'react';
import copy from 'copy-to-clipboard';
import { Button } from 'antd';
function CopyButton({ content, variant="text-primary", className = '', btnText = 'copy' }) {
const [copied, setCopied] = useState(false)
const copyHandler = () => {
setCopied(true);
copy(content);
setTimeout(() => {
setCopied(false);
}, 1000);
};
return (
<Button
type='text'
onClick={ copyHandler }
size='small'
className='capitalize mt-2 font-medium text-neutral-400'
>
{ copied ? 'copied' : btnText }
</Button>
)
}
export default CopyButton