diff options
Diffstat (limited to 'src/client/views/AntimodeMenu.tsx')
-rw-r--r-- | src/client/views/AntimodeMenu.tsx | 143 |
1 files changed, 86 insertions, 57 deletions
diff --git a/src/client/views/AntimodeMenu.tsx b/src/client/views/AntimodeMenu.tsx index 0f1fc6b69..de1207ce4 100644 --- a/src/client/views/AntimodeMenu.tsx +++ b/src/client/views/AntimodeMenu.tsx @@ -1,8 +1,7 @@ -import React = require("react"); -import { observable, action, runInAction } from "mobx"; -import "./AntimodeMenu.scss"; -export interface AntimodeMenuProps { -} +import React = require('react'); +import { observable, action, runInAction } from 'mobx'; +import './AntimodeMenu.scss'; +export interface AntimodeMenuProps {} /** * This is an abstract class that serves as the base for a PDF-style or Marquee-style @@ -17,15 +16,19 @@ export abstract class AntimodeMenu<T extends AntimodeMenuProps> extends React.Co @observable protected _top: number = -300; @observable protected _left: number = -300; @observable protected _opacity: number = 0; - @observable protected _transitionProperty: string = "opacity"; - @observable protected _transitionDuration: string = "0.5s"; - @observable protected _transitionDelay: string = ""; + @observable protected _transitionProperty: string = 'opacity'; + @observable protected _transitionDuration: string = '0.5s'; + @observable protected _transitionDelay: string = ''; @observable protected _canFade: boolean = false; @observable public Pinned: boolean = false; - get width() { return this._mainCont.current ? this._mainCont.current.getBoundingClientRect().width : 0; } - get height() { return this._mainCont.current ? this._mainCont.current.getBoundingClientRect().height : 0; } + get width() { + return this._mainCont.current ? this._mainCont.current.getBoundingClientRect().width : 0; + } + get height() { + return this._mainCont.current ? this._mainCont.current.getBoundingClientRect().height : 0; + } @action /** @@ -36,12 +39,12 @@ export abstract class AntimodeMenu<T extends AntimodeMenuProps> extends React.Co */ public jumpTo = (x: number, y: number, forceJump: boolean = false) => { if (!this.Pinned || forceJump) { - this._transitionProperty = this._transitionDuration = this._transitionDelay = ""; + this._transitionProperty = this._transitionDuration = this._transitionDelay = ''; this._opacity = 1; this._left = x; this._top = y; } - } + }; @action /** @@ -51,56 +54,56 @@ export abstract class AntimodeMenu<T extends AntimodeMenuProps> extends React.Co public fadeOut = (forceOut: boolean) => { if (!this.Pinned) { if (this._opacity === 0.2) { - this._transitionProperty = "opacity"; - this._transitionDuration = "0.1s"; + this._transitionProperty = 'opacity'; + this._transitionDuration = '0.1s'; } if (forceOut) { - this._transitionProperty = ""; - this._transitionDuration = ""; + this._transitionProperty = ''; + this._transitionDuration = ''; } - this._transitionDelay = ""; + this._transitionDelay = ''; this._opacity = 0; this._left = this._top = -300; } - } + }; @action protected pointerLeave = (e: React.PointerEvent) => { if (!this.Pinned && this._canFade) { - this._transitionProperty = "opacity"; - this._transitionDuration = "0.5s"; - this._transitionDelay = "1s"; + this._transitionProperty = 'opacity'; + this._transitionDuration = '0.5s'; + this._transitionDelay = '1s'; this._opacity = 0.2; setTimeout(() => this.fadeOut(false), 3000); } - } + }; @action protected pointerEntered = (e: React.PointerEvent) => { - this._transitionProperty = "opacity"; - this._transitionDuration = "0.1s"; - this._transitionDelay = ""; + this._transitionProperty = 'opacity'; + this._transitionDuration = '0.1s'; + this._transitionDelay = ''; this._opacity = 1; - } + }; @action protected togglePin = (e: React.MouseEvent) => { - runInAction(() => this.Pinned = !this.Pinned); - } + runInAction(() => (this.Pinned = !this.Pinned)); + }; protected dragStart = (e: React.PointerEvent) => { - document.removeEventListener("pointermove", this.dragging); - document.addEventListener("pointermove", this.dragging); - document.removeEventListener("pointerup", this.dragEnd); - document.addEventListener("pointerup", this.dragEnd); + document.removeEventListener('pointermove', this.dragging); + document.addEventListener('pointermove', this.dragging); + document.removeEventListener('pointerup', this.dragEnd); + document.addEventListener('pointerup', this.dragEnd); this._offsetX = e.pageX - this._mainCont.current!.getBoundingClientRect().left; this._offsetY = e.pageY - this._mainCont.current!.getBoundingClientRect().top; e.stopPropagation(); e.preventDefault(); - } + }; @action protected dragging = (e: PointerEvent) => { @@ -115,32 +118,41 @@ export abstract class AntimodeMenu<T extends AntimodeMenuProps> extends React.Co e.stopPropagation(); e.preventDefault(); - } + }; protected dragEnd = (e: PointerEvent) => { - document.removeEventListener("pointermove", this.dragging); - document.removeEventListener("pointerup", this.dragEnd); + document.removeEventListener('pointermove', this.dragging); + document.removeEventListener('pointerup', this.dragEnd); e.stopPropagation(); e.preventDefault(); - } + }; protected handleContextMenu = (e: React.MouseEvent) => { e.stopPropagation(); e.preventDefault(); - } + }; protected getDragger = () => { - return <div className="antimodeMenu-dragger" key="dragger" onPointerDown={this.dragStart} style={{ width: "20px" }} />; - } + return <div className="antimodeMenu-dragger" key="dragger" onPointerDown={this.dragStart} style={{ width: '20px' }} />; + }; - protected getElement(buttons: JSX.Element[]) { + protected getElement(buttons: JSX.Element) { return ( - <div className="antimodeMenu-cont" onPointerLeave={this.pointerLeave} onPointerEnter={this.pointerEntered} ref={this._mainCont} onContextMenu={this.handleContextMenu} + <div + className="antimodeMenu-cont" + onPointerLeave={this.pointerLeave} + onPointerEnter={this.pointerEntered} + ref={this._mainCont} + onContextMenu={this.handleContextMenu} style={{ - left: this._left, top: this._top, opacity: this._opacity, transitionProperty: this._transitionProperty, transitionDuration: this._transitionDuration, transitionDelay: this._transitionDelay, - position: this.Pinned ? "unset" : undefined + left: this._left, + top: this._top, + opacity: this._opacity, + transitionProperty: this._transitionProperty, + transitionDuration: this._transitionDuration, + transitionDelay: this._transitionDelay, + position: this.Pinned ? 'unset' : undefined, }}> - {/* {this.getDragger} */} {buttons} </div> ); @@ -148,34 +160,51 @@ export abstract class AntimodeMenu<T extends AntimodeMenuProps> extends React.Co protected getElementVert(buttons: JSX.Element[]) { return ( - <div className="antimodeMenu-cont" onPointerLeave={this.pointerLeave} onPointerEnter={this.pointerEntered} ref={this._mainCont} onContextMenu={this.handleContextMenu} + <div + className="antimodeMenu-cont" + onPointerLeave={this.pointerLeave} + onPointerEnter={this.pointerEntered} + ref={this._mainCont} + onContextMenu={this.handleContextMenu} style={{ left: this.Pinned ? undefined : this._left, top: this.Pinned ? 0 : this._top, right: this.Pinned ? 0 : undefined, - height: "inherit", + height: 'inherit', width: 200, - opacity: this._opacity, transitionProperty: this._transitionProperty, transitionDuration: this._transitionDuration, transitionDelay: this._transitionDelay, - position: this.Pinned ? "absolute" : undefined + opacity: this._opacity, + transitionProperty: this._transitionProperty, + transitionDuration: this._transitionDuration, + transitionDelay: this._transitionDelay, + position: this.Pinned ? 'absolute' : undefined, }}> {buttons} </div> ); } - - protected getElementWithRows(rows: JSX.Element[], numRows: number, hasDragger: boolean = true) { return ( - <div className="antimodeMenu-cont with-rows" onPointerLeave={this.pointerLeave} onPointerEnter={this.pointerEntered} ref={this._mainCont} onContextMenu={this.handleContextMenu} + <div + className="antimodeMenu-cont with-rows" + onPointerLeave={this.pointerLeave} + onPointerEnter={this.pointerEntered} + ref={this._mainCont} + onContextMenu={this.handleContextMenu} style={{ - left: this._left, top: this._top, opacity: this._opacity, transitionProperty: this._transitionProperty, - transitionDuration: this._transitionDuration, transitionDelay: this._transitionDelay, height: "auto", - flexDirection: this.Pinned ? "row" : undefined, position: this.Pinned ? "unset" : undefined + left: this._left, + top: this._top, + opacity: this._opacity, + transitionProperty: this._transitionProperty, + transitionDuration: this._transitionDuration, + transitionDelay: this._transitionDelay, + height: 'auto', + flexDirection: this.Pinned ? 'row' : undefined, + position: this.Pinned ? 'unset' : undefined, }}> - {hasDragger ? <div className="antimodeMenu-dragger" onPointerDown={this.dragStart} style={{ width: "20px" }} /> : (null)} + {hasDragger ? <div className="antimodeMenu-dragger" onPointerDown={this.dragStart} style={{ width: '20px' }} /> : null} {rows} </div> ); } -}
\ No newline at end of file +} |