2020-10-20 08:44:32 -04:00
|
|
|
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'
|
2021-06-18 05:29:06 -04:00
|
|
|
import ControlledDropdown from '../../../shared/components/controlled-dropdown'
|
2020-10-20 08:44:32 -04:00
|
|
|
|
2020-11-09 09:52:22 -05:00
|
|
|
function PreviewDownloadButton({
|
|
|
|
isCompiling,
|
|
|
|
outputFiles,
|
|
|
|
pdfDownloadUrl,
|
2021-04-27 03:52:58 -04:00
|
|
|
showText,
|
2020-11-09 09:52:22 -05:00
|
|
|
}) {
|
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',
|
2021-04-27 03:52:58 -04:00
|
|
|
right: '-100vw',
|
2020-11-09 09:52:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
>
|
2022-01-19 06:56:57 -05:00
|
|
|
<Icon type="download" fw />
|
2020-11-09 09:52:22 -05:00
|
|
|
<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 (
|
2021-06-18 05:29:06 -04:00
|
|
|
<ControlledDropdown
|
2020-11-09 09:52:22 -05:00
|
|
|
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>
|
2021-06-18 05:29:06 -04:00
|
|
|
</ControlledDropdown>
|
2020-10-20 08:44:32 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PreviewDownloadButton.propTypes = {
|
|
|
|
isCompiling: PropTypes.bool.isRequired,
|
|
|
|
outputFiles: PropTypes.array,
|
2020-11-09 09:52:22 -05:00
|
|
|
pdfDownloadUrl: PropTypes.string,
|
2021-04-27 03:52:58 -04:00
|
|
|
showText: PropTypes.bool.isRequired,
|
2020-10-20 08:44:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default PreviewDownloadButton
|