blob: 79283479c97acf336e149f3c2c165e05b429838b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
import { IconLookup } from '@fortawesome/fontawesome-svg-core';
import { faChartLine, faClipboard } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { action, makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { Utils } from '../../../Utils';
import './TimelineMenu.scss';
@observer
export class TimelineMenu extends React.Component {
// eslint-disable-next-line no-use-before-define
public static Instance: TimelineMenu;
@observable private _opacity = 0;
@observable private _x = 0;
@observable private _y = 0;
@observable private _currentMenu: JSX.Element[] = [];
constructor(props: object) {
super(props);
makeObservable(this);
TimelineMenu.Instance = this;
}
@action
openMenu = (x?: number, y?: number) => {
this._opacity = 1;
x ? (this._x = x) : (this._x = 0);
y ? (this._y = y) : (this._y = 0);
};
@action
closeMenu = () => {
this._opacity = 0;
this._currentMenu = [];
this._x = -1000000;
this._y = -1000000;
};
@action
addItem = (type: 'input' | 'button', title: string, event: (e: any, ...args: any[]) => void) => {
if (type === 'input') {
const inputRef = React.createRef<HTMLInputElement>();
let text = '';
this._currentMenu.push(
<div key={Utils.GenerateGuid()} className="timeline-menu-item">
<FontAwesomeIcon icon={faClipboard as IconLookup} size="lg" />
<input
className="timeline-menu-input"
ref={inputRef}
placeholder={title}
onChange={e => {
e.stopPropagation();
text = e.target.value;
}}
onKeyDown={e => {
if (e.keyCode === 13) {
event(Number(text));
this.closeMenu();
e.stopPropagation();
}
}}
/>
</div>
);
} else if (type === 'button') {
this._currentMenu.push(
<div key={Utils.GenerateGuid()} className="timeline-menu-item">
<FontAwesomeIcon icon={faChartLine as IconLookup} size="lg" />
<p
className="timeline-menu-desc"
onClick={e => {
e.preventDefault();
e.stopPropagation();
event(e);
this.closeMenu();
}}>
{title}
</p>
</div>
);
}
};
@action
addMenu = (title: string) => {
this._currentMenu.unshift(
<div key={Utils.GenerateGuid()} className="timeline-menu-header">
<p className="timeline-menu-header-desc">{title}</p>
</div>
);
};
render() {
return (
<div key={Utils.GenerateGuid()} className="timeline-menu-container" style={{ opacity: this._opacity, left: this._x, top: this._y }}>
{this._currentMenu}
</div>
);
}
}
|