pdf-compile-button.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {
  2. Button,
  3. Dropdown,
  4. MenuItem,
  5. OverlayTrigger,
  6. Tooltip,
  7. } from 'react-bootstrap'
  8. import Icon from '../../../shared/components/icon'
  9. import ControlledDropdown from '../../../shared/components/controlled-dropdown'
  10. import { useTranslation } from 'react-i18next'
  11. import { memo } from 'react'
  12. import classnames from 'classnames'
  13. import { useCompileContext } from '../../../shared/context/compile-context'
  14. const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
  15. function PdfCompileButton() {
  16. const {
  17. autoCompile,
  18. compiling,
  19. draft,
  20. hasChanges,
  21. setAutoCompile,
  22. setDraft,
  23. setStopOnValidationError,
  24. stopOnValidationError,
  25. startCompile,
  26. stopCompile,
  27. recompileFromScratch,
  28. } = useCompileContext()
  29. const { t } = useTranslation()
  30. const compileButtonLabel = compiling ? t('compiling') + '…' : t('recompile')
  31. return (
  32. <ControlledDropdown
  33. className={classnames({
  34. 'toolbar-item': true,
  35. 'btn-recompile-group': true,
  36. 'btn-recompile-group-has-changes': hasChanges,
  37. })}
  38. id="pdf-recompile-dropdown"
  39. >
  40. <OverlayTrigger
  41. placement="bottom"
  42. delayShow={500}
  43. overlay={
  44. <Tooltip id="tooltip-logs-toggle" className="keyboard-tooltip">
  45. {t('recompile_pdf')}{' '}
  46. <span className="keyboard-shortcut">({modifierKey} + Enter)</span>
  47. </Tooltip>
  48. }
  49. >
  50. <Button
  51. className="btn-recompile"
  52. bsStyle="success"
  53. onClick={startCompile}
  54. aria-label={compileButtonLabel}
  55. >
  56. <Icon type="refresh" spin={compiling} />
  57. <span className="toolbar-hide-medium toolbar-hide-small btn-recompile-label">
  58. {compileButtonLabel}
  59. </span>
  60. </Button>
  61. </OverlayTrigger>
  62. <Dropdown.Toggle
  63. aria-label={t('toggle_compile_options_menu')}
  64. className="btn-recompile"
  65. bsStyle="success"
  66. />
  67. <Dropdown.Menu>
  68. <MenuItem header>{t('auto_compile')}</MenuItem>
  69. <MenuItem onSelect={() => setAutoCompile(true)}>
  70. <Icon type={autoCompile ? 'check' : ''} modifier="fw" />
  71. {t('on')}
  72. </MenuItem>
  73. <MenuItem onSelect={() => setAutoCompile(false)}>
  74. <Icon type={!autoCompile ? 'check' : ''} modifier="fw" />
  75. {t('off')}
  76. </MenuItem>
  77. <MenuItem header>{t('compile_mode')}</MenuItem>
  78. <MenuItem onSelect={() => setDraft(false)}>
  79. <Icon type={!draft ? 'check' : ''} modifier="fw" />
  80. {t('normal')}
  81. </MenuItem>
  82. <MenuItem onSelect={() => setDraft(true)}>
  83. <Icon type={draft ? 'check' : ''} modifier="fw" />
  84. {t('fast')} <span className="subdued">[draft]</span>
  85. </MenuItem>
  86. <MenuItem header>Syntax Checks</MenuItem>
  87. <MenuItem onSelect={() => setStopOnValidationError(true)}>
  88. <Icon type={stopOnValidationError ? 'check' : ''} modifier="fw" />
  89. {t('stop_on_validation_error')}
  90. </MenuItem>
  91. <MenuItem onSelect={() => setStopOnValidationError(false)}>
  92. <Icon type={!stopOnValidationError ? 'check' : ''} modifier="fw" />
  93. {t('ignore_validation_errors')}
  94. </MenuItem>
  95. <MenuItem divider />
  96. <MenuItem
  97. onSelect={stopCompile}
  98. disabled={!compiling}
  99. aria-disabled={!compiling}
  100. >
  101. {t('stop_compile')}
  102. </MenuItem>
  103. <MenuItem
  104. onSelect={recompileFromScratch}
  105. disabled={compiling}
  106. aria-disabled={compiling}
  107. >
  108. {t('recompile_from_scratch')}
  109. </MenuItem>
  110. </Dropdown.Menu>
  111. </ControlledDropdown>
  112. )
  113. }
  114. export default memo(PdfCompileButton)