-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecutionCopyOutputButton.tsx
42 lines (37 loc) · 1.26 KB
/
ExecutionCopyOutputButton.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
38
39
40
41
42
import React from 'react';
import { Button, ButtonGroup, Text } from '@adobe/react-spectrum';
import { ToastQueue } from '@react-spectrum/toast';
import Copy from '@spectrum-icons/workflow/Copy';
const toastTimeout = 3000;
interface ExecutionCopyOutputButtonProps {
output: string;
}
const ExecutionCopyOutputButton: React.FC<ExecutionCopyOutputButtonProps> = ({ output }) => {
const onCopyExecutionOutput = () => {
if (output) {
navigator.clipboard
.writeText(output)
.then(() => {
ToastQueue.info('Execution output copied to clipboard!', {
timeout: toastTimeout,
});
})
.catch(() => {
ToastQueue.negative('Failed to copy execution output!', {
timeout: toastTimeout,
});
});
} else {
ToastQueue.negative('No execution output to copy!', {
timeout: toastTimeout,
});
}
};
return (
<Button variant="secondary" isDisabled={!output} onPress={onCopyExecutionOutput}>
<Copy />
<Text>Copy</Text>
</Button>
);
};
export default ExecutionCopyOutputButton;