Skip to content

Commit 2f06af0

Browse files
committed
fix(CodeEditor): Set default height
The docs state that the default height is 100%. However, the examples just break if you don't pass in a height. This should help.
1 parent a382cd6 commit 2f06af0

File tree

9 files changed

+62
-19
lines changed

9 files changed

+62
-19
lines changed

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

Lines changed: 15 additions & 5 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. If `height` prop is set to 100%, this will also become enabled. */
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. */
@@ -250,7 +252,6 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
250252
onEditorDidMount: () => {},
251253
language: Language.plaintext,
252254
isDarkTheme: false,
253-
height: '',
254255
width: '',
255256
isLineNumbersVisible: true,
256257
isReadOnly: false,
@@ -522,6 +523,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
522523
},
523524
...optionsProp
524525
};
526+
const isFullHeight = this.props.height === '100%' ? true : this.props.isFullHeight;
525527

526528
return (
527529
<Dropzone multiple={false} onDropAccepted={this.onDropAccepted} onDropRejected={this.onDropRejected}>
@@ -644,7 +646,7 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
644646
const editor = (
645647
<div className={css(styles.codeEditorCode)} ref={this.wrapperRef} tabIndex={0} dir="ltr">
646648
<Editor
647-
height={height}
649+
height={height === '100%' ? undefined : height}
648650
width={width}
649651
language={language}
650652
value={value}
@@ -660,13 +662,21 @@ class CodeEditor extends React.Component<CodeEditorProps, CodeEditorState> {
660662
);
661663

662664
return (
663-
<div className={css(styles.codeEditor, isReadOnly && styles.modifiers.readOnly, className)} ref={this.ref}>
665+
<div
666+
className={css(
667+
styles.codeEditor,
668+
isReadOnly && styles.modifiers.readOnly,
669+
isFullHeight && styles.modifiers.fullHeight,
670+
className
671+
)}
672+
ref={this.ref}
673+
>
664674
{isUploadEnabled || providedEmptyState ? (
665675
<div
666676
{...getRootProps({
667677
onClick: (event) => event.stopPropagation() // Prevents clicking TextArea from opening file dialog
668678
})}
669-
className={css(isLoading && fileUploadStyles.modifiers.loading)}
679+
className={css(styles.codeEditorContainer, isLoading && fileUploadStyles.modifiers.loading)}
670680
>
671681
{editorHeader}
672682
<div className={css(styles.codeEditorMain, isDragActive && styles.modifiers.dragHover)}>

packages/react-code-editor/src/components/CodeEditor/examples/CodeEditor.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';
2424

2525
```
2626

27+
### With isFullHeight height, height will match the size of the parent
28+
29+
```ts file="CodeEditorFullHeight.tsx"
30+
31+
```
32+
2733
### With shortcut menu and main header content
2834

2935
These examples below are the shortcuts that we recommend describing in the popover since they are monaco features.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import { CodeEditor, Language } from '@patternfly/react-code-editor';
3+
4+
export const CodeEditorFullHeight: React.FunctionComponent = () => {
5+
const onEditorDidMount = (editor, monaco) => {
6+
editor.layout();
7+
editor.focus();
8+
monaco.editor.getModels()[0].updateOptions({ tabSize: 5 });
9+
};
10+
11+
const onChange = (value) => {
12+
// eslint-disable-next-line no-console
13+
console.log(value);
14+
};
15+
16+
return (
17+
<div style={{ height: '400px' }}>
18+
<CodeEditor
19+
code="Some example content"
20+
onChange={onChange}
21+
language={Language.javascript}
22+
onEditorDidMount={onEditorDidMount}
23+
isFullHeight
24+
/>
25+
</div>
26+
);
27+
};

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"tslib": "^2.7.0"
5555
},
5656
"devDependencies": {
57-
"@patternfly/patternfly": "6.0.0",
57+
"@patternfly/patternfly": "6.1.0-prerelease.2",
5858
"case-anything": "^2.1.13",
5959
"css": "^3.0.0",
6060
"fs-extra": "^11.2.0"

packages/react-docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:a11y": "patternfly-a11y --config patternfly-a11y.config"
2424
},
2525
"dependencies": {
26-
"@patternfly/patternfly": "6.0.0",
26+
"@patternfly/patternfly": "6.1.0-prerelease.2",
2727
"@patternfly/react-charts": "workspace:^",
2828
"@patternfly/react-code-editor": "workspace:^",
2929
"@patternfly/react-core": "workspace:^",

packages/react-icons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@fortawesome/free-brands-svg-icons": "^5.15.4",
3434
"@fortawesome/free-regular-svg-icons": "^5.15.4",
3535
"@fortawesome/free-solid-svg-icons": "^5.15.4",
36-
"@patternfly/patternfly": "6.0.0",
36+
"@patternfly/patternfly": "6.1.0-prerelease.2",
3737
"fs-extra": "^11.2.0",
3838
"tslib": "^2.7.0"
3939
},

packages/react-styles/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"clean": "rimraf dist css"
2020
},
2121
"devDependencies": {
22-
"@patternfly/patternfly": "6.0.0",
22+
"@patternfly/patternfly": "6.1.0-prerelease.2",
2323
"change-case": "^5.4.4",
2424
"fs-extra": "^11.2.0"
2525
},

packages/react-tokens/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"clean": "rimraf dist"
3030
},
3131
"devDependencies": {
32-
"@patternfly/patternfly": "6.0.0",
32+
"@patternfly/patternfly": "6.1.0-prerelease.2",
3333
"css": "^3.0.0",
3434
"fs-extra": "^11.2.0"
3535
}

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,10 +3160,10 @@ __metadata:
31603160
languageName: node
31613161
linkType: hard
31623162

3163-
"@patternfly/patternfly@npm:6.0.0":
3164-
version: 6.0.0
3165-
resolution: "@patternfly/patternfly@npm:6.0.0"
3166-
checksum: 10c0/b3bd98bc3a3831814773b67ac22090f7c3ac9f9e9963248ea6d1466a898cb571edb7750cc41e61160e833107e9b63ad1e40424904b1fbb1b837b81741a9d3454
3163+
"@patternfly/patternfly@npm:6.1.0-prerelease.2":
3164+
version: 6.1.0-prerelease.2
3165+
resolution: "@patternfly/patternfly@npm:6.1.0-prerelease.2"
3166+
checksum: 10c0/6d5e861bbdebd4ea578bf81f6e6c730cf76e24624541747c478ca7e0e76fdeb2d4c2cab4c44abd0c720a1b2aada5deff4e25fb6cb6fc56b118b33f29ff7cce3b
31673167
languageName: node
31683168
linkType: hard
31693169

@@ -3257,7 +3257,7 @@ __metadata:
32573257
version: 0.0.0-use.local
32583258
resolution: "@patternfly/react-core@workspace:packages/react-core"
32593259
dependencies:
3260-
"@patternfly/patternfly": "npm:6.0.0"
3260+
"@patternfly/patternfly": "npm:6.1.0-prerelease.2"
32613261
"@patternfly/react-icons": "workspace:^"
32623262
"@patternfly/react-styles": "workspace:^"
32633263
"@patternfly/react-tokens": "workspace:^"
@@ -3278,7 +3278,7 @@ __metadata:
32783278
resolution: "@patternfly/react-docs@workspace:packages/react-docs"
32793279
dependencies:
32803280
"@patternfly/documentation-framework": "npm:^6.0.0-alpha.106"
3281-
"@patternfly/patternfly": "npm:6.0.0"
3281+
"@patternfly/patternfly": "npm:6.1.0-prerelease.2"
32823282
"@patternfly/patternfly-a11y": "npm:5.0.0"
32833283
"@patternfly/react-charts": "workspace:^"
32843284
"@patternfly/react-code-editor": "workspace:^"
@@ -3317,7 +3317,7 @@ __metadata:
33173317
"@fortawesome/free-brands-svg-icons": "npm:^5.15.4"
33183318
"@fortawesome/free-regular-svg-icons": "npm:^5.15.4"
33193319
"@fortawesome/free-solid-svg-icons": "npm:^5.15.4"
3320-
"@patternfly/patternfly": "npm:6.0.0"
3320+
"@patternfly/patternfly": "npm:6.1.0-prerelease.2"
33213321
fs-extra: "npm:^11.2.0"
33223322
tslib: "npm:^2.7.0"
33233323
peerDependencies:
@@ -3400,7 +3400,7 @@ __metadata:
34003400
version: 0.0.0-use.local
34013401
resolution: "@patternfly/react-styles@workspace:packages/react-styles"
34023402
dependencies:
3403-
"@patternfly/patternfly": "npm:6.0.0"
3403+
"@patternfly/patternfly": "npm:6.1.0-prerelease.2"
34043404
change-case: "npm:^5.4.4"
34053405
fs-extra: "npm:^11.2.0"
34063406
languageName: unknown
@@ -3441,7 +3441,7 @@ __metadata:
34413441
version: 0.0.0-use.local
34423442
resolution: "@patternfly/react-tokens@workspace:packages/react-tokens"
34433443
dependencies:
3444-
"@patternfly/patternfly": "npm:6.0.0"
3444+
"@patternfly/patternfly": "npm:6.1.0-prerelease.2"
34453445
css: "npm:^3.0.0"
34463446
fs-extra: "npm:^11.2.0"
34473447
languageName: unknown

0 commit comments

Comments
 (0)