1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { connect, DispatchProp } from "react-redux";
7 import { StyleRulesCallback, Tooltip, WithStyles, withStyles } from "@material-ui/core";
8 import { ArvadosTheme } from 'common/custom-theme';
9 import CopyToClipboard from 'react-copy-to-clipboard';
10 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
11 import { CopyIcon } from 'components/icon/icon';
13 type CssRules = 'copyIcon';
15 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
17 marginLeft: theme.spacing.unit,
18 color: theme.palette.grey["500"],
23 verticalAlign: 'middle',
28 interface CopyToClipboardDataProps {
29 children?: React.ReactNode;
33 type CopyToClipboardProps = CopyToClipboardDataProps & WithStyles<CssRules> & DispatchProp;
35 export const CopyToClipboardSnackbar = connect()(withStyles(styles)(
36 class CopyToClipboardSnackbar extends React.Component<CopyToClipboardProps> {
38 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
41 kind: SnackbarKind.SUCCESS
46 const { children, value, classes } = this.props;
48 <Tooltip title="Copy to clipboard">
49 <span className={classes.copyIcon}>
50 <CopyToClipboard text={value} onCopy={this.onCopy}>
51 {children || <CopyIcon />}