Skip to content

Commit 677d2d9

Browse files
committed
feat: add hideToolbar props (#188).
1 parent 4647f5d commit 677d2d9

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ export interface IMarkdownEditor extends ReactCodeMirrorProps {
222222
/** Shows a preview that will be converted to html. */
223223
visible?: boolean;
224224
visibleEditor?: boolean;
225+
/** Option to hide the tool bar. */
226+
hideToolbar?: boolean;
225227
/** Tool display settings. */
226228
toolbars?: IToolBarProps['toolbars'];
227229
/** Tool display settings. */

src/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface IMarkdownEditor extends ReactCodeMirrorProps {
2626
/** Shows a preview that will be converted to html. */
2727
visible?: boolean;
2828
visibleEditor?: boolean;
29+
/** Option to hide the tool bar. */
30+
hideToolbar?: boolean;
2931
/** Tool display settings. */
3032
toolbars?: IToolBarProps['toolbars'];
3133
/** Tool display settings. */
@@ -61,6 +63,7 @@ function MarkdownEditor(
6163
toolbarsMode = getModeCommands(),
6264
visible = true,
6365
visibleEditor = true,
66+
hideToolbar = true,
6467
previewProps = {},
6568
extensions = [],
6669
...codemirrorProps
@@ -90,10 +93,12 @@ function MarkdownEditor(
9093
};
9194
return (
9295
<div className={`${prefixCls || ''} wmde-markdown-var ${className || ''}`} ref={container}>
93-
<div>
94-
<ToolBar {...toolBarProps} toolbars={toolbarsMode} mode />
95-
<ToolBar {...toolBarProps} toolbars={toolbars} />
96-
</div>
96+
{hideToolbar && (
97+
<div>
98+
<ToolBar {...toolBarProps} toolbars={toolbarsMode} mode />
99+
<ToolBar {...toolBarProps} toolbars={toolbars} />
100+
</div>
101+
)}
97102
<div className={`${prefixCls}-content`} style={{ height: codemirrorProps.height }}>
98103
<div className={`${prefixCls}-content-editor`} ref={containerEditor}>
99104
{visibleEditor && (

website/App.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let count = 1;
1414
export default function App() {
1515
const [visible, setVisible] = useState(true);
1616
const [mdstr, setMdstr] = useState<string>(DocumentStrSource);
17+
const [hideToolbar, setHideToolbar] = useState(true);
1718
return (
1819
<div className={styles.warpper}>
1920
<dark-mode light="Light" dark="Dart" style={{ position: 'fixed' }}></dark-mode>
@@ -22,7 +23,7 @@ export default function App() {
2223
<Logo style={{ fill: 'currentColor' }} />
2324
</div>
2425
<div className={styles.editor}>
25-
<MarkdownEditor visible={visible} height="500px" value={mdstr} />
26+
<MarkdownEditor visible={visible} height="500px" value={mdstr} hideToolbar={hideToolbar} />
2627
<div style={{ marginTop: 10, display: 'flex', gap: '10px' }}>
2728
<button
2829
onClick={() => {
@@ -32,6 +33,10 @@ export default function App() {
3233
>
3334
Modify Markdown
3435
</button>
36+
<label>
37+
<input type="checkbox" checked={hideToolbar} onChange={(evn) => setHideToolbar(evn.target.checked)} />
38+
hideToolbar
39+
</label>
3540
<button onClick={() => setVisible(!visible)}>{visible ? 'Show' : 'Hide'}</button>
3641
<span>v{VERSION}</span>
3742
</div>

0 commit comments

Comments
 (0)