@@ -10,13 +10,20 @@ import 'ace-builds/src-noconflict/theme-sqlserver';
1010const noop = ( ) => { } ;
1111
1212export interface Props {
13+ autoHeight : boolean ;
1314 onChange ?: ( value : string ) => void ;
1415 readOnly : boolean ;
1516 value : string ;
1617 onSelectionChange : ( value : string ) => void ;
1718}
1819
19- function SqlEditor ( { onChange, readOnly, value, onSelectionChange } : Props ) {
20+ function SqlEditor ( {
21+ autoHeight,
22+ onChange,
23+ readOnly,
24+ value,
25+ onSelectionChange,
26+ } : Props ) {
2027 const { config } = useAppContext ( ) ;
2128 const [ dimensions , setDimensions ] = useState ( { width : - 1 , height : - 1 } ) ;
2229 const [ editor , setEditor ] = useState < any > ( null ) ;
@@ -57,46 +64,72 @@ function SqlEditor({ onChange, readOnly, value, onSelectionChange }: Props) {
5764 tabSize : 2 ,
5865 } ;
5966
67+ if ( autoHeight ) {
68+ return (
69+ < Measure
70+ bounds
71+ onResize = { ( contentRect : any ) => setDimensions ( contentRect . bounds ) }
72+ >
73+ { ( { measureRef } ) => (
74+ < div ref = { measureRef } className = "h-100 w-100" >
75+ < AceEditor
76+ editorProps = { { $blockScrolling : Infinity } }
77+ focus = { ! readOnly }
78+ height = { height + 'px' }
79+ fontSize = { 14 }
80+ highlightActiveLine = { false }
81+ mode = "sql"
82+ name = "query-ace-editor"
83+ onChange = { onChange || noop }
84+ onLoad = { ( editor ) => setEditor ( editor ) }
85+ onSelectionChange = { handleSelection }
86+ readOnly = { readOnly }
87+ setOptions = { setOptions }
88+ showGutter = { true }
89+ showPrintMargin = { false }
90+ theme = "sqlserver"
91+ value = { value }
92+ width = { width + 'px' }
93+ />
94+ </ div >
95+ ) }
96+ </ Measure >
97+ ) ;
98+ }
99+
60100 return (
61- < Measure
62- bounds
63- onResize = { ( contentRect : any ) => setDimensions ( contentRect . bounds ) }
64- >
65- { ( { measureRef } ) => (
66- < div ref = { measureRef } className = "h-100 w-100" >
67- < AceEditor
68- editorProps = { { $blockScrolling : Infinity } }
69- focus = { ! readOnly }
70- height = { height + 'px' }
71- fontSize = { 14 }
72- highlightActiveLine = { false }
73- mode = "sql"
74- name = "query-ace-editor"
75- onChange = { onChange || noop }
76- onLoad = { ( editor ) => setEditor ( editor ) }
77- onSelectionChange = { handleSelection }
78- readOnly = { readOnly }
79- setOptions = { setOptions }
80- showGutter = { true }
81- showPrintMargin = { false }
82- theme = "sqlserver"
83- value = { value }
84- width = { width + 'px' }
85- />
86- </ div >
87- ) }
88- </ Measure >
101+ < AceEditor
102+ editorProps = { { $blockScrolling : Infinity } }
103+ focus = { ! readOnly }
104+ fontSize = { 14 }
105+ highlightActiveLine = { false }
106+ mode = "sql"
107+ name = "query-ace-editor"
108+ onChange = { onChange || noop }
109+ onLoad = { ( editor ) => setEditor ( editor ) }
110+ onSelectionChange = { handleSelection }
111+ readOnly = { readOnly }
112+ setOptions = { setOptions }
113+ showGutter = { true }
114+ showPrintMargin = { false }
115+ theme = "sqlserver"
116+ value = { value }
117+ maxLines = { 12 }
118+ width = { '100%' }
119+ />
89120 ) ;
90121}
91122
92123SqlEditor . propTypes = {
124+ autoHeight : PropTypes . bool ,
93125 onChange : PropTypes . func ,
94126 onSelectionChange : PropTypes . func ,
95127 readOnly : PropTypes . bool ,
96128 value : PropTypes . string ,
97129} ;
98130
99131SqlEditor . defaultProps = {
132+ autoHeight : true ,
100133 onSelectionChange : ( ) => { } ,
101134 readOnly : false ,
102135 value : '' ,
0 commit comments