Skip to content

Commit 2745666

Browse files
authored
Merge pull request nubasedev#98 from Nes-si/to_pr
Adding Tabbed layout
2 parents 3b1999f + 57b6c82 commit 2745666

File tree

7 files changed

+95
-1
lines changed

7 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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
commands={commands}
52+
onCommand={this.handleCommand}
53+
/>
54+
{
55+
this.state.tab === TAB_CODE ?
56+
<MdeEditor
57+
editorRef={(c) => this.editorRef = c}
58+
onChange={this.handleMdeStateChange}
59+
editorState={mdeEditorState}
60+
/>
61+
:
62+
< MdePreview
63+
previewRef={(c) => this.previewRef = c}
64+
html={mdeEditorState ? mdeEditorState.html : ""}
65+
/>
66+
}
67+
</div>
68+
);
69+
}
70+
}

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: $mde-toolbar-color;
89
ul.mde-header-group {
910
display: inline-block;
1011
margin: 0 1rem 0 0;

src/styles/variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
$mde-border-radius: 2px !default;
22
$mde-border-color: #c8ccd0 !default;
33
$mde-button-color: #242729 !default;
4+
$mde-toolbar-color: #f9f9f9 !default;
45
$mde-toolbar-padding: 10px !default;
56
$mde-editor-min-height: 200px !default;
67
$mde-editor-padding: 10px !default;

0 commit comments

Comments
 (0)