import * as React from 'react';
import { If } from 'react-if';
import { Button, ButtonGroup } from 'react-bootstrap';
import { AppContext, DefaultTooltip } from 'cbioportal-frontend-commons';
import { ICopyDownloadInputsProps } from './ICopyDownloadControls';
export interface ICopyDownloadButtonsProps extends ICopyDownloadInputsProps {
copyButtonRef?: (el: HTMLButtonElement | null) => void;
}
export class CopyDownloadButtons extends React.Component<
ICopyDownloadButtonsProps,
{}
> {
public static defaultProps = {
className: '',
copyLabel: '',
downloadLabel: '',
showCopy: true,
showDownload: true,
showCopyMessage: false,
};
get baseTooltipProps() {
return {
placement: 'top',
mouseLeaveDelay: 0,
mouseEnterDelay: 0.5,
};
}
copyButton() {
const button = (
);
// We need two separate tooltips to properly show/hide "Copied" text, and switch between "Copy" and "Copied".
// (Also, we need to manually set the visibility due to async rendering issues after clicking the button)
return (
Copied!}
visible={this.props.showCopyMessage}
{...this.baseTooltipProps}
overlayClassName={this.props.className}
>
Copy}
visible={this.props.showCopyMessage ? false : undefined}
{...this.baseTooltipProps}
overlayClassName={this.props.className}
>
{button}
);
}
downloadButton() {
return (
Download TSV}
{...this.baseTooltipProps}
overlayClassName={this.props.className}
>
);
}
public render() {
return (
{this.copyButton()}
{this.downloadButton()}
);
}
}
CopyDownloadButtons.contextType = AppContext;