Skip to content

Commit

Permalink
feat: add hideToolbar props (#188).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 28, 2022
1 parent 4647f5d commit 677d2d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export interface IMarkdownEditor extends ReactCodeMirrorProps {
/** Shows a preview that will be converted to html. */
visible?: boolean;
visibleEditor?: boolean;
/** Option to hide the tool bar. */
hideToolbar?: boolean;
/** Tool display settings. */
toolbars?: IToolBarProps['toolbars'];
/** Tool display settings. */
Expand Down
13 changes: 9 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface IMarkdownEditor extends ReactCodeMirrorProps {
/** Shows a preview that will be converted to html. */
visible?: boolean;
visibleEditor?: boolean;
/** Option to hide the tool bar. */
hideToolbar?: boolean;
/** Tool display settings. */
toolbars?: IToolBarProps['toolbars'];
/** Tool display settings. */
Expand Down Expand Up @@ -61,6 +63,7 @@ function MarkdownEditor(
toolbarsMode = getModeCommands(),
visible = true,
visibleEditor = true,
hideToolbar = true,
previewProps = {},
extensions = [],
...codemirrorProps
Expand Down Expand Up @@ -90,10 +93,12 @@ function MarkdownEditor(
};
return (
<div className={`${prefixCls || ''} wmde-markdown-var ${className || ''}`} ref={container}>
<div>
<ToolBar {...toolBarProps} toolbars={toolbarsMode} mode />
<ToolBar {...toolBarProps} toolbars={toolbars} />
</div>
{hideToolbar && (
<div>
<ToolBar {...toolBarProps} toolbars={toolbarsMode} mode />
<ToolBar {...toolBarProps} toolbars={toolbars} />
</div>
)}
<div className={`${prefixCls}-content`} style={{ height: codemirrorProps.height }}>
<div className={`${prefixCls}-content-editor`} ref={containerEditor}>
{visibleEditor && (
Expand Down
7 changes: 6 additions & 1 deletion website/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let count = 1;
export default function App() {
const [visible, setVisible] = useState(true);
const [mdstr, setMdstr] = useState<string>(DocumentStrSource);
const [hideToolbar, setHideToolbar] = useState(true);
return (
<div className={styles.warpper}>
<dark-mode light="Light" dark="Dart" style={{ position: 'fixed' }}></dark-mode>
Expand All @@ -22,7 +23,7 @@ export default function App() {
<Logo style={{ fill: 'currentColor' }} />
</div>
<div className={styles.editor}>
<MarkdownEditor visible={visible} height="500px" value={mdstr} />
<MarkdownEditor visible={visible} height="500px" value={mdstr} hideToolbar={hideToolbar} />
<div style={{ marginTop: 10, display: 'flex', gap: '10px' }}>
<button
onClick={() => {
Expand All @@ -32,6 +33,10 @@ export default function App() {
>
Modify Markdown
</button>
<label>
<input type="checkbox" checked={hideToolbar} onChange={(evn) => setHideToolbar(evn.target.checked)} />
hideToolbar
</label>
<button onClick={() => setVisible(!visible)}>{visible ? 'Show' : 'Hide'}</button>
<span>v{VERSION}</span>
</div>
Expand Down

0 comments on commit 677d2d9

Please sign in to comment.