2020-10-20 08:44:32 -04:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-12-02 05:03:03 -05:00
|
|
|
import { Dropdown, OverlayTrigger, Tooltip } from 'react-bootstrap'
|
2020-11-26 04:58:56 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2020-12-02 05:03:03 -05:00
|
|
|
import PreviewDownloadFileList from './preview-download-file-list'
|
2020-10-20 08:44:32 -04:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
|
2020-11-09 09:52:22 -05:00
|
|
|
function PreviewDownloadButton({
|
|
|
|
isCompiling,
|
|
|
|
outputFiles,
|
|
|
|
pdfDownloadUrl,
|
|
|
|
showText
|
|
|
|
}) {
|
2020-10-20 08:44:32 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2020-11-09 09:52:22 -05:00
|
|
|
let textStyle = {}
|
|
|
|
if (!showText) {
|
|
|
|
textStyle = {
|
|
|
|
position: 'absolute',
|
|
|
|
right: '-100vw'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 06:24:21 -05:00
|
|
|
const pdfDownloadDisabled = isCompiling || !pdfDownloadUrl
|
2020-11-09 09:52:22 -05:00
|
|
|
const buttonElement = (
|
|
|
|
<a
|
|
|
|
className="btn btn-xs btn-info"
|
2021-01-12 06:24:21 -05:00
|
|
|
disabled={pdfDownloadDisabled}
|
2020-11-09 09:52:22 -05:00
|
|
|
download
|
|
|
|
href={pdfDownloadUrl || '#'}
|
2021-01-12 06:24:21 -05:00
|
|
|
style={{ pointerEvents: 'auto' }}
|
2020-11-09 09:52:22 -05:00
|
|
|
>
|
|
|
|
<Icon type="download" modifier="fw" />
|
|
|
|
<span className="toolbar-text" style={textStyle}>
|
|
|
|
{t('download_pdf')}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
|
2021-01-12 06:24:21 -05:00
|
|
|
const hideTooltip = showText && pdfDownloadUrl
|
|
|
|
|
2020-10-20 08:44:32 -04:00
|
|
|
return (
|
2020-11-09 09:52:22 -05:00
|
|
|
<Dropdown
|
|
|
|
id="download-dropdown"
|
|
|
|
className="toolbar-item"
|
|
|
|
disabled={isCompiling}
|
|
|
|
>
|
2021-01-12 06:24:21 -05:00
|
|
|
{hideTooltip ? (
|
2020-11-09 09:52:22 -05:00
|
|
|
buttonElement
|
|
|
|
) : (
|
|
|
|
<OverlayTrigger
|
|
|
|
placement="bottom"
|
|
|
|
overlay={
|
2021-01-12 06:24:21 -05:00
|
|
|
<Tooltip id="tooltip-download-pdf">
|
|
|
|
{pdfDownloadDisabled
|
|
|
|
? t('please_compile_pdf_before_download')
|
|
|
|
: t('download_pdf')}
|
|
|
|
</Tooltip>
|
2020-11-09 09:52:22 -05:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{buttonElement}
|
|
|
|
</OverlayTrigger>
|
|
|
|
)}
|
2020-10-20 08:44:32 -04:00
|
|
|
<Dropdown.Toggle
|
|
|
|
className="btn btn-xs btn-info dropdown-toggle"
|
|
|
|
aria-label={t('toggle_output_files_list')}
|
2020-11-12 09:09:48 -05:00
|
|
|
bsStyle="info"
|
2020-10-20 08:44:32 -04:00
|
|
|
/>
|
|
|
|
<Dropdown.Menu id="download-dropdown-list">
|
2020-12-02 05:03:03 -05:00
|
|
|
<PreviewDownloadFileList fileList={outputFiles} />
|
2020-10-20 08:44:32 -04:00
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewDownloadButton.propTypes = {
|
|
|
|
isCompiling: PropTypes.bool.isRequired,
|
|
|
|
outputFiles: PropTypes.array,
|
2020-11-09 09:52:22 -05:00
|
|
|
pdfDownloadUrl: PropTypes.string,
|
|
|
|
showText: PropTypes.bool.isRequired
|
2020-10-20 08:44:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewDownloadButton
|