-
-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathdeck-code-surfer-split.js
More file actions
92 lines (85 loc) · 2.57 KB
/
deck-code-surfer-split.js
File metadata and controls
92 lines (85 loc) · 2.57 KB
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
import CodeSurfer from "code-surfer";
import React from "react";
import { modes, incStep, decStep } from "mdx-deck";
import { withDeck } from "mdx-deck/dist/context";
import { withSlide } from "mdx-deck/dist/Slide";
export default withDeck(
withSlide(
class extends React.Component {
componentDidMount() {
document.body.addEventListener("keydown", this.handleKeyDown);
}
componentWillUnmount() {
document.body.removeEventListener("keydown", this.handleKeyDown);
}
shouldComponentUpdate() {
return this.props.deck.index === this.props.slide.index;
}
handleKeyDown = e => {
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
if (this.props.deck.index !== this.props.slide.index) return;
const { update } = this.props.deck;
switch (e.key) {
case "ArrowDown":
e.preventDefault();
update(incStep(this.props.stepsTop));
break;
case "ArrowUp":
e.preventDefault();
update(decStep());
break;
}
};
render() {
const {
codeTop,
codeBottom,
stepsTop,
stepsBottom,
title,
showNumbers,
notes,
Prism
} = this.props;
const { step, mode } = this.props.deck;
const currentStepTop =
step < 0 ? { notes } : stepsTop[step] || stepsTop[0];
const currentStepBottom =
step < 0 ? { notes } : stepsBottom[step] || stepsBottom[0];
const topSize = codeTop.split("\n").length - 1;
const bottomSize = codeBottom.split("\n").length - 1;
return (
<div
style={{
height: "100vh",
display: "flex",
flexDirection: "column"
}}
>
<div style={{ flex: topSize, overflow: "hidden" }} key="codeTop">
<CodeSurfer
code={codeTop}
step={currentStepTop}
showNumbers={showNumbers}
Prism={Prism}
/>
</div>
<div style={{ height: "25px" }} />
<div
style={{ flex: bottomSize, overflow: "hidden" }}
key="codeBottom"
>
<CodeSurfer
code={codeBottom}
step={currentStepBottom}
showNumbers={showNumbers}
Prism={Prism}
/>
</div>
<div style={{ height: "25px" }} />
</div>
);
}
}
)
);