scratch-gui
Version:
GraphicaL User Interface for creating and running Scratch 3.0 projects
69 lines (61 loc) • 1.99 kB
JSX
import PropTypes from 'prop-types';
import React from 'react';
import bindAll from 'lodash.bindall';
import VM from 'scratch-vm';
import {setStageSize, STAGE_SIZES} from '../reducers/stage-size';
import {setFullScreen} from '../reducers/mode';
import {connect} from 'react-redux';
import StageHeaderComponent from '../components/stage-header/stage-header.jsx';
// eslint-disable-next-line react/prefer-stateless-function
class StageHeader extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleKeyPress'
]);
}
componentDidMount () {
document.addEventListener('keydown', this.handleKeyPress);
}
componentWillUnmount () {
document.removeEventListener('keydown', this.handleKeyPress);
}
handleKeyPress (event) {
if (event.key === 'Escape' && this.props.isFullScreen) {
this.props.onSetStageUnFull(false);
}
}
render () {
const {
...props
} = this.props;
return (
<StageHeaderComponent
{...props}
onKeyPress={this.handleKeyPress}
/>
);
}
}
StageHeader.propTypes = {
isFullScreen: PropTypes.bool,
isPlayerOnly: PropTypes.bool,
onSetStageUnFull: PropTypes.func.isRequired,
stageSize: PropTypes.oneOf(Object.keys(STAGE_SIZES)),
vm: PropTypes.instanceOf(VM).isRequired
};
const mapStateToProps = state => ({
stageSize: state.stageSize.stageSize,
isFullScreen: state.mode.isFullScreen,
isPlayerOnly: state.mode.isPlayerOnly
});
const mapDispatchToProps = dispatch => ({
onSetStageLarge: () => dispatch(setStageSize(STAGE_SIZES.large)),
onSetStageSmall: () => dispatch(setStageSize(STAGE_SIZES.small)),
onSetStageFull: () => dispatch(setFullScreen(true)),
onSetStageUnFull: () => dispatch(setFullScreen(false))
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(StageHeader);