import PropTypes from 'prop-types'
import { Dropdown, MenuItem, OverlayTrigger, Tooltip } from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import classNames from 'classnames'
import Icon from '../../../shared/components/icon'
import ControlledDropdown from '../../../shared/components/controlled-dropdown'
function PreviewRecompileButton({
compilerState: {
autoCompileHasChanges,
autoCompileHasLintingError,
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 recompileButtonGroupClasses = classNames(
'btn-recompile-group',
'toolbar-item',
{
'btn-recompile-group-has-changes':
autoCompileHasChanges && !autoCompileHasLintingError,
}
)
const buttonElement = (
)
return showText ? (
buttonElement
) : (
{isCompiling ? t('compiling') : t('recompile')}
}
>
{buttonElement}
)
}
PreviewRecompileButton.propTypes = {
compilerState: PropTypes.shape({
autoCompileHasChanges: PropTypes.bool.isRequired,
autoCompileHasLintingError: PropTypes.bool,
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