import { action, observable } from "mobx"; import * as React from "react"; interface DividerProps { index: number columnStartXCoords: number[] xMargin: number setColumnStartXCoords: (newCoords: number[]) => void } export default class Divider extends React.Component{ @observable private isHoverActive = false; @observable private isResizingActive = false; @action private registerResizing = (e: React.PointerEvent) => { e.stopPropagation(); e.preventDefault(); window.removeEventListener("pointermove", this.onPointerMove); window.removeEventListener("pointerup", this.onPointerUp); window.addEventListener("pointermove", this.onPointerMove); window.addEventListener("pointerup", this.onPointerUp); this.isResizingActive = true; } @action private onPointerUp = () => { this.isResizingActive = false; this.isHoverActive = false; window.removeEventListener("pointermove", this.onPointerMove); window.removeEventListener("pointerup", this.onPointerUp); } @action onPointerMove = ({ movementX }: PointerEvent) => { // if (DragManager.docsBeingDragged.length == 0) { // //convert client X to how we're doing stuff // const xPos = e.clientX + 2 * this.props.xMargin // // get difference (-25 is because that's the center of the divider) // const xDividerPos = this.props.columnStartXCoords[this.props.index + 1] - 25 // const diff = xDividerPos - xPos // // make a copy of the array // const colXCoords = [...this.props.columnStartXCoords] // colXCoords[this.props.index + 1] += movementX this.props.columnStartXCoords[this.props.index + 1] += movementX // this.props.setColumnStartXCoords(colXCoords) console.log(this.props.columnStartXCoords) // this.props.columnStartXCoords = colXCoords // } } render() { return (
this.isHoverActive = true)} onPointerLeave={action(() => !this.isResizingActive && (this.isHoverActive = false))} >
this.registerResizing(e)} style={{ height: "95%", width: 12, borderRight: "4px solid #282828", borderLeft: "4px solid #282828", margin: "0px 10px" }} />
) } }