forked from TaxyAI/browser-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopyButton.tsx
37 lines (35 loc) · 952 Bytes
/
CopyButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react';
import { CopyIcon } from '@chakra-ui/icons';
import { useToast } from '@chakra-ui/react';
import { callRPC } from '../helpers/pageRPC';
export default function CopyButton(props: { text: string }) {
const toast = useToast();
return (
<CopyIcon
cursor="pointer"
color="gray.500"
_hover={{ color: 'gray.700' }}
onClick={async (event) => {
try {
event.preventDefault();
await callRPC('copyToClipboard', [props.text]);
toast({
title: 'Copied to clipboard',
status: 'success',
duration: 3000,
isClosable: true,
});
} catch (e) {
console.error(e);
toast({
title: 'Error',
description: 'Could not copy to clipboard',
status: 'error',
duration: 5000,
isClosable: true,
});
}
}}
/>
);
}