pdf-compile-button.js 3.3 KB

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