Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es6ify scrollbuttons #22376

Merged
merged 3 commits into from
May 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 31 additions & 19 deletions apps/src/templates/instructions/ScrollButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,32 @@ const CRAFT_MARGIN = 0;
/**
* A pair of buttons for scrolling instructions in CSF
*/
const ScrollButtons = React.createClass({
propTypes: {
class ScrollButtons extends React.Component {
static propTypes = {
style: PropTypes.object,
visible: PropTypes.bool.isRequired,
height: PropTypes.number.isRequired,
getScrollTarget: PropTypes.func.isRequired,
isMinecraft: PropTypes.bool.isRequired,
},
};

getMargin() {
return this.props.isMinecraft ? CRAFT_MARGIN : MARGIN;
},
}

getMinHeight() {
const scrollButtonsHeight = getOuterHeight(this.refs.scrollUp, true) +
getOuterHeight(this.refs.scrollDown, true);
const scrollButtonsHeight = getOuterHeight(this.scrollUp, true) +
getOuterHeight(this.scrollDown, true);
return scrollButtonsHeight + (this.getMargin() * 2);
},
}

scrollStartUp = () => {
this.scrollStart(DIRECTIONS.UP);
};

scrollStartDown = () => {
this.scrollStart(DIRECTIONS.DOWN);
};

scrollStart(dir) {
// initial scroll in response to button click
Expand All @@ -103,16 +111,16 @@ const ScrollButtons = React.createClass({
}.bind(this), CONTINUOUS_SCROLL_TIMEOUT);

this.unbindMouseUp = addMouseUpTouchEvent(document, this.scrollStop);
},
}

scrollStop() {
scrollStop = () => {
this.unbindMouseUp();
clearTimeout(this.scrollTimeout);
clearInterval(this.scrollInterval);
this.unbindMouseUp = null;
this.scrollTimeout = null;
this.scrollInterval = null;
},
};

render() {

Expand All @@ -133,8 +141,9 @@ const ScrollButtons = React.createClass({
const upButton = (this.props.isMinecraft) ?
<button
className="arrow"
ref="scrollUp"
onMouseDown={this.scrollStart.bind(this, DIRECTIONS.UP)}
ref={(c) => { this.scrollUp = c; }}
key="scrollUp"
onMouseDown={this.scrollStartUp}
style={[
styles.all,
upStyle
Expand All @@ -143,8 +152,9 @@ const ScrollButtons = React.createClass({
<img src="/blockly/media/1x1.gif" className="scroll-up-btn" />
</button> :
<div
ref="scrollUp"
onMouseDown={this.scrollStart.bind(this, DIRECTIONS.UP)}
ref={(c) => { this.scrollUp = c; }}
key="scrollUp"
onMouseDown={this.scrollStartUp}
style={[
styles.all,
styles.arrow,
Expand All @@ -156,8 +166,9 @@ const ScrollButtons = React.createClass({
const downButton = (this.props.isMinecraft) ?
<button
className="arrow"
ref="scrollDown"
onMouseDown={this.scrollStart.bind(this, DIRECTIONS.DOWN)}
ref={(c) => { this.scrollDown = c; }}
key="scrollUp"
onMouseDown={this.scrollStartDown}
style={[
styles.all,
downStyle
Expand All @@ -166,8 +177,9 @@ const ScrollButtons = React.createClass({
<img src="/blockly/media/1x1.gif" className="scroll-down-btn" />
</button> :
<div
ref="scrollDown"
onMouseDown={this.scrollStart.bind(this, DIRECTIONS.DOWN)}
ref={(c) => { this.scrollDown = c; }}
key="scrollDown"
onMouseDown={this.scrollStartDown}
style={[
styles.all,
styles.arrow,
Expand All @@ -183,7 +195,7 @@ const ScrollButtons = React.createClass({
</div>
);
}
});
}

export default connect(function propsFromStore(state) {
return {
Expand Down