1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { ReactElementLike } from 'prop-types';
7 import copy from 'copy-to-clipboard';
9 interface CopyToClipboardProps {
10 getText: (() => string);
11 children: ReactElementLike;
12 onCopy?(text: string, result: boolean): void;
16 format?: string; // MIME type
20 export default class CopyResultToClipboard extends React.PureComponent<CopyToClipboardProps> {
21 static defaultProps = {
34 const elem = React.Children.only(children);
36 const text = getText();
38 const result = copy(text, options);
44 // Bypass onClick if it was present
45 if (elem && elem.props && typeof elem.props.onClick === 'function') {
46 elem.props.onClick(event);
59 const elem = React.Children.only(children);
61 return React.cloneElement(elem, {...props, onClick: this.onClick});