diff --git a/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx b/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx index ac7fc3f5d4b..c9a0b444c5c 100644 --- a/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx +++ b/packages/react-code-editor/src/components/CodeEditor/CodeEditor.tsx @@ -149,7 +149,7 @@ export interface CodeEditorProps extends Omit, ' emptyStateTitle?: React.ReactNode; /** Editor header main content title. */ headerMainContent?: string; - /** Height of code editor. Defaults to 100%. 'sizeToFit' will automatically change the height + /** Height of code editor. 'sizeToFit' will automatically change the height * to the height of the content. */ height?: string | 'sizeToFit'; @@ -157,6 +157,8 @@ export interface CodeEditorProps extends Omit, ' isCopyEnabled?: boolean; /** Flag indicating the editor is styled using monaco's dark theme. */ isDarkTheme?: boolean; + /** Flag that enables component to consume the available height of its container */ + isFullHeight?: boolean; /** Flag indicating the editor has a plain header. */ isHeaderPlain?: boolean; /** Flag to add download button to code editor actions. */ @@ -250,7 +252,6 @@ class CodeEditor extends React.Component { onEditorDidMount: () => {}, language: Language.plaintext, isDarkTheme: false, - height: '', width: '', isLineNumbersVisible: true, isReadOnly: false, @@ -521,6 +522,7 @@ class CodeEditor extends React.Component { }, ...optionsProp }; + const isFullHeight = this.props.height === '100%' ? true : this.props.isFullHeight; return ( @@ -641,9 +643,15 @@ class CodeEditor extends React.Component { ); const editor = ( -
+
{ ); return ( -
+
{isUploadEnabled || providedEmptyState ? (
event.stopPropagation() // Prevents clicking TextArea from opening file dialog })} className={css(isLoading && fileUploadStyles.modifiers.loading)} + style={{ display: 'flex', flexDirection: 'column', flexGrow: '1' }} > {editorHeader} -
+
{(showEmptyState || providedEmptyState) && !value ? emptyState : editor} @@ -677,7 +697,11 @@ class CodeEditor extends React.Component { ) : ( <> {editorHeader} - {showEditor &&
{editor}
} + {showEditor && ( +
+ {editor} +
+ )} )}
diff --git a/packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md b/packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md index 62c95d96cd1..a02f7d36e76 100644 --- a/packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md +++ b/packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md @@ -43,3 +43,9 @@ These examples below are the shortcuts that we recommend describing in the popov ```ts file="CodeEditorCustomControl.tsx" ``` + +### With 100% height + +```ts file="CodeEditorModal.tsx" + +``` diff --git a/packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorModal.tsx b/packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorModal.tsx new file mode 100644 index 00000000000..f048c4eed1a --- /dev/null +++ b/packages/react-code-editor/src/components/CodeEditor/examples/CodeEditorModal.tsx @@ -0,0 +1,58 @@ +import React from 'react'; +import { CodeEditor, Language } from '@patternfly/react-code-editor'; +import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from '@patternfly/react-core'; + +export const CodeEditorFullHeight: React.FunctionComponent = () => { + const [isModalOpen, setIsModalOpen] = React.useState(false); + + const onEditorDidMount = (editor, monaco) => { + editor.layout(); + editor.focus(); + monaco.editor.getModels()[0].updateOptions({ tabSize: 5 }); + }; + + const handleModalToggle = (_event: KeyboardEvent | React.MouseEvent) => { + setIsModalOpen(!isModalOpen); + }; + + const onChange = (value) => { + // eslint-disable-next-line no-console + console.log(value); + }; + + return ( + + + + + + + + + + + + + + ); +};