Skip to content

Commit bc69d26

Browse files
committed
feat: add toolbarsFilter porps. #197
1 parent cd677a4 commit bc69d26

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/components/ToolBar/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { ICommand, defaultCommands } from '../../commands';
33
import { IMarkdownEditor, ToolBarProps } from '../../';
44
import './index.less';
55

6-
export interface IToolBarProps<T = keyof typeof defaultCommands | ICommand> extends ToolBarProps {
6+
export type Commands = keyof typeof defaultCommands | ICommand;
7+
8+
export interface IToolBarProps<T = Commands> extends ToolBarProps {
79
className?: string;
810
editorProps: IMarkdownEditor;
911
mode?: boolean;

src/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { EditorView, ViewUpdate } from '@codemirror/view';
55
import * as events from '@uiw/codemirror-extensions-events';
66
import CodeMirror, { ReactCodeMirrorProps, ReactCodeMirrorRef } from '@uiw/react-codemirror';
77
import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
8-
import ToolBar, { IToolBarProps } from './components/ToolBar';
8+
import ToolBar, { Commands } from './components/ToolBar';
99
import { getCommands, getModeCommands } from './commands';
1010
import { defaultTheme } from './theme';
1111
import './index.less';
@@ -36,9 +36,11 @@ export interface IMarkdownEditor extends ReactCodeMirrorProps {
3636
/** Whether to enable scrolling */
3737
enableScroll?: boolean;
3838
/** Tool display settings. */
39-
toolbars?: IToolBarProps['toolbars'];
39+
toolbars?: Commands[];
4040
/** The tool on the right shows the settings. */
41-
toolbarsMode?: IToolBarProps['toolbars'];
41+
toolbarsMode?: Commands[];
42+
/** Tool display filter settings. */
43+
toolbarsFilter?: (tool: Commands, idx: number) => boolean;
4244
/** Toolbar on bottom */
4345
toolbarBottom?: boolean;
4446
/** Option to hide the tool bar. */
@@ -84,6 +86,7 @@ function MarkdownEditorInternal(
8486
onChange,
8587
toolbars = getCommands(),
8688
toolbarsMode = getModeCommands(),
89+
toolbarsFilter,
8790
visible = true,
8891
renderPreview,
8992
visibleEditor = true,
@@ -202,10 +205,13 @@ function MarkdownEditorInternal(
202205
]
203206
.filter(Boolean)
204207
.join(' ');
208+
209+
const tools = toolbarsFilter ? toolbars.filter(toolbarsFilter) : toolbars;
210+
const toolsMode = toolbarsFilter ? toolbarsMode.filter(toolbarsFilter) : toolbarsMode;
205211
const toolbarView = hideToolbar && (
206212
<div className={clsToolbar}>
207-
<ToolBar {...toolBarProps} toolbars={toolbars} />
208-
<ToolBar {...toolBarProps} toolbars={toolbarsMode} mode />
213+
<ToolBar {...toolBarProps} toolbars={tools} />
214+
<ToolBar {...toolBarProps} toolbars={toolsMode} mode />
209215
</div>
210216
);
211217
const child = toolbarBottom ? (

0 commit comments

Comments
 (0)