detach-compile-button.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { useTranslation } from 'react-i18next'
  2. import { memo } from 'react'
  3. import classnames from 'classnames'
  4. import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
  5. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  6. import OLButton from '@/shared/components/ol/ol-button'
  7. const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
  8. function DetachCompileButton() {
  9. const { t } = useTranslation()
  10. const { compiling, startCompile, hasChanges } = useDetachCompileContext()
  11. const tooltipElement = (
  12. <>
  13. {t('recompile_pdf')}{' '}
  14. <span className="keyboard-shortcut">({modifierKey} + Enter)</span>
  15. </>
  16. )
  17. return (
  18. <div className="detach-compile-button-container ms-1">
  19. <OLTooltip
  20. id="detach-compile"
  21. description={tooltipElement}
  22. tooltipProps={{ className: 'keyboard-tooltip' }}
  23. overlayProps={{ delay: { show: 500, hide: 0 } }}
  24. >
  25. <OLButton
  26. variant="primary"
  27. onClick={() => startCompile()}
  28. disabled={compiling}
  29. className={classnames('detach-compile-button', {
  30. 'btn-striped-animated': hasChanges,
  31. 'detach-compile-button-disabled': compiling,
  32. })}
  33. size="sm"
  34. isLoading={compiling}
  35. loadingLabel={t('compiling')}
  36. >
  37. {t('recompile')}
  38. </OLButton>
  39. </OLTooltip>
  40. </div>
  41. )
  42. }
  43. export default memo(DetachCompileButton)