mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
* auto resize panes when dbl click on separator is triggered * use const instead of let
This commit is contained in:
parent
6b9a4f6ff0
commit
82c7afbeec
1 changed files with 33 additions and 6 deletions
|
|
@ -1,11 +1,13 @@
|
|||
/* eslint-disable quote-props */
|
||||
import React from 'react';
|
||||
import {PureComponent} from '../base-components';
|
||||
import _ from 'lodash';
|
||||
|
||||
export default class SplitPane extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleDragStart = this.handleDragStart.bind(this);
|
||||
this.handleAutoResize = this.handleAutoResize.bind(this);
|
||||
this.onDrag = this.onDrag.bind(this);
|
||||
this.onDragEnd = this.onDragEnd.bind(this);
|
||||
this.state = {dragging: false};
|
||||
|
|
@ -18,6 +20,28 @@ export default class SplitPane extends PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
setupPanes(ev) {
|
||||
this.panes = Array.from(ev.target.parentNode.childNodes);
|
||||
this.paneIndex = this.panes.indexOf(ev.target);
|
||||
this.paneIndex -= Math.ceil(this.paneIndex / 2);
|
||||
}
|
||||
|
||||
handleAutoResize(ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
this.setupPanes(ev);
|
||||
|
||||
const sizes_ = this.getSizes();
|
||||
sizes_[this.paneIndex] = 0;
|
||||
sizes_[this.paneIndex + 1] = 0;
|
||||
|
||||
const availableWidth = 1 - _.sum(sizes_);
|
||||
sizes_[this.paneIndex] = availableWidth / 2;
|
||||
sizes_[this.paneIndex + 1] = availableWidth / 2;
|
||||
|
||||
this.props.onResize(sizes_);
|
||||
}
|
||||
|
||||
handleDragStart(ev) {
|
||||
ev.preventDefault();
|
||||
this.setState({dragging: true});
|
||||
|
|
@ -37,14 +61,12 @@ export default class SplitPane extends PureComponent {
|
|||
|
||||
this.dragTarget = ev.target;
|
||||
this.dragPanePosition = this.dragTarget.getBoundingClientRect()[this.d2];
|
||||
this.panes = Array.from(ev.target.parentNode.childNodes);
|
||||
this.panesSize = ev.target.parentNode.getBoundingClientRect()[this.d1];
|
||||
this.paneIndex = this.panes.indexOf(ev.target);
|
||||
this.paneIndex -= Math.ceil(this.paneIndex / 2);
|
||||
this.setupPanes(ev);
|
||||
}
|
||||
|
||||
onDrag(ev) {
|
||||
let {sizes} = this.props;
|
||||
getSizes() {
|
||||
const {sizes} = this.props;
|
||||
let sizes_;
|
||||
|
||||
if (sizes) {
|
||||
|
|
@ -53,9 +75,13 @@ export default class SplitPane extends PureComponent {
|
|||
const total = this.props.children.length;
|
||||
const count = new Array(total).fill(1 / total);
|
||||
|
||||
sizes = count;
|
||||
sizes_ = count;
|
||||
}
|
||||
return sizes_;
|
||||
}
|
||||
|
||||
onDrag(ev) {
|
||||
const sizes_ = this.getSizes();
|
||||
|
||||
const i = this.paneIndex;
|
||||
const pos = ev[this.d3];
|
||||
|
|
@ -106,6 +132,7 @@ export default class SplitPane extends PureComponent {
|
|||
<div
|
||||
key="divider"
|
||||
onMouseDown={this.handleDragStart}
|
||||
onDoubleClick={this.handleAutoResize}
|
||||
style={{backgroundColor: borderColor}}
|
||||
className={css('divider', `divider_${direction}`)}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue