Skip to content

Commit 4b7c712

Browse files
committed
Switch to modifier classes
1 parent 1572e85 commit 4b7c712

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ export interface CodeEditorProps extends Omit<React.HTMLProps<HTMLDivElement>, '
149149
emptyStateTitle?: React.ReactNode;
150150
/** Editor header main content title. */
151151
headerMainContent?: string;
152-
/** Height of code editor. Defaults to 100%. 'sizeToFit' will automatically change the height
152+
/** Height of code editor. 'sizeToFit' will automatically change the height
153153
* to the height of the content.
154154
*/
155155
height?: string | 'sizeToFit';
156156
/** Flag to add copy button to code editor actions. */
157157
isCopyEnabled?: boolean;
158158
/** Flag indicating the editor is styled using monaco's dark theme. */
159159
isDarkTheme?: boolean;
160+
/** Flag that enables component to consume the available height of its container */
161+
isFullHeight?: boolean;
160162
/** Flag indicating the editor has a plain header. */
161163
isHeaderPlain?: boolean;
162164
/** Flag to add download button to code editor actions. */
@@ -520,6 +522,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
520522
},
521523
...optionsProp
522524
};
525+
const isFullHeight = this.props.height === '100%' ? true : this.props.isFullHeight;
523526

524527
return (
525528
<Dropzone multiple={false} onDropAccepted={this.onDropAccepted} onDropRejected={this.onDropRejected}>
@@ -641,14 +644,13 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
641644

642645
const editor = (
643646
<div
644-
className={css(styles.codeEditorCode)}
645-
style={{ height: '100%' }}
647+
className={css(styles.codeEditorCode, isFullHeight && styles.modifiers.fullHeight)}
646648
ref={this.wrapperRef}
647649
tabIndex={0}
648650
dir="ltr"
649651
>
650652
<Editor
651-
height={height}
653+
height={height === '100%' ? undefined : height}
652654
width={width}
653655
language={language}
654656
value={value}
@@ -664,8 +666,12 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
664666

665667
return (
666668
<div
667-
className={css(styles.codeEditor, isReadOnly && styles.modifiers.readOnly, className)}
668-
style={{ height: '100%', display: 'flex', flexDirection: 'column' }}
669+
className={css(
670+
styles.codeEditor,
671+
isReadOnly && styles.modifiers.readOnly,
672+
isFullHeight && styles.modifiers.fullHeight,
673+
className
674+
)}
669675
ref={this.ref}
670676
>
671677
{isUploadEnabled || providedEmptyState ? (
@@ -677,8 +683,11 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
677683
>
678684
{editorHeader}
679685
<div
680-
className={css(styles.codeEditorMain, isDragActive && styles.modifiers.dragHover)}
681-
style={{ flexGrow: 1 }}
686+
className={css(
687+
styles.codeEditorMain,
688+
isDragActive && styles.modifiers.dragHover,
689+
isFullHeight && styles.modifiers.fullHeight
690+
)}
682691
>
683692
<div className={css(styles.codeEditorUpload)}>
684693
<input {...getInputProps()} /* hidden, necessary for react-dropzone */ />
@@ -690,7 +699,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
690699
<>
691700
{editorHeader}
692701
{showEditor && (
693-
<div className={css(styles.codeEditorMain)} style={{ flexGrow: 1 }}>
702+
<div className={css(styles.codeEditorMain, isFullHeight && styles.modifiers.fullHeight)}>
694703
{editor}
695704
</div>
696705
)}

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const CodeEditorFullHeight: React.FunctionComponent = () => {
4141
onChange={onChange}
4242
language={Language.javascript}
4343
onEditorDidMount={onEditorDidMount}
44+
isFullHeight
4445
/>
4546
</ModalBody>
4647
<ModalFooter>

0 commit comments

Comments
 (0)