/
index.jsx
53 lines (49 loc) · 1.22 KB
/
index.jsx
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
import Editor from "nib-core";
import React, { useState, useEffect } from "react";
import NibConverter from "nib-converter";
import uploadCallback from "../../common/uploadCallback";
import "./styles.css";
/**
* @visibleName 15. Convert from HTML
*/
const ConvertFromHTMLDemo = () => {
const [html, setHTML] = useState();
const [updateEditor, setUpdateEditor] = useState();
const defaultValue = NibConverter.convertFromHTML(html);
useEffect(() => {
if (updateEditor) setUpdateEditor(false);
}, [updateEditor]);
return (
<div>
<textarea
placeholder="Enter HTML"
className="nib-html_textarea"
value={html}
onChange={evt => setHTML(evt.target.value)}
/>
<button
className="docs_btn nib-html_btn"
type="button"
onClick={() => setUpdateEditor(true)}
>
Update Editor
</button>
{!updateEditor && (
<Editor
config={{
plugins: {
image: {
uploadCallback
}
},
toolbar: {
options: "top"
}
}}
defaultValue={defaultValue}
/>
)}
</div>
);
};
export default ConvertFromHTMLDemo;