-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditor.js
71 lines (51 loc) · 1.8 KB
/
Editor.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
import React, {useState} from 'react'
import 'codemirror/lib/codemirror.css'
import 'codemirror/theme/material.css'
import 'codemirror/mode/clike/clike'
import 'codemirror/mode/xml/xml'
import 'codemirror/mode/css/css'
import 'codemirror/mode/javascript/javascript'
import {Controlled as ControlledEditor } from 'react-codemirror2'
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'
import {faCompressAlt, faExpandAlt} from '@fortawesome/free-solid-svg-icons'
function Editor(props) {
const {
language,
displayName,
value,
onChange
} = props;
const [open, setOpen] = useState(true)
function handleChange(editor, data, value){
onChange(value)
}
return (
<div className={`editor-container ${open ? '' : 'collapsed'} `}>
<div className="editor-title">
{displayName}
<button
type="button"
className="expand-collapse-button"
onClick = {()=> setOpen(preOpen => !preOpen)}
>
<FontAwesomeIcon
icon={open ? faCompressAlt : faExpandAlt}
/>
</button>
</div>
<ControlledEditor
onBeforeChange={handleChange}
value={value}
className="code-mirror-wrapper"
options={{
line: true,
lint: true,
mode: language,
theme: 'material',
lineNumbers: true
}}
/>
</div>
)
}
export default Editor