pdf-compile-button.js 3.2 KB

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