forked from Joeyonng/react-jupyter-notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
128 lines (123 loc) · 3.7 KB
/
App.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React, {useState} from 'react';
import nb_test from "./nb_test.json"
import JupyterViewer from "./lib/JupyterViewer";
import hljsStyles from "./lib/hljsStyles";
function App() {
const [state, setState] = useState({
rawIpynb: nb_test,
mediaAlign: "left",
displaySource: "auto",
displayOutput: "auto",
showLineNumbers: true,
codeBlockStyles: undefined,
})
return (
<React.Fragment>
<div
style={{
display: "flex",
justifyContent: "space-between"
}}
>
<input
name="rawIpynb"
type="file"
onChange={e => {
if (e.target.files[0]) {
const reader = new FileReader();
reader.readAsText(e.target.files[0], "UTF-8");
reader.onload = (e) => {
setState({...state, rawIpynb: JSON.parse(e.target.result)})
};
reader.onerror = (e) => {
console.log('reader error!', e)
};
}
}}
/>
<div>
<label htmlFor="mediaAlign">mediaAlign</label>
<select
name="mediaAlign"
onChange={e => {
setState({...state, mediaAlign: e.target.value})
}}
>
<option value="left">left</option>
<option value="center">center</option>
<option value="right">right</option>
</select>
</div>
<div>
<label htmlFor="displaySource">displaySource</label>
<select
name="displaySource"
onChange={e => {
setState({...state, displaySource: e.target.value})
}}
>
<option value="auto">auto</option>
<option value="hide">hide</option>
<option value="show">show</option>
</select>
</div>
<div>
<label htmlFor="displayOutput">displayOutput</label>
<select
name="displayOutput"
onChange={e => {
setState({...state, displayOutput: e.target.value})
}}
>
<option value="auto">auto</option>
<option value="hide">hide</option>
<option value="show">show</option>
<option value="scroll">scroll</option>
</select>
</div>
<div>
<label htmlFor="showLineNumbers">showLineNumbers</label>
<select
name="showLineNumbers"
onChange={e => {
setState({...state, showLineNumbers: e.target.value === 'show'})
}}
>
<option value="show">show</option>
<option value="hide">hide</option>
</select>
</div>
<div>
<label htmlFor="hljsStyle">hljsStyle</label>
<select
name="hljsStyle"
onChange={e => {
setState({
...state,
codeBlockStyles: e.target.value === 'default' ? undefined : {
hljsStyle: e.target.value,
}
})
}}
>
<option key="default" value="default">DEFAULT</option>
{Object.keys(hljsStyles).map(name => (
<option key={name} value={name}>{name}</option>
))}
</select>
</div>
</div>
{!state.rawIpynb ? null :
<JupyterViewer
rawIpynb={state.rawIpynb}
mediaAlign={state.mediaAlign}
showLineNumbers={state.showLineNumbers}
displaySource={state.displaySource}
displayOutput={state.displayOutput}
codeBlockStyles={state.codeBlockStyles}
/>
}
</React.Fragment>
)
}
export default App;