@@ -5,6 +5,7 @@ import { IProps } from './common/props';
55import CodeMirror , { ICodeMirror } from './components/CodeMirror' ;
66import PreviewMarkdown from './components/PreviewMarkdown' ;
77import ToolBar from './components/ToolBar' ;
8+ import ToolBarMode from './components/ToolBarMode' ;
89import './index.less' ;
910
1011export interface IMarkdownEditor extends IProps , ICodeMirror {
@@ -13,11 +14,12 @@ export interface IMarkdownEditor extends IProps, ICodeMirror {
1314 height ?: number ,
1415 visble ?: boolean ,
1516 toolbars ?: string [ ] ,
17+ toolbarsMode ?: string [ ] ,
1618 options ?: CodeMirror . EditorConfiguration ,
1719}
1820
1921interface IMarkdownEditorState {
20- preview : boolean ;
22+ fullscreen : boolean ;
2123}
2224
2325export default class MarkdownEditor extends React . PureComponent < IMarkdownEditor , IMarkdownEditorState , { } > {
@@ -29,11 +31,13 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
2931 visble : true ,
3032 } ;
3133 public preview ! : PreviewMarkdown ;
34+ public toolbarsMode ! : ToolBarMode ;
3235 public CodeMirror ! : CodeMirror ;
3336 public render ( ) {
34- const { prefixCls, className, toolbars, onChange, visble, ...codemirrorProps } = this . props ;
37+ const { prefixCls, className, toolbars, toolbarsMode , onChange, visble, ...codemirrorProps } = this . props ;
3538 return (
3639 < div className = { classnames ( prefixCls , className ) } >
40+ < ToolBarMode ref = { ( mode : ToolBarMode ) => this . toolbarsMode = mode } toolbarsMode = { toolbarsMode } onClick = { this . onClickMode } />
3741 < ToolBar toolbars = { toolbars } onClick = { this . onClick } />
3842 < div className = { classnames ( `${ prefixCls } -content` ) } >
3943 < CodeMirror
@@ -79,17 +83,33 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
7983 onChange ( editor , data , value ) ;
8084 }
8185 }
86+
8287 private previewMarkdown ( ) {
8388 if ( this . preview ) {
8489 this . preview . state . visble ? this . preview . hide ( ) : this . preview . show ( ) ;
90+ this . toolbarsMode . updateMode ( 'preview' , ! this . preview . state . visble ) ;
8591 this . CodeMirror . editor . setSize ( this . preview . state . visble ? '100%' : '50%' ) ;
8692 }
8793 }
88- private onClick = ( type : string ) => {
94+
95+ private fullScreen ( ) {
96+ if ( this . toolbarsMode ) {
97+ this . toolbarsMode . updateMode ( 'fullscreen' , ! this . toolbarsMode . state . fullscreen ) ;
98+ }
99+ }
100+
101+ private onClickMode = ( type : string ) => {
89102 if ( type === 'preview' ) {
90103 this . previewMarkdown ( ) ;
91104 return ;
92105 }
106+ if ( type === 'fullscreen' ) {
107+ this . fullScreen ( ) ;
108+ return ;
109+ }
110+ }
111+
112+ private onClick = ( type : string ) => {
93113 const selection = this . CodeMirror . editor . getSelection ( ) ;
94114 const pos = this . CodeMirror . editor . getCursor ( ) ;
95115 let value = '' ;
0 commit comments