diff options
| author | yipstanley <stanley_yip@brown.edu> | 2019-02-10 22:12:04 -0500 |
|---|---|---|
| committer | yipstanley <stanley_yip@brown.edu> | 2019-02-10 22:12:04 -0500 |
| commit | 69f0b463a78c82aaf78ceb6a5162431424452311 (patch) | |
| tree | a54c7129f36d307420422b3babfa6da4d85db67e /src/client/views/ContextMenu.tsx | |
| parent | 2e930b98726a09e597106d43a6763dd36d038771 (diff) | |
| parent | 099c5823f05285fc5086c5a433658cf06dc4a04b (diff) | |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into server_implementation
Diffstat (limited to 'src/client/views/ContextMenu.tsx')
| -rw-r--r-- | src/client/views/ContextMenu.tsx | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/client/views/ContextMenu.tsx b/src/client/views/ContextMenu.tsx new file mode 100644 index 000000000..4f26a75d2 --- /dev/null +++ b/src/client/views/ContextMenu.tsx @@ -0,0 +1,68 @@ +import React = require("react"); +import { ContextMenuItem, ContextMenuProps } from "./ContextMenuItem"; +import { observable } from "mobx"; +import { observer } from "mobx-react"; +import "./ContextMenu.scss" + +@observer +export class ContextMenu extends React.Component { + static Instance: ContextMenu + + @observable private _items: Array<ContextMenuProps> = [{ description: "test", event: (e: React.MouseEvent) => e.preventDefault() }]; + @observable private _pageX: number = 0; + @observable private _pageY: number = 0; + @observable private _display: string = "none"; + + private ref: React.RefObject<HTMLDivElement>; + + constructor(props: Readonly<{}>) { + super(props); + + this.ref = React.createRef() + + ContextMenu.Instance = this; + } + + clearItems() { + this._items = [] + this._display = "none" + } + + addItem(item: ContextMenuProps) { + if (this._items.indexOf(item) === -1) { + this._items.push(item); + } + } + + getItems() { + return this._items; + } + + displayMenu(x: number, y: number) { + this._pageX = x + this._pageY = y + + this._display = "flex" + } + + intersects = (x: number, y: number): boolean => { + if (this.ref.current && this._display !== "none") { + if (x >= this._pageX && x <= this._pageX + this.ref.current.getBoundingClientRect().width) { + if (y >= this._pageY && y <= this._pageY + this.ref.current.getBoundingClientRect().height) { + return true; + } + } + } + return false; + } + + render() { + return ( + <div className="contextMenu-cont" style={{ left: this._pageX, top: this._pageY, display: this._display }} ref={this.ref}> + {this._items.map(prop => { + return <ContextMenuItem {...prop} key={prop.description} /> + })} + </div> + ) + } +}
\ No newline at end of file |
