pdf-compile-button-inner.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { Button, OverlayTrigger, Tooltip } from 'react-bootstrap'
  2. import PropTypes from 'prop-types'
  3. import Icon from '../../../shared/components/icon'
  4. import { useTranslation } from 'react-i18next'
  5. import { memo } from 'react'
  6. import { useLayoutContext } from '../../../shared/context/layout-context'
  7. const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
  8. function PdfCompileButtonInner({ startCompile, compiling }) {
  9. const { detachRole, view, pdfLayout } = useLayoutContext()
  10. const { t } = useTranslation()
  11. const compileButtonLabel = compiling ? t('compiling') + '…' : t('recompile')
  12. // show the compile shortcut when the editor is visible
  13. const showCompileShortcut =
  14. detachRole !== 'detached' &&
  15. (view === 'editor' || pdfLayout === 'sideBySide')
  16. return (
  17. <OverlayTrigger
  18. placement="bottom"
  19. delayShow={500}
  20. overlay={
  21. <Tooltip id="tooltip-logs-toggle" className="keyboard-tooltip">
  22. {t('recompile_pdf')}{' '}
  23. {showCompileShortcut && (
  24. <span className="keyboard-shortcut">({modifierKey} + Enter)</span>
  25. )}
  26. </Tooltip>
  27. }
  28. >
  29. <Button
  30. className="btn-recompile"
  31. bsStyle="success"
  32. onClick={() => startCompile()}
  33. aria-label={compileButtonLabel}
  34. disabled={compiling}
  35. >
  36. <Icon type="refresh" spin={compiling} />
  37. <span className="toolbar-hide-medium toolbar-hide-small btn-recompile-label">
  38. {compileButtonLabel}
  39. </span>
  40. </Button>
  41. </OverlayTrigger>
  42. )
  43. }
  44. PdfCompileButtonInner.propTypes = {
  45. compiling: PropTypes.bool.isRequired,
  46. startCompile: PropTypes.func.isRequired,
  47. }
  48. export default memo(PdfCompileButtonInner)