detach-compile-button.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { useTranslation } from 'react-i18next'
  2. import { memo } from 'react'
  3. import classnames from 'classnames'
  4. import Icon from '../../../shared/components/icon'
  5. import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
  6. import OLTooltip from '@/features/ui/components/ol/ol-tooltip'
  7. import OLButton from '@/features/ui/components/ol/ol-button'
  8. import { bsVersion } from '@/features/utils/bootstrap-5'
  9. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  10. const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
  11. function DetachCompileButton() {
  12. const { t } = useTranslation()
  13. const { compiling, startCompile, hasChanges } = useDetachCompileContext()
  14. const compileButtonLabel = compiling ? `${t('compiling')}…` : t('recompile')
  15. const tooltipElement = (
  16. <>
  17. {t('recompile_pdf')}{' '}
  18. <span className="keyboard-shortcut">({modifierKey} + Enter)</span>
  19. </>
  20. )
  21. return (
  22. <div
  23. className={classnames(
  24. 'detach-compile-button-container',
  25. bsVersion({ bs5: 'ms-1' })
  26. )}
  27. >
  28. <OLTooltip
  29. id="detach-compile"
  30. description={tooltipElement}
  31. tooltipProps={{ className: 'keyboard-tooltip' }}
  32. overlayProps={{ delay: { show: 500, hide: 0 } }}
  33. >
  34. <OLButton
  35. variant="primary"
  36. onClick={() => startCompile()}
  37. disabled={compiling}
  38. className={classnames('detach-compile-button', {
  39. 'btn-striped-animated': hasChanges,
  40. 'detach-compile-button-disabled': compiling,
  41. })}
  42. size="sm"
  43. isLoading={compiling}
  44. bs3Props={{
  45. loading: compiling && (
  46. <>
  47. <Icon type="refresh" spin={compiling} />
  48. <span className="detach-compile-button-label">
  49. {compileButtonLabel}
  50. </span>
  51. </>
  52. ),
  53. }}
  54. >
  55. <BootstrapVersionSwitcher
  56. bs3={
  57. <>
  58. <Icon type="refresh" spin={compiling} />
  59. <span className="detach-compile-button-label">
  60. {compileButtonLabel}
  61. </span>
  62. </>
  63. }
  64. bs5={t('recompile')}
  65. />
  66. </OLButton>
  67. </OLTooltip>
  68. </div>
  69. )
  70. }
  71. export default memo(DetachCompileButton)