🔥(frontend) hide markdown button if not text

If we are selected a block that is not a text block,
we hide the markdown button.
This commit is contained in:
Anthony LC
2024-08-30 14:55:46 +02:00
committed by Anthony LC
parent 38b32c1227
commit 00b223f648

View File

@@ -11,9 +11,10 @@ import {
UnnestBlockButton,
useBlockNoteEditor,
useComponentsContext,
useSelectedBlocks,
} from '@blocknote/react';
import { forEach, isArray } from 'lodash';
import React from 'react';
import React, { useMemo } from 'react';
export const BlockNoteToolbar = () => {
return (
@@ -91,6 +92,7 @@ const recursiveContent = (content: Block[], base: string = '') => {
export function MarkdownButton() {
const editor = useBlockNoteEditor();
const Components = useComponentsContext();
const selectedBlocks = useSelectedBlocks(editor);
const handleConvertMarkdown = () => {
const blocks = editor.getSelection()?.blocks;
@@ -114,7 +116,11 @@ export function MarkdownButton() {
});
};
if (!Components) {
const show = useMemo(() => {
return !!selectedBlocks.find((block) => block.content !== undefined);
}, [selectedBlocks]);
if (!show || !editor.isEditable || !Components) {
return null;
}