1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import copy from 'copy-to-clipboard';
8 interface CopyToClipboardProps {
9 getText: (() => string);
11 onCopy?(text: string, result: boolean): void;
15 format?: string; // MIME type
19 export default class CopyResultToClipboard extends React.PureComponent<CopyToClipboardProps> {
20 static defaultProps = {
33 const elem = React.Children.only(children);
35 const text = getText();
37 const result = copy(text, options);
43 // Bypass onClick if it was present
44 if (elem && elem.props && typeof elem.props.onClick === 'function') {
45 elem.props.onClick(event);
58 const elem = React.Children.only(children);
60 return React.cloneElement(elem, {...props, onClick: this.onClick});