@@ -3,8 +3,13 @@ import {Command} from "../types";
33import { ReactMde } from "../ReactMde" ;
44import { MdePreview , MdeEditor , MdeToolbar } from "../components" ;
55import { LayoutProps } from "../types/LayoutProps" ;
6+ import { TAB_CODE , TAB_PREVIEW } from "./TabbedLayout" ;
67
78export class HorizontalLayout extends React . Component < LayoutProps , { } > {
9+ state = {
10+ showCode : true ,
11+ showPreview : true ,
12+ } ;
813
914 editorRef : MdeEditor ;
1015 previewRef : MdePreview ;
@@ -23,31 +28,70 @@ export class HorizontalLayout extends React.Component<LayoutProps, {}> {
2328 onCommand ( command ) ;
2429 }
2530
31+ handleShowCode = ( ) => {
32+ if ( ! this . state . showCode || this . state . showPreview )
33+ this . setState ( { showCode : ! this . state . showCode } ) ;
34+ } ;
35+
36+ handleShowPreview = ( ) => {
37+ if ( ! this . state . showPreview || this . state . showCode )
38+ this . setState ( { showPreview : ! this . state . showPreview } ) ;
39+ } ;
40+
2641 /**
2742 * Renders react-mde
2843 * @returns
2944 * @memberOf ReactMde
3045 */
3146 render ( ) {
32-
3347 const { commands, mdeEditorState } = this . props ;
3448
49+ let styleTabCode = "mde-tab" ;
50+ let styleTabPreview = "mde-tab" ;
51+ let stylePreview = null ;
52+ if ( this . state . showCode )
53+ styleTabCode += " mde-tab-activated" ;
54+ else
55+ stylePreview = "mde-preview-only" ;
56+ if ( this . state . showPreview )
57+ styleTabPreview += " mde-tab-activated" ;
58+
3559 return (
3660 < div className = "react-mde-horizontal-layout" >
3761 < MdeToolbar
3862 commands = { commands }
3963 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- />
64+ >
65+ < div className = "mde-tabs" >
66+ < button
67+ className = { styleTabCode }
68+ onClick = { this . handleShowCode }
69+ >
70+ Code
71+ </ button >
72+ < button
73+ className = { styleTabPreview }
74+ onClick = { this . handleShowPreview }
75+ >
76+ Preview
77+ </ button >
78+ </ div >
79+ </ MdeToolbar >
80+ < div className = "mde-content" >
81+ { this . state . showCode &&
82+ < MdeEditor
83+ editorRef = { ( c ) => this . editorRef = c }
84+ onChange = { this . handleMdeStateChange }
85+ editorState = { mdeEditorState }
86+ />
87+ }
88+ { this . state . showPreview &&
89+ < MdePreview
90+ className = { stylePreview }
91+ previewRef = { ( c ) => this . previewRef = c }
92+ html = { mdeEditorState ? mdeEditorState . html : "" }
93+ />
94+ }
5195 </ div >
5296 </ div >
5397 ) ;
0 commit comments