mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
1760d93fc4
* Upgrade react and react-dom * Fix test * Ensure that the "history:toggle" event is broadcast when switching in or out of history view * Add ControlledDropdown * Remove DropdownButton stories GitOrigin-RevId: 3810f6986bb60e59af31f960f431c31be16554f5
84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
import React from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import { Dropdown, OverlayTrigger, Tooltip } from 'react-bootstrap'
|
|
import { useTranslation } from 'react-i18next'
|
|
import PreviewDownloadFileList from './preview-download-file-list'
|
|
import Icon from '../../../shared/components/icon'
|
|
import ControlledDropdown from '../../../shared/components/controlled-dropdown'
|
|
|
|
function PreviewDownloadButton({
|
|
isCompiling,
|
|
outputFiles,
|
|
pdfDownloadUrl,
|
|
showText,
|
|
}) {
|
|
const { t } = useTranslation()
|
|
|
|
let textStyle = {}
|
|
if (!showText) {
|
|
textStyle = {
|
|
position: 'absolute',
|
|
right: '-100vw',
|
|
}
|
|
}
|
|
|
|
const pdfDownloadDisabled = isCompiling || !pdfDownloadUrl
|
|
const buttonElement = (
|
|
<a
|
|
className="btn btn-xs btn-info"
|
|
disabled={pdfDownloadDisabled}
|
|
download
|
|
href={pdfDownloadUrl || '#'}
|
|
style={{ pointerEvents: 'auto' }}
|
|
>
|
|
<Icon type="download" modifier="fw" />
|
|
<span className="toolbar-text" style={textStyle}>
|
|
{t('download_pdf')}
|
|
</span>
|
|
</a>
|
|
)
|
|
|
|
const hideTooltip = showText && pdfDownloadUrl
|
|
|
|
return (
|
|
<ControlledDropdown
|
|
id="download-dropdown"
|
|
className="toolbar-item"
|
|
disabled={isCompiling}
|
|
>
|
|
{hideTooltip ? (
|
|
buttonElement
|
|
) : (
|
|
<OverlayTrigger
|
|
placement="bottom"
|
|
overlay={
|
|
<Tooltip id="tooltip-download-pdf">
|
|
{pdfDownloadDisabled
|
|
? t('please_compile_pdf_before_download')
|
|
: t('download_pdf')}
|
|
</Tooltip>
|
|
}
|
|
>
|
|
{buttonElement}
|
|
</OverlayTrigger>
|
|
)}
|
|
<Dropdown.Toggle
|
|
className="btn btn-xs btn-info dropdown-toggle"
|
|
aria-label={t('toggle_output_files_list')}
|
|
bsStyle="info"
|
|
/>
|
|
<Dropdown.Menu id="download-dropdown-list">
|
|
<PreviewDownloadFileList fileList={outputFiles} />
|
|
</Dropdown.Menu>
|
|
</ControlledDropdown>
|
|
)
|
|
}
|
|
|
|
PreviewDownloadButton.propTypes = {
|
|
isCompiling: PropTypes.bool.isRequired,
|
|
outputFiles: PropTypes.array,
|
|
pdfDownloadUrl: PropTypes.string,
|
|
showText: PropTypes.bool.isRequired,
|
|
}
|
|
|
|
export default PreviewDownloadButton
|