-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuseMonacoEditor.js
38 lines (34 loc) · 1.05 KB
/
useMonacoEditor.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
import { useCallback } from "react";
import * as monaco from "monaco-editor";
const useMonacoEditor = (dependencies) => {
/**
* Create editor
* @param {{element: HTMLElement, value: string, language: string, theme: string, options: object, disableMinimap: boolean}} props
* Props to be used to compose editor
* @returns Monaco Editor object
*/
const createEditor = useCallback(
(props) => {
const { element, value, language, theme, options, disableMinimap } =
props;
return monaco.editor.create(element, {
value: value,
language: language,
theme: theme,
"semanticHighlighting.enabled": true,
selectOnLineNumbers: true,
autoIndent: "full",
lineNumbers: disableMinimap ? "off" : "on",
overviewRulerBorder: !disableMinimap,
overviewRulerLanes: disableMinimap ? 0 : 3,
minimap: {
enabled: !disableMinimap,
},
...options,
});
},
[dependencies],
);
return { createEditor };
};
export default useMonacoEditor;