openreplay/frontend/app/components/hocs/withCopy.tsx
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

30 lines
824 B
TypeScript

import React from 'react';
import copy from 'copy-to-clipboard';
import { Tooltip } from 'UI';
const withCopy = (WrappedComponent: React.ComponentType) => {
function ComponentWithCopy(props: any) {
const [copied, setCopied] = React.useState(false);
const { value, tooltip } = props;
const copyToClipboard = (text: string) => {
copy(text);
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 1000);
};
return (
<div
onClick={() => copyToClipboard(value)}
className="w-fit cursor-pointer"
>
<Tooltip title={copied ? tooltip : 'Click to copy'} delay={0}>
<WrappedComponent {...props} copyToClipboard={copyToClipboard} />
</Tooltip>
</div>
);
}
return ComponentWithCopy;
};
export default withCopy;