forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 1.11 KB
/
index.js
File metadata and controls
40 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React from 'react';
import { classes } from 'common/util';
import styles from './Divider.module.scss';
class Divider extends React.Component {
constructor(props) {
super(props);
this.handleMouseDown = this.handleMouseDown.bind(this);
this.handleMouseMove = this.handleMouseMove.bind(this);
this.handleMouseUp = this.handleMouseUp.bind(this);
}
handleMouseDown(e) {
this.target = e.target;
document.addEventListener('mousemove', this.handleMouseMove);
document.addEventListener('mouseup', this.handleMouseUp);
}
handleMouseMove(e) {
const { onResize } = this.props;
if (onResize) onResize(this.target.parentElement, e.clientX, e.clientY);
}
handleMouseUp(e) {
document.removeEventListener('mousemove', this.handleMouseMove);
document.removeEventListener('mouseup', this.handleMouseUp);
}
render() {
const { className, horizontal } = this.props;
return (
<div className={classes(styles.divider, horizontal ? styles.horizontal : styles.vertical, className)}
onMouseDown={this.handleMouseDown} />
);
}
}
export default Divider;