openreplay/frontend/app/components/shared/CopyText/CopyText.tsx
Andrey Babushkin eab2d3a2cf
Fix localisation (#3123)
* fix localised errors

* fix locales
2025-03-10 15:51:21 +01:00

33 lines
789 B
TypeScript

import React, { useState } from 'react';
import { Tooltip } from 'antd';
import copy from 'copy-to-clipboard';
import { useTranslation } from 'react-i18next';
interface Props {
label?: string;
afterLabel?: string;
children: any;
content: string;
}
function CopyText(props: Props) {
const { t } = useTranslation();
const {
children,
label = t('Click to copy'),
afterLabel = t('Copied'),
content = '',
} = props;
const [isCopied, setIsCopied] = useState(false);
const onClick = () => {
copy(content);
setIsCopied(true);
setTimeout(() => setIsCopied(false), 5000);
};
return (
<Tooltip title={isCopied ? afterLabel : label} placement="top">
<span onClick={onClick}>{children}</span>
</Tooltip>
);
}
export default CopyText;