detach-compile-button.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { useTranslation } from 'react-i18next'
  2. import { memo } from 'react'
  3. import { Button } from 'react-bootstrap'
  4. import classNames from 'classnames'
  5. import Icon from '../../../shared/components/icon'
  6. import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
  7. import Tooltip from '../../../shared/components/tooltip'
  8. const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
  9. function DetachCompileButton() {
  10. const { t } = useTranslation()
  11. const { compiling, startCompile, hasChanges } = useDetachCompileContext()
  12. const compileButtonLabel = compiling ? `${t('compiling')}…` : t('recompile')
  13. const tooltipElement = (
  14. <>
  15. {t('recompile_pdf')}{' '}
  16. <span className="keyboard-shortcut">({modifierKey} + Enter)</span>
  17. </>
  18. )
  19. return (
  20. <div className="detach-compile-button-container">
  21. <Tooltip
  22. id="detach-compile"
  23. description={tooltipElement}
  24. tooltipProps={{ className: 'keyboard-tooltip' }}
  25. overlayProps={{ delayShow: 500 }}
  26. >
  27. <Button
  28. bsStyle="primary"
  29. onClick={() => startCompile()}
  30. disabled={compiling}
  31. className={classNames('detach-compile-button', {
  32. 'btn-striped-animated': hasChanges,
  33. 'detach-compile-button-disabled': compiling,
  34. })}
  35. >
  36. <Icon type="refresh" spin={compiling} />
  37. <span className="detach-compile-button-label">
  38. {compileButtonLabel}
  39. </span>
  40. </Button>
  41. </Tooltip>
  42. </div>
  43. )
  44. }
  45. export default memo(DetachCompileButton)