From 34ec45cac6804d1ef94146033239a8a3003b994f Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 30 Apr 2018 10:06:20 -0700 Subject: [PATCH] Handle specific drag --- ui/src/shared/components/ResizeContainer.tsx | 20 ++++----- ui/src/shared/components/ResizeDivision.tsx | 47 ++++++++++++-------- ui/src/shared/components/ResizeHandle.tsx | 41 ++++++++++++----- ui/src/style/components/resizer.scss | 11 +++++ 4 files changed, 78 insertions(+), 41 deletions(-) diff --git a/ui/src/shared/components/ResizeContainer.tsx b/ui/src/shared/components/ResizeContainer.tsx index e638771df..e9a97830c 100644 --- a/ui/src/shared/components/ResizeContainer.tsx +++ b/ui/src/shared/components/ResizeContainer.tsx @@ -7,7 +7,7 @@ import {ErrorHandling} from 'src/shared/decorators/errors' import {MIN_DIVISIONS, ORIENTATION_HORIZONTAL} from 'src/shared/constants/' interface State { - isDragging: boolean + activeHandleID: string divisions: DivisionState[] } @@ -40,13 +40,13 @@ class Resizer extends Component { constructor(props) { super(props) this.state = { - isDragging: false, + activeHandleID: null, divisions: this.initialDivisions, } } public render() { - const {isDragging, divisions} = this.state + const {activeHandleID, divisions} = this.state const {containerClass, orientation} = this.props if (divisions.length < MIN_DIVISIONS) { @@ -59,7 +59,7 @@ class Resizer extends Component { return (
{ render={d.render} orientation={orientation} draggable={i > 0} - isDragging={isDragging} + activeHandleID={activeHandleID} onHandleStartDrag={this.handleStartDrag} /> ))} @@ -97,20 +97,20 @@ class Resizer extends Component { })) } - private handleStartDrag = () => { - this.setState({isDragging: true}) + private handleStartDrag = activeHandleID => { + this.setState({activeHandleID}) } private handleStopDrag = () => { - this.setState({isDragging: false}) + this.setState({activeHandleID: ''}) } private handleMouseLeave = () => { - this.setState({isDragging: false}) + this.setState({activeHandleID: ''}) } private handleDrag = () => { - if (!this.state.isDragging) { + if (!this.state.activeHandleID) { return } diff --git a/ui/src/shared/components/ResizeDivision.tsx b/ui/src/shared/components/ResizeDivision.tsx index e28e10a92..27c232b98 100644 --- a/ui/src/shared/components/ResizeDivision.tsx +++ b/ui/src/shared/components/ResizeDivision.tsx @@ -8,19 +8,25 @@ import { HUNDRED, } from 'src/shared/constants/' +const NOOP = () => {} + interface Props { id: string name?: string size: number offset: number - isDragging: boolean + activeHandleID: string draggable: boolean orientation: string render: () => ReactElement - onHandleStartDrag: () => void + onHandleStartDrag: (activeHandleID: string) => void } class Division extends PureComponent { + public static defaultProps: Partial = { + name: '', + } + public render() { const {render} = this.props @@ -33,27 +39,30 @@ class Division extends PureComponent { } private get dragHandle() { - const { - name, - isDragging, - orientation, - onHandleStartDrag, - draggable, - } = this.props + const {name, activeHandleID, orientation, id, draggable} = this.props - if (name) { - return
{name}
+ if (!name && !draggable) { + return null } - if (draggable) { - return ( - - ) + return ( + + ) + } + + private get dragCallback() { + const {draggable} = this.props + if (!draggable) { + return NOOP } + + return this.props.onHandleStartDrag } private get style() { diff --git a/ui/src/shared/components/ResizeHandle.tsx b/ui/src/shared/components/ResizeHandle.tsx index 9ba7f4bae..190bf088a 100644 --- a/ui/src/shared/components/ResizeHandle.tsx +++ b/ui/src/shared/components/ResizeHandle.tsx @@ -7,26 +7,43 @@ import { } from 'src/shared/constants/' interface Props { - onHandleStartDrag: () => void - isDragging: boolean + name: string + id: string + onHandleStartDrag: (activeHandleID: string) => void + activeHandleID: string orientation: string } class ResizeHandle extends PureComponent { public render() { - const {onHandleStartDrag, isDragging, orientation} = this.props - return ( -
+
+ {this.props.name} +
) } + + private get className(): string { + const {name, orientation} = this.props + + return classnames({ + 'resizer--handle': !name, + 'resizer--title': name, + dragging: this.isActive, + vertical: orientation === ORIENTATION_VERTICAL, + horizontal: orientation === ORIENTATION_HORIZONTAL, + }) + } + + private get isActive(): boolean { + const {id, activeHandleID} = this.props + + return id === activeHandleID + } + + private handleMouseDown = (): void => { + this.props.onHandleStartDrag(this.props.id) + } } export default ResizeHandle diff --git a/ui/src/style/components/resizer.scss b/ui/src/style/components/resizer.scss index 884ab335d..e71325850 100644 --- a/ui/src/style/components/resizer.scss +++ b/ui/src/style/components/resizer.scss @@ -184,4 +184,15 @@ $resizer-color-kapacitor: $c-rainforest; font-weight: 600; color: $g13-mist; @include no-user-select(); + + &:hover { + cursor: ns-resize; + background-color: $g4-onyx; + } + + &.dragging { + cursor: ns-resize; + color: $c-laser; + background-color: $g5-pepper; + } }