This repository has been archived by the owner on Dec 17, 2020. It is now read-only.
/
UndoRedoButton.tsx
95 lines (79 loc) · 1.81 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
92
93
94
95
import { ProvenanceGraph } from '@visdesignlab/provenance-lib-core';
import React from 'react';
import { style } from 'typestyle';
export interface UndoRedoConfig<T, S extends string, A> {
undoCallback: () => void;
redoCallback: () => void;
graph?: ProvenanceGraph<T, 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;
return (
<div>
<button
className={undoButtonStyle}
disabled={isAtRoot}
onClick={undoCallback}>Undo</button>
<button
className={redoButtonStyle}
disabled={isAtLatest}
onClick={redoCallback}>Redo</button>
</div>
);
}
const undoButtonStyle = style({
backgroundColor:"#768d87",
borderRadius:"2px",
border:"none",
display:"inline-block",
cursor:"pointer",
color:"#ffffff",
fontFamily:"Lato,Helvetica Neue,Arial,Helvetica,sans-serif",
fontSize:"14px",
padding:"5px 15px",
marginRight: "1px",
marginLeft: "10px",
$nest: {
"&:hover": {
backgroundColor: "#6c7c7c"
},
"&:disabled": {
backgroundColor: "#a8b3b0"
},
"&:active": {
backgroundColor: "#6c7c7c"
}
}
});
const redoButtonStyle = style({
backgroundColor:"#768d87",
borderRadius:"2px",
border:"none",
display:"inline-block",
cursor:"pointer",
color:"#ffffff",
fontFamily:"Lato,Helvetica Neue,Arial,Helvetica,sans-serif",
fontSize:"14px",
padding:"5px 15px",
$nest: {
"&:hover": {
backgroundColor: "#6c7c7c"
},
"&:disabled": {
backgroundColor: "#a8b3b0"
},
"&:active": {
backgroundColor: "#6c7c7c"
}
}
});
export default UndoRedoButton;