14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- import React from "react" ;
18
- import Grid from "@mui/material/Grid" ;
19
- import { Box , InputLabel , Tooltip } from "@mui/material" ;
20
- import { Theme } from "@mui/material/styles" ;
21
- import createStyles from "@mui/styles/createStyles" ;
22
- import withStyles from "@mui/styles/withStyles" ;
23
- import { Button , CopyIcon , HelpIcon } from "mds" ;
24
- import { fieldBasic } from "../common/styleLibrary" ;
17
+ import React , { Fragment } from "react" ;
18
+ import { Button , CodeEditor , CopyIcon } from "mds" ;
25
19
import CopyToClipboard from "react-copy-to-clipboard" ;
26
- import CodeEditor from "@uiw/react-textarea-code-editor" ;
27
20
import TooltipWrapper from "../../TooltipWrapper/TooltipWrapper" ;
28
21
29
22
interface ICodeWrapper {
30
23
value : string ;
31
24
label ?: string ;
32
25
mode ?: string ;
33
26
tooltip ?: string ;
34
- classes : any ;
35
- onChange ?: ( editor : any , data : any , value : string ) => any ;
36
- onBeforeChange : ( editor : any , data : any , value : string ) => any ;
37
- readOnly ?: boolean ;
38
- editorHeight ?: string ;
27
+ onChange : ( value : string ) => any ;
28
+ editorHeight ?: string | number ;
39
29
}
40
30
41
- const styles = ( theme : Theme ) =>
42
- createStyles ( {
43
- ...fieldBasic ,
44
- } ) ;
45
-
46
31
const CodeMirrorWrapper = ( {
47
32
value,
48
33
label = "" ,
49
34
tooltip = "" ,
50
35
mode = "json" ,
51
- classes,
52
- onBeforeChange,
53
- readOnly = false ,
54
- editorHeight = "250px" ,
36
+ onChange,
37
+ editorHeight = 250 ,
55
38
} : ICodeWrapper ) => {
56
39
return (
57
- < React . Fragment >
58
- < Grid item xs = { 12 } sx = { { marginBottom : "10px" } } >
59
- < InputLabel className = { classes . inputLabel } >
60
- < span > { label } </ span >
61
- { tooltip !== "" && (
62
- < div className = { classes . tooltipContainer } >
63
- < Tooltip title = { tooltip } placement = "top-start" >
64
- < div className = { classes . tooltip } >
65
- < HelpIcon />
66
- </ div >
67
- </ Tooltip >
68
- </ div >
69
- ) }
70
- </ InputLabel >
71
- </ Grid >
72
-
73
- < Grid
74
- item
75
- xs = { 12 }
76
- style = { {
77
- maxHeight : editorHeight ,
78
- overflow : "auto" ,
79
- border : "1px solid #eaeaea" ,
80
- } }
81
- >
82
- < CodeEditor
83
- value = { value }
84
- language = { mode }
85
- onChange = { ( evn ) => {
86
- onBeforeChange ( null , null , evn . target . value ) ;
87
- } }
88
- id = { "code_wrapper" }
89
- padding = { 15 }
90
- style = { {
91
- fontSize : 12 ,
92
- backgroundColor : "#fefefe" ,
93
- fontFamily :
94
- "ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace" ,
95
- minHeight : editorHeight || "initial" ,
96
- color : "#000000" ,
97
- } }
98
- />
99
- </ Grid >
100
- < Grid
101
- item
102
- xs = { 12 }
103
- sx = { {
104
- background : "#f7f7f7" ,
105
- border : "1px solid #eaeaea" ,
106
- borderTop : 0 ,
107
- } }
108
- >
109
- < Box
110
- sx = { {
111
- display : "flex" ,
112
- alignItems : "center" ,
113
- padding : "2px" ,
114
- paddingRight : "5px" ,
115
- justifyContent : "flex-end" ,
116
- "& button" : {
117
- height : "26px" ,
118
- width : "26px" ,
119
- padding : "2px" ,
120
- " .min-icon" : {
121
- marginLeft : "0" ,
122
- } ,
123
- } ,
124
- } }
125
- >
40
+ < CodeEditor
41
+ value = { value }
42
+ onChange = { ( value ) => onChange ( value ) }
43
+ mode = { mode }
44
+ tooltip = { tooltip }
45
+ editorHeight = { editorHeight }
46
+ label = { label }
47
+ helpTools = {
48
+ < Fragment >
126
49
< TooltipWrapper tooltip = { "Copy to Clipboard" } >
127
50
< CopyToClipboard text = { value } >
128
51
< Button
@@ -134,10 +57,10 @@ const CodeMirrorWrapper = ({
134
57
/>
135
58
</ CopyToClipboard >
136
59
</ TooltipWrapper >
137
- </ Box >
138
- </ Grid >
139
- </ React . Fragment >
60
+ </ Fragment >
61
+ }
62
+ / >
140
63
) ;
141
64
} ;
142
65
143
- export default withStyles ( styles ) ( CodeMirrorWrapper ) ;
66
+ export default CodeMirrorWrapper ;
0 commit comments