This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
widget.js
59 lines (50 loc) · 1.72 KB
/
widget.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
import React from "react";
import { withStyles } from "@material-ui/core/styles";
import CircularProgress from "@material-ui/core/CircularProgress";
import Typography from "@material-ui/core/Typography";
import { DashboardContext } from "../App/context";
import { uuidv4, onNextFrame } from "../utils";
const styles = (theme) => ({
loading: {
margin: "auto",
padding: theme.spacing(2),
textAlign: "center",
color: theme.palette.text.secondary,
},
});
class Widget extends React.Component {
render() {
const { classes, data } = this.props;
const { widgetManager } = this.context;
const uuid = uuidv4();
let model_id = data["model_id"];
onNextFrame(() => {
if (widgetManager) {
widgetManager.renderWidget(model_id);
}
});
return (
<div
id={uuid}
className="jupyter-widget output_subarea output_widget_state"
>
<div id={model_id}>
<div className="loading">
<CircularProgress size={14} color="secondary" />
<Typography>loading widget {" "}</Typography>
</div>
</div>
<script type="application/vnd.jupyter.widget-view+json">
{JSON.stringify(data)}
</script>
</div>
);
}
}
Widget.defaultProps = {
mediaType: "application/vnd.jupyter.widget-view+json",
};
Widget.contextType = DashboardContext;
// This is messing up the widget rendering so we do this styles on cell.scss
// export default withStyles(styles, { withTheme: true })(Widget);
export default Widget;