1
1
import React , { FC } from 'react' ;
2
2
3
- import { EuiCodeBlock } from '@elastic/eui' ;
3
+ import Editor , { Monaco } from "@monaco-editor/react" ;
4
+ import { editor } from "monaco-editor" ;
4
5
5
6
import { useWithOrchestratorTheme } from '@/hooks' ;
7
+ import { useOrchestratorTheme } from '@/hooks' ;
6
8
7
9
import { getStyles } from './styles' ;
8
10
@@ -21,19 +23,39 @@ export const WfoJsonCodeBlock: FC<WfoJsonCodeBlockProps> = ({
21
23
data,
22
24
isBasicStyle = false ,
23
25
} ) => {
26
+ const { isDarkThemeActive } = useOrchestratorTheme ( ) ;
24
27
const { euiCodeBlockStyle, euiBasicCodeBlockStyle } =
25
28
useWithOrchestratorTheme ( getStyles ) ;
26
29
27
30
const json = JSON . stringify ( data , null , 4 ) ;
28
31
32
+ const [ editorHeight , setEditorHeight ] = React . useState ( 0 ) ;
33
+
34
+ function editorDidMount (
35
+ editor : editor . IStandaloneCodeEditor ,
36
+ monaco : Monaco
37
+ ) {
38
+ const scrollHeight = editor . getScrollHeight ( ) ;
39
+ setEditorHeight ( Math . min ( scrollHeight , 500 ) ) ;
40
+ }
41
+
29
42
return (
30
- < EuiCodeBlock
43
+ < Editor
44
+ height = { editorHeight }
31
45
css = { isBasicStyle ? euiBasicCodeBlockStyle : euiCodeBlockStyle }
32
- isCopyable = { true }
46
+ theme = { isDarkThemeActive ? "vs-dark" : "light" }
47
+ options = { {
48
+ readOnly : true ,
49
+ lineNumbers : isBasicStyle ? "off" : "on" ,
50
+ scrollBeyondLastLine : false ,
51
+ contextmenu : false ,
52
+ minimap : { enabled : false } ,
53
+ mouseWheelZoom : true ,
54
+ mouseStyle : "copy" ,
55
+ } }
56
+ onMount = { editorDidMount }
33
57
language = "json"
34
- lineNumbers = { ! isBasicStyle }
35
- >
36
- { json }
37
- </ EuiCodeBlock >
58
+ value = { json }
59
+ />
38
60
) ;
39
61
} ;
0 commit comments