-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
51 lines (42 loc) · 1.5 KB
/
App.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
import React, { useState } from "react";
import './App.css';
import { convertToSvg } from "./services/svg";
function App() {
const [text, updateText] = useState(`What they see
- What they do
-> What they see next
- What they do next
`);
const [svg, updateSvg] = useState("");
const [svgWidth, updateSvgWidth] = useState(100);
const [svgBlob, updateSvgBlob] = useState("");
function convertSvg(text: string){
updateText(text);
const result = convertToSvg(text);
updateSvg(result.svg)
updateSvgWidth(result.box.right);
var data = new Blob([result.svg], {type: 'image/svg+xml'});
var url = window.URL.createObjectURL(data);
updateSvgBlob(url);
}
return (
<div className="App">
<div className="logo">
<h1>not-uml</h1>
<p>A shorthand for designing UI flows</p>
</div>
<textarea value={text} onChange={(e) => convertSvg(e.target.value)}></textarea>
<div id="instructions">
<h4>How to</h4>
<p><b>Views</b> start with "<code>-></code>"</p>
<p><b>Actions</b> start with "<code>-</code>"</p>
<p>Indent actions under the parent view. Indent views under actions when taking the action will lead to the view.</p>
</div>
<div className="chart-container">
<div style={{width: svgWidth + "px"}} dangerouslySetInnerHTML={{ __html: svg }} />
</div>
<a title="Download SVG" id="download-button" download="chart.svg" href={svgBlob}><span>Download</span></a>
</div>
);
}
export default App;