import { useTranslation } from 'react-i18next' import { memo } from 'react' import classNames from 'classnames' import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context' import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error' import SplitMenu from '../../../shared/components/split-menu' import Icon from '../../../shared/components/icon' const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl' function PdfCompileButton() { const { animateCompileDropdownArrow, autoCompile, compiling, draft, hasChanges, setAnimateCompileDropdownArrow, setAutoCompile, setDraft, setStopOnValidationError, stopOnFirstError, stopOnValidationError, startCompile, stopCompile, recompileFromScratch, } = useCompileContext() const { enableStopOnFirstError, disableStopOnFirstError } = useStopOnFirstError({ eventSource: 'dropdown' }) const { t } = useTranslation() const compileButtonLabel = compiling ? `${t('compiling')}…` : t('recompile') const tooltipElement = ( <> {t('recompile_pdf')}{' '} ({modifierKey} + Enter) ) const dropdownToggleClassName = classNames({ 'detach-compile-button-animate': animateCompileDropdownArrow, 'btn-striped-animated': hasChanges, }) const buttonClassName = classNames({ 'btn-striped-animated': hasChanges, 'no-left-radius': true, }) return ( startCompile(), text: compileButtonLabel, className: buttonClassName, }} dropdownToggle={{ 'aria-label': t('toggle_compile_options_menu'), handleAnimationEnd: () => setAnimateCompileDropdownArrow(false), className: dropdownToggleClassName, }} dropdown={{ id: 'pdf-recompile-dropdown', }} > {t('auto_compile')} setAutoCompile(true)}> {t('on')} setAutoCompile(false)}> {t('off')} {t('compile_mode')} setDraft(false)}> {t('normal')} setDraft(true)}> {t('fast')} [draft] Syntax Checks setStopOnValidationError(true)}> {t('stop_on_validation_error')} setStopOnValidationError(false)}> {t('ignore_validation_errors')} {t('compile_error_handling')} {t('stop_on_first_error')} {t('try_to_compile_despite_errors')} stopCompile()} disabled={!compiling} aria-disabled={!compiling} > {t('stop_compile')} recompileFromScratch()} disabled={compiling} aria-disabled={compiling} > {t('recompile_from_scratch')} ) } export default memo(PdfCompileButton)