Skip to content

Commit 5a933bc

Browse files
committed
adding tabbed layout
1 parent 792371c commit 5a933bc

File tree

6 files changed

+95
-1
lines changed

6 files changed

+95
-1
lines changed

src/LayoutMap.tsx

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

44
class LayoutMap {
55
vertical: typeof VerticalLayout = VerticalLayout;
66
noPreview: typeof NoPreviewLayout = NoPreviewLayout;
77
horizontal: typeof HorizontalLayout = HorizontalLayout;
8+
tabbed: typeof TabbedLayout = TabbedLayout;
89
}
910

1011
const layoutMap = new LayoutMap();
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
8+
export const TAB_CODE: string = "TAB_CODE";
9+
export const TAB_PREVIEW: string = "TAB_PREVIEW";
10+
11+
export class TabbedLayout extends React.Component<LayoutProps, {}> {
12+
state = {
13+
tab: TAB_CODE,
14+
};
15+
16+
editorRef: MdeEditor;
17+
previewRef: MdePreview;
18+
19+
20+
21+
/**
22+
* Handler for the textArea value change
23+
* @memberOf ReactMde
24+
*/
25+
handleMdeStateChange = (value) => {
26+
const {onChange} = this.props;
27+
onChange(value);
28+
}
29+
30+
handleCommand = (command: Command) => {
31+
const { onCommand } = this.props;
32+
onCommand(command);
33+
}
34+
35+
/**
36+
* Renders react-mde
37+
* @returns
38+
* @memberOf ReactMde
39+
*/
40+
render() {
41+
42+
const { commands, mdeEditorState } = this.props;
43+
44+
return (
45+
<div className="react-mde-tabbed-layout">
46+
<div>
47+
<button onClick={() => this.setState({tab: TAB_CODE})}>Code</button>
48+
<button onClick={() => this.setState({tab: TAB_PREVIEW})}>Preview</button>
49+
</div>
50+
<MdeToolbar
51+
className="react-mde-toolbar"
52+
commands={commands}
53+
onCommand={this.handleCommand}
54+
/>
55+
{
56+
this.state.tab === TAB_CODE ?
57+
<MdeEditor
58+
editorRef={(c) => this.editorRef = c}
59+
onChange={this.handleMdeStateChange}
60+
editorState={mdeEditorState}
61+
/>
62+
:
63+
< MdePreview
64+
previewRef={(c) => this.previewRef = c}
65+
html={mdeEditorState ? mdeEditorState.html : ""}
66+
/>
67+
}
68+
</div>
69+
);
70+
}
71+
}

src/components-layout/index.tsx

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

src/styles/react-mde-all.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
@import "react-mde-vertical-layout";
77
@import "react-mde-no-preview-layout";
88
@import "react-mde-horizontal-layout";
9+
@import "react-mde-tabbed-layout";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@import "variables";
2+
3+
.react-mde-tabbed-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+
.mde-text {
13+
overflow-y: auto;
14+
}
15+
16+
.mde-preview {
17+
overflow-y: auto;
18+
}
19+
}

src/styles/react-mde-toolbar.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
outline: 0;
66
}
77
padding: $mde-toolbar-padding;
8+
background: #f9f9f9;
89
ul.mde-header-group {
910
display: inline-block;
1011
margin: 0 1rem 0 0;

0 commit comments

Comments
 (0)