1- import React , { useState , useRef , useImperativeHandle } from 'react' ;
1+ import React , { useState , useRef , useImperativeHandle , Fragment } from 'react' ;
22import { markdown , markdownLanguage } from '@codemirror/lang-markdown' ;
33import { languages } from '@codemirror/language-data' ;
44import { EditorView , ViewUpdate } from '@codemirror/view' ;
@@ -28,16 +28,18 @@ export interface IMarkdownEditor extends ReactCodeMirrorProps {
2828 /** Shows a preview that will be converted to html. */
2929 visible ?: boolean ;
3030 visibleEditor ?: boolean ;
31- /** Option to hide the tool bar. */
32- hideToolbar ?: boolean ;
3331 /** Override the default preview component */
3432 renderPreview ?: ( props : MarkdownPreviewProps , initVisible : boolean ) => React . ReactNode ;
3533 /** Preview expanded width @default `50%` */
3634 previewWidth ?: string ;
3735 /** Tool display settings. */
3836 toolbars ?: IToolBarProps [ 'toolbars' ] ;
39- /** Tool display settings. */
37+ /** The tool on the right shows the settings. */
4038 toolbarsMode ?: IToolBarProps [ 'toolbars' ] ;
39+ /** Toolbar on bottom */
40+ toolbarBottom ?: boolean ;
41+ /** Option to hide the tool bar. */
42+ hideToolbar ?: boolean ;
4143 /** [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview#options-props) options */
4244 previewProps ?: MarkdownPreviewProps ;
4345 /** replace the default `extensions` */
@@ -60,6 +62,7 @@ export interface MarkdownEditorRef {
6062const MarkdownEditor : MarkdownEditorComponent = React . forwardRef < MarkdownEditorRef , IMarkdownEditor > (
6163 MarkdownEditorInternal ,
6264) as unknown as MarkdownEditorComponent ;
65+
6366type MarkdownEditorComponent = React . FC < React . PropsWithRef < IMarkdownEditor > > & {
6467 Markdown : typeof MarkdownPreview ;
6568} ;
@@ -82,6 +85,7 @@ function MarkdownEditorInternal(
8285 renderPreview,
8386 visibleEditor = true ,
8487 hideToolbar = true ,
88+ toolbarBottom = false ,
8589 previewProps = { } ,
8690 extensions = [ ] ,
8791 previewWidth = '50%' ,
@@ -121,35 +125,56 @@ function MarkdownEditorInternal(
121125 setValue ( value ) ;
122126 onChange && onChange ( value , viewUpdate ) ;
123127 } ;
128+ const conentView = (
129+ < div className = { `${ prefixCls } -content` } style = { { height : codemirrorProps . height } } >
130+ < div className = { `${ prefixCls } -content-editor` } ref = { containerEditor } >
131+ { visibleEditor && (
132+ < CodeMirror
133+ theme = { defaultTheme }
134+ { ...codemirrorProps }
135+ extensions = { extensionsData }
136+ height = { height }
137+ ref = { codeMirror }
138+ onChange = { handleChange }
139+ />
140+ ) }
141+ </ div >
142+ < div className = { clsPreview } ref = { preview } >
143+ { renderPreview ? (
144+ renderPreview ( previewProps , ! ! visible )
145+ ) : (
146+ < MarkdownPreview { ...previewProps } data-visible = { ! ! visible } />
147+ ) }
148+ </ div >
149+ </ div >
150+ ) ;
151+
152+ const clsToolbar = [
153+ prefixCls && `${ prefixCls } -toolbar-warp` ,
154+ prefixCls && toolbarBottom && `${ prefixCls } -toolbar-bottom` ,
155+ ]
156+ . filter ( Boolean )
157+ . join ( ' ' ) ;
158+ const toolbarView = hideToolbar && (
159+ < div className = { clsToolbar } >
160+ < ToolBar { ...toolBarProps } toolbars = { toolbars } />
161+ < ToolBar { ...toolBarProps } toolbars = { toolbarsMode } mode />
162+ </ div >
163+ ) ;
164+ const child = toolbarBottom ? (
165+ < Fragment >
166+ { conentView }
167+ { toolbarView }
168+ </ Fragment >
169+ ) : (
170+ < Fragment >
171+ { toolbarView }
172+ { conentView }
173+ </ Fragment >
174+ ) ;
124175 return (
125176 < div className = { cls } ref = { container } >
126- { hideToolbar && (
127- < div className = { `${ prefixCls } -toolbar-warp` } >
128- < ToolBar { ...toolBarProps } toolbars = { toolbars } />
129- < ToolBar { ...toolBarProps } toolbars = { toolbarsMode } mode />
130- </ div >
131- ) }
132- < div className = { `${ prefixCls } -content` } style = { { height : codemirrorProps . height } } >
133- < div className = { `${ prefixCls } -content-editor` } ref = { containerEditor } >
134- { visibleEditor && (
135- < CodeMirror
136- theme = { defaultTheme }
137- { ...codemirrorProps }
138- extensions = { extensionsData }
139- height = { height }
140- ref = { codeMirror }
141- onChange = { handleChange }
142- />
143- ) }
144- </ div >
145- < div className = { clsPreview } ref = { preview } >
146- { renderPreview ? (
147- renderPreview ( previewProps , ! ! visible )
148- ) : (
149- < MarkdownPreview { ...previewProps } data-visible = { ! ! visible } />
150- ) }
151- </ div >
152- </ div >
177+ { child }
153178 </ div >
154179 ) ;
155180}
0 commit comments