Skip to content

Commit 3b1999f

Browse files
authored
Merge pull request nubasedev#97 from Nes-si/to_pr
Adding horizontal layout
2 parents ff8bc78 + 792371c commit 3b1999f

15 files changed

+146
-25
lines changed

demo/client.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "../node_modules/normalize.css/normalize.css";
77
import "../node_modules/draft-js/dist/Draft.css";
88
import "../src/styles/react-mde-all.scss";
99
import "./styles/demo.scss";
10+
import "./styles/variables.scss";
1011

1112
render(
1213
<App />,

demo/styles/demo.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
@import 'variables.scss';
22

3+
* {
4+
box-sizing: border-box;
5+
}
6+
37
body {
48
font-size: 14px;
59
font-family: sans-serif;
610
}
711

812
.container {
9-
max-width: 600px;
10-
@media screen and (min-width: 768px) {
11-
margin: 50px auto;
12-
}
13+
width: 100%;
14+
height: 600px;
15+
padding: 10px;
1316
}

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/VerticalLayout.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ export class VerticalLayout extends React.Component<LayoutProps, {}> {
3333
const { commands, mdeEditorState } = this.props;
3434

3535
return (
36-
<div className="vertical-layout">
36+
<div className="react-mde-vertical-layout">
3737
<MdeToolbar
3838
commands={commands}
3939
onCommand={this.handleCommand}
4040
/>
41-
<MdeEditor
42-
editorRef={(c) => this.editorRef = c}
43-
onChange={this.handleMdeStateChange}
44-
editorState={mdeEditorState}
45-
/>
46-
<MdePreview
47-
previewRef={(c) => this.previewRef = c}
48-
html={mdeEditorState ? mdeEditorState.html : ""}
49-
/>
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>
5052
</div>
5153
);
5254
}

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
@import "react-mde-editor";
44
@import "react-mde-preview";
55
@import "react-mde";
6+
@import "react-mde-vertical-layout";
67
@import "react-mde-no-preview-layout";
8+
@import "react-mde-horizontal-layout";

src/styles/react-mde-editor.scss

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
@import "variables";
22

33
.mde-text {
4-
border-width: 1px 0 1px 0;
5-
border-style: solid;
6-
border-color: $mde-border-color;
4+
75
.public-DraftEditor-content {
8-
box-sizing: border-box;
96
width: 100%;
107
min-height: $mde-editor-min-height;
11-
max-height: $mde-editor-max-height;
128
padding: $mde-editor-padding;
13-
overflow-y: scroll;
149
}
1510
}
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+
}

src/styles/react-mde-no-preview-layout-all.scss

Whitespace-only changes.

0 commit comments

Comments
 (0)