import React from 'react' import PropTypes from 'prop-types' import { Dropdown, MenuItem, OverlayTrigger, Tooltip } from 'react-bootstrap' import { useTranslation } from 'react-i18next' import Icon from '../../../shared/components/icon' function PreviewRecompileButton({ compilerState: { isAutoCompileOn, isCompiling, isDraftModeOn, isSyntaxCheckOn }, onRecompile, onRecompileFromScratch, onRunSyntaxCheckNow, onStopCompilation, onSetAutoCompile, onSetDraftMode, onSetSyntaxCheck, showText }) { const { t } = useTranslation() function handleSelectAutoCompileOn() { onSetAutoCompile(true) } function handleSelectAutoCompileOff() { onSetAutoCompile(false) } function handleSelectDraftModeOn() { onSetDraftMode(true) } function handleSelectDraftModeOff() { onSetDraftMode(false) } function handleSelectSyntaxCheckOn() { onSetSyntaxCheck(true) } function handleSelectSyntaxCheckOff() { onSetSyntaxCheck(false) } let compilingProps = {} let recompileProps = {} function _hideText(keepAria) { return { 'aria-hidden': !keepAria, style: { position: 'absolute', right: '-100vw' } } } if (!showText) { compilingProps = _hideText(isCompiling) recompileProps = _hideText(!isCompiling) } else if (isCompiling) { recompileProps = _hideText() } else { compilingProps = _hideText() } const buttonElement = ( {t('auto_compile')} {t('on')} {t('off')} {t('compile_mode')} {t('normal')} {t('fast')} [draft] Syntax Checks {t('stop_on_validation_error')} {t('ignore_validation_errors')} {t('run_syntax_check_now')} {t('stop_compile')} {t('recompile_from_scratch')} ) return showText ? ( buttonElement ) : ( {isCompiling ? t('compiling') : t('recompile')} } > {buttonElement} ) } PreviewRecompileButton.propTypes = { compilerState: PropTypes.shape({ isAutoCompileOn: PropTypes.bool.isRequired, isCompiling: PropTypes.bool.isRequired, isDraftModeOn: PropTypes.bool.isRequired, isSyntaxCheckOn: PropTypes.bool.isRequired, logEntries: PropTypes.object.isRequired }), onRecompile: PropTypes.func.isRequired, onRecompileFromScratch: PropTypes.func.isRequired, onRunSyntaxCheckNow: PropTypes.func.isRequired, onSetAutoCompile: PropTypes.func.isRequired, onSetDraftMode: PropTypes.func.isRequired, onSetSyntaxCheck: PropTypes.func.isRequired, onStopCompilation: PropTypes.func.isRequired, showText: PropTypes.bool.isRequired } export default PreviewRecompileButton