Skip to content

Commit 8a026ef

Browse files
committed
support other height units than 'px'
1 parent 9c5bf36 commit 8a026ef

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ while the documentation is not complete.
102102
- **minEditorHeight?: number**: The minimum height of the editor.
103103
- **maxEditorHeight?: number**: The max height of the editor (after that, it will scroll).
104104
- **minPreviewHeight?: number**: The minimum height of the preview.
105+
- **heightUnits?: string**: The height units, defaults to `px`.
105106
- **loadSuggestions?: (text: string, triggeredBy: string) => Promise<Suggestion[]>**: Function to load mention suggestions based on the
106107
given `text` and `triggeredBy` (character that triggered the suggestions). The result should be an array of `{preview: React.ReactNode, value: string}`.
107108
The `preview` is what is going to be displayed in the suggestions box. The `value` is what is going to be inserted in the `textarea` on click or enter.

src/components/Preview.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface PreviewProps {
77
refObject?: React.RefObject<HTMLDivElement>;
88
loadingPreview?: React.ReactNode;
99
minHeight: number;
10+
heightUnits: string;
1011
generateMarkdownPreview: GenerateMarkdownPreview;
1112
markdown: string;
1213
}
@@ -48,7 +49,7 @@ export class Preview extends React.Component<
4849
}
4950

5051
render() {
51-
const { classes, minHeight, loadingPreview, refObject } = this.props;
52+
const { classes, minHeight, loadingPreview, refObject, heightUnits } = this.props;
5253
const { preview, loading } = this.state;
5354
const finalHtml = loading ? loadingPreview : preview;
5455

@@ -66,10 +67,12 @@ export class Preview extends React.Component<
6667
content = <div className="mde-preview-content">{finalHtml}</div>;
6768
}
6869

70+
const minHeightVal = (minHeight && heightUnits) ? (minHeight + 10) + heightUnits : minHeight + 10;
71+
6972
return (
7073
<div
7174
className={classNames("mde-preview", classes, { loading })}
72-
style={{ minHeight: minHeight + 10 }}
75+
style={{ minHeight: minHeightVal }}
7376
data-testid="mde-preview"
7477
>
7578
{content}

src/components/ReactMde.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface ReactMdeProps {
3333
maxEditorHeight?: number;
3434
initialEditorHeight?: number;
3535
minPreviewHeight?: number;
36+
heightUnits?: string;
3637
classes?: Classes;
3738
refs?: Refs;
3839
toolbarCommands?: ToolbarCommands;
@@ -87,6 +88,7 @@ export class ReactMde extends React.Component<ReactMdeProps, ReactMdeState> {
8788
minEditorHeight: 200,
8889
maxEditorHeight: 500,
8990
minPreviewHeight: 200,
91+
heightUnits: "px",
9092
selectedTab: "write",
9193
disablePreview: false,
9294
suggestionTriggerCharacters: ["@"]
@@ -167,6 +169,7 @@ export class ReactMde extends React.Component<ReactMdeProps, ReactMdeState> {
167169
value,
168170
l18n,
169171
minPreviewHeight,
172+
heightUnits,
170173
childProps,
171174
selectedTab,
172175
generateMarkdownPreview,
@@ -224,6 +227,7 @@ export class ReactMde extends React.Component<ReactMdeProps, ReactMdeState> {
224227
textAreaComponent={textAreaComponent}
225228
textAreaProps={childProps && childProps.textArea}
226229
height={this.state.editorHeight}
230+
heightUnits={this.props.heightUnits}
227231
value={value}
228232
suggestionTriggerCharacters={suggestionTriggerCharacters}
229233
loadSuggestions={loadSuggestions}
@@ -250,6 +254,7 @@ export class ReactMde extends React.Component<ReactMdeProps, ReactMdeState> {
250254
refObject={this.finalRefs.preview}
251255
loadingPreview={loadingPreview}
252256
minHeight={minPreviewHeight}
257+
heightUnits={heightUnits}
253258
generateMarkdownPreview={generateMarkdownPreview}
254259
markdown={value}
255260
/>

src/components/TextArea.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface TextAreaProps {
4242
refObject?: React.RefObject<HTMLTextAreaElement>;
4343
readOnly?: boolean;
4444
height?: number;
45+
heightUnits?: string;
4546
suggestionTriggerCharacters?: string[];
4647
loadSuggestions?: (
4748
text: string,
@@ -363,6 +364,7 @@ export class TextArea extends React.Component<TextAreaProps, TextAreaState> {
363364
readOnly,
364365
textAreaProps,
365366
height,
367+
heightUnits,
366368
value,
367369
suggestionTriggerCharacters,
368370
loadSuggestions,
@@ -383,13 +385,15 @@ export class TextArea extends React.Component<TextAreaProps, TextAreaState> {
383385
"textarea") as DetailedHTMLFactory<
384386
TextareaHTMLAttributes<HTMLTextAreaElement>,
385387
HTMLTextAreaElement
386-
>;
388+
>;
389+
390+
const heightVal = (height && heightUnits) ? height + heightUnits : height;
387391

388392
return (
389393
<div className="mde-textarea-wrapper">
390394
<TextAreaComponent
391395
className={classNames("mde-text", classes)}
392-
style={{ height }}
396+
style={{ height: heightVal }}
393397
ref={this.props.refObject}
394398
readOnly={readOnly}
395399
value={value}

0 commit comments

Comments
 (0)