From 1f68dae9485294f642bdb842347c53e5fab604d0 Mon Sep 17 00:00:00 2001 From: Melissa Zhang Date: Sun, 19 Apr 2020 01:12:15 -0700 Subject: added slider bar functionality for sliding between two images --- src/client/views/nodes/ComparisonBox.scss | 22 ++++++++++- src/client/views/nodes/ComparisonBox.tsx | 64 ++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/ComparisonBox.scss b/src/client/views/nodes/ComparisonBox.scss index 2c907a010..5112ed4b8 100644 --- a/src/client/views/nodes/ComparisonBox.scss +++ b/src/client/views/nodes/ComparisonBox.scss @@ -15,7 +15,7 @@ .beforeBox-cont { height: 100%; - width: 300px; + background-color: red; } .slide-bar { @@ -34,6 +34,24 @@ top: 0; right: 0; height: 100%; - width: 300px; + width: 100%; + background-color: orange; + } + + .clear-button { + position: absolute; + top: 0; + height: 25px; + width: 25px; + background-color: white; + border-radius: 50%; + } + + .clear-button.before { + left: 0; + } + + .clear-button.after { + right: 0; } } \ No newline at end of file diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx index 5c44b3068..fe3f47e2a 100644 --- a/src/client/views/nodes/ComparisonBox.tsx +++ b/src/client/views/nodes/ComparisonBox.tsx @@ -24,7 +24,6 @@ import { ContentFittingDocumentView } from './ContentFittingDocumentView'; library.add(faImage, faEye as any, faPaintBrush, faBrain); library.add(faFileAudio, faAsterisk); - export const pageSchema = createSchema({ beforeDoc: "string", afterDoc: "string" @@ -56,13 +55,41 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent { + @action + private registerSliding = (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); + } + + componentDidMount() { + const initialWidth = this.props.PanelWidth() / 2; + this.props.Document.clipWidth = initialWidth; + } + + private onPointerMove = ({ movementX }: PointerEvent) => { + const width = this.props.Document.clipWidth + movementX; + if (width && width > 0 && width < this.props.PanelWidth()) { + this.props.Document.clipWidth = width; + } + } + + @action + private onPointerUp = () => { + window.removeEventListener("pointermove", this.onPointerMove); + window.removeEventListener("pointerup", this.onPointerUp); + } + + clearBeforeDoc = (e: React.MouseEvent) => { e.stopPropagation; e.preventDefault; delete this.props.Document.beforeDoc; } - clearAfterDoc = (e: PointerEvent) => { + clearAfterDoc = (e: React.MouseEvent) => { e.stopPropagation; e.preventDefault; delete this.props.Document.afterDoc; @@ -75,9 +102,11 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent -
+
+ {/* wraps around before image and slider bar */} +
+ style={{ width: this.props.PanelWidth() }}> { beforeDoc ? - +
this.clearBeforeDoc(e)} + /> : -
upload before image!
+
+ upload before image! +
}
-
+
this.registerSliding(e)} />
{ this._afterDropDisposer && this._afterDropDisposer(); this._afterDropDisposer = this.createDropTarget(ele, "afterDoc"); - }} - style={{ backgroundColor: "orange" }}> + }}> { afterDoc ? - +
this.clearAfterDoc(e)} + /> : -
+
upload after image!
} -- cgit v1.2.3-70-g09d2