Merge branch 'main' into 21720-material-ui-upgrade
[arvados.git] / services / workbench2 / src / views-components / context-menu / actions / copy-to-clipboard-action.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import copy from 'copy-to-clipboard';
7 import { ListItemIcon, ListItemText, ListItem } from "@mui/material";
8 import { Link } from "components/icon/icon";
9
10 interface CopyToClipboardActionProps {
11     href?: any;
12     kind?: string;
13     customText?: string;
14     onClick?: () => void;
15 };
16
17 export const CopyToClipboardAction = (props: CopyToClipboardActionProps) => {
18     const copyToClipboard = () => {
19         if (props.href) {
20             copy(props.href);
21         }
22
23         if (props.onClick) {
24             props.onClick();
25         }
26     };
27
28     return props.href
29          ? <ListItem button onClick={copyToClipboard}>
30              <ListItemIcon>
31                  <Link />
32              </ListItemIcon>
33              <ListItemText>
34                  {props.customText ? props.customText : "Copy link to clipboard"}
35              </ListItemText>
36          </ListItem>
37          : null;
38 };