mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-24 10:44:27 +08:00

* chore: added jsx-runtime plugin in eslint tsconfig Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: updated react imports Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: renamed redux dispatch Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * fix: build is fixed --------- Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> Co-authored-by: Palash Gupta <palashgdev@gmail.com>
42 lines
969 B
TypeScript
42 lines
969 B
TypeScript
import { Popover } from 'antd';
|
|
import { useNotifications } from 'hooks/useNotifications';
|
|
import { ReactNode, useCallback, useEffect } from 'react';
|
|
import { useCopyToClipboard } from 'react-use';
|
|
|
|
function CopyClipboardHOC({
|
|
textToCopy,
|
|
children,
|
|
}: CopyClipboardHOCProps): JSX.Element {
|
|
const [value, setCopy] = useCopyToClipboard();
|
|
const { notifications } = useNotifications();
|
|
useEffect(() => {
|
|
if (value.value) {
|
|
notifications.success({
|
|
message: 'Copied to clipboard',
|
|
});
|
|
}
|
|
}, [value, notifications]);
|
|
|
|
const onClick = useCallback((): void => {
|
|
setCopy(textToCopy);
|
|
}, [setCopy, textToCopy]);
|
|
|
|
return (
|
|
<span onClick={onClick} role="presentation" tabIndex={-1}>
|
|
<Popover
|
|
placement="top"
|
|
content={<span style={{ fontSize: '0.9rem' }}>Copy to clipboard</span>}
|
|
>
|
|
{children}
|
|
</Popover>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
interface CopyClipboardHOCProps {
|
|
textToCopy: string;
|
|
children: ReactNode;
|
|
}
|
|
|
|
export default CopyClipboardHOC;
|