Skip to content

Commit

Permalink
Dynamic height calculations
Browse files Browse the repository at this point in the history
Signed-off-by: Neha Gokhale <[email protected]>
  • Loading branch information
nmgokhale committed Jan 18, 2024
1 parent bfa00c9 commit ec1941a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { keymap, placeholder } from "@codemirror/view";
import { defaultKeymap, indentWithTab } from "@codemirror/commands";
import { basicSetup, EditorView } from "codemirror";
import { autocompletion } from "@codemirror/autocomplete";
import { EditorState } from "@codemirror/state";

Check failure on line 42 in canvas_modules/common-canvas/src/common-properties/controls/expression/expression.jsx

View workflow job for this annotation

GitHub Actions / build

'EditorState' is defined but never used
import { javascript } from "@codemirror/lang-javascript";
import { python } from "@codemirror/lang-python";
import { sql } from "@codemirror/lang-sql";
Expand Down Expand Up @@ -79,7 +80,8 @@ class ExpressionControl extends React.Component {
super(props);
this.state = {
showExpressionBuilder: false,
validationInProgress: false
validationInProgress: false,
expressionEditorHeight: 0
};

this.editorRef = React.createRef();
Expand Down Expand Up @@ -157,7 +159,17 @@ class ExpressionControl extends React.Component {
console.log(viewUpdate.state.doc.toString());

Check warning on line 159 in canvas_modules/common-canvas/src/common-properties/controls/expression/expression.jsx

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
});

// TODO: Add height calculations from editorDidMount()
// set the default height, should be between 4 and 20 lines
const controlWidth = (this.expressionEditorDiv) ? this.expressionEditorDiv.clientWidth : 0;
const charPerLine = (controlWidth > 0) ? controlWidth / pxPerChar : defaultCharPerLine;
// charlimit in the control sets the height within a min and max
let height = (this.props.control.charLimit)
? Math.min((this.props.control.charLimit / charPerLine) * pxPerLine, maxLineHeight) : minLineHeight;
// let an explicit prop override the calculated height
height = this.props.control.rows ? pxPerLine * this.props.control.rows : height;
height = this.props.height ? this.props.height : height;
this.setState({ expressionEditorHeight: Math.max(Math.floor(height), minLineHeight) });

// TODO: Rename this.view to this.editor


Expand Down Expand Up @@ -458,7 +470,7 @@ class ExpressionControl extends React.Component {
<div ref={ (ref) => (this.expressionEditorDiv = ref) } data-id={ControlUtils.getDataId(this.props.propertyId)}
className={className}
>
<div ref={this.editorRef} />
<div ref={this.editorRef} style={{ height: this.state.expressionEditorHeight }} />
<ValidationMessage state={this.props.state} messageInfo={messageInfo} inTable={this.props.tableControl} />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

.cm-editor {
height: 104px;
height: inherit;
overflow: auto;
width: 100%;
background: $field-02;
Expand Down

0 comments on commit ec1941a

Please sign in to comment.