-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathattina.js
56 lines (48 loc) · 1.05 KB
/
attina.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
import React from "react";
import { mermaidAPI } from "mermaid";
function getDiagram(title, input, callback) {
mermaidAPI.render(title, input, diagram => {
callback({ diagram });
});
}
class Attina extends React.Component {
constructor(props) {
super(props);
this.state = {
diagram: "Loading..."
};
}
componentWillMount() {
getDiagram(this.props.title, this.props.diagram, state =>
this.setState(state)
);
}
componentWillReceiveProps({ diagram }) {
getDiagram(this.props.title, diagram, state => this.setState(state));
}
render() {
const { style = "", ...props } = this.props;
const template = `
<html>
<body>
<style>
body {
margin: 0;
padding: 0;
}
${style}
</style>
${this.state.diagram}
</body>
</html>
`;
return (
<iframe {...props} src={`data:text/html;charset=utf-8,${template}`} />
);
}
}
Attina.defaultProps = {
title: "diagram",
frameBorder: 0
};
export default Attina;