Skip to content

Commit e8fea79

Browse files
committed
adding horizontal layout
1 parent 9204dad commit e8fea79

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

src/LayoutMap.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as React from "react";
2-
import {VerticalLayout, NoPreviewLayout} from "./components-layout";
2+
import {VerticalLayout, NoPreviewLayout, HorizontalLayout} from "./components-layout";
33

44
class LayoutMap {
55
vertical: typeof VerticalLayout = VerticalLayout;
66
noPreview: typeof NoPreviewLayout = NoPreviewLayout;
7+
horizontal: typeof HorizontalLayout = HorizontalLayout;
78
}
89

910
const layoutMap = new LayoutMap();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as React from "react";
2+
import {Command} from "../types";
3+
import {ReactMde} from "../ReactMde";
4+
import {MdePreview, MdeEditor, MdeToolbar} from "../components";
5+
import {LayoutProps} from "../types/LayoutProps";
6+
7+
export class HorizontalLayout extends React.Component<LayoutProps, {}> {
8+
9+
editorRef: MdeEditor;
10+
previewRef: MdePreview;
11+
12+
/**
13+
* Handler for the textArea value change
14+
* @memberOf ReactMde
15+
*/
16+
handleMdeStateChange = (value) => {
17+
const {onChange} = this.props;
18+
onChange(value);
19+
}
20+
21+
handleCommand = (command: Command) => {
22+
const { onCommand } = this.props;
23+
onCommand(command);
24+
}
25+
26+
/**
27+
* Renders react-mde
28+
* @returns
29+
* @memberOf ReactMde
30+
*/
31+
render() {
32+
33+
const { commands, mdeEditorState } = this.props;
34+
35+
return (
36+
<div className="react-mde-horizontal-layout">
37+
<MdeToolbar
38+
commands={commands}
39+
onCommand={this.handleCommand}
40+
/>
41+
<div className="react-mde-content">
42+
<MdeEditor
43+
editorRef={(c) => this.editorRef = c}
44+
onChange={this.handleMdeStateChange}
45+
editorState={mdeEditorState}
46+
/>
47+
<MdePreview
48+
previewRef={(c) => this.previewRef = c}
49+
html={mdeEditorState ? mdeEditorState.html : ""}
50+
/>
51+
</div>
52+
</div>
53+
);
54+
}
55+
}

src/components-layout/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./VerticalLayout";
22
export * from "./NoPreviewLayout";
3+
export * from "./HorizontalLayout";

src/styles/react-mde-all.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
@import "react-mde";
66
@import "react-mde-vertical-layout";
77
@import "react-mde-no-preview-layout";
8+
@import "react-mde-horizontal-layout";
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@import "variables";
2+
3+
.react-mde-horizontal-layout {
4+
height: 100%;
5+
display: flex;
6+
flex-direction: column;
7+
8+
.mde-header {
9+
border-bottom: 1px solid $mde-border-color;
10+
}
11+
12+
.react-mde-content {
13+
display: flex;
14+
height: 100%;
15+
16+
.mde-text {
17+
width: 50%;
18+
overflow-y: auto;
19+
border-radius: 0px;
20+
}
21+
22+
.mde-preview {
23+
width: 50%;
24+
padding: 10px;
25+
border-left: 1px solid $mde-border-color;
26+
overflow-y: auto;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)