This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
/
UndoRedoButton.tsx
91 lines (80 loc) · 1.91 KB
/
UndoRedoButton.tsx
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
// @ts-ignore
import { ProvenanceGraph } from '@visdesignlab/trrack';
import React from 'react';
import { Button } from 'semantic-ui-react';
import { style } from 'typestyle';
export interface UndoRedoConfig<T, S extends string, A> {
undoCallback: () => void;
redoCallback: () => void;
graph?: ProvenanceGraph<S, A>;
}
function UndoRedoButton<T, S extends string, A>({
graph,
undoCallback,
redoCallback,
}: UndoRedoConfig<T, S, A>) {
if (graph === undefined) {
return null;
}
const isAtRoot = graph.root === graph.current;
const isAtLatest = graph.nodes[graph.current].children.length === 0;
const margin = {
marginRight: '3px',
} as React.CSSProperties;
return (
<div>
<Button
variant="outlined"
className={undoButtonStyle}
disabled={isAtRoot}
onClick={undoCallback}
>
<i style={margin} className="fas fa-undo marginRight"></i>
Undo
</Button>
<Button
variant="outlined"
className={redoButtonStyle}
disabled={isAtLatest}
onClick={redoCallback}
>
<i style={margin} className="fas fa-redo marginRight"></i>
Redo
</Button>
</div>
);
}
const undoButtonStyle = style({
marginTop: '2px',
borderRadius: '2px',
display: 'inline-block',
cursor: 'pointer',
fontFamily: 'Lato,Helvetica Neue,Arial,Helvetica,sans-serif',
fontSize: '14px',
marginRight: '1px',
$nest: {
'&:hover': {
backgroundColor: '#6c7c7c',
},
'&:active': {
backgroundColor: '#6c7c7c',
},
},
});
const redoButtonStyle = style({
marginTop: '2px',
borderRadius: '2px',
display: 'inline-block',
cursor: 'pointer',
fontFamily: 'Lato,Helvetica Neue,Arial,Helvetica,sans-serif',
fontSize: '14px',
$nest: {
'&:hover': {
backgroundColor: '#6c7c7c',
},
'&:active': {
backgroundColor: '#6c7c7c',
},
},
});
export default UndoRedoButton;