import { Editor, useEditorState } from "@tiptap/react";
import {
AlignCenter,
AlignLeft,
AlignRight,
Bold,
Heading1,
Heading2,
Heading3,
Highlighter,
Italic,
List,
ListOrdered,
} from "lucide-react";
import { Toggle } from "../ui/toggle";
export default function Menubar({ editor }: { editor: Editor | null }) {
if (!editor) {
return null;
}
const editorState = useEditorState({
editor,
selector: (ctx) => {
return {
// Text formatting
isBold: ctx.editor.isActive("bold") ?? false,
isItalic: ctx.editor.isActive("italic") ?? false,
isStrike: ctx.editor.isActive("strike") ?? false,
isHighlight: ctx.editor.isActive("highlight") ?? false,
// Text alignment
isAlignLeft: ctx.editor.isActive({ textAlign: "left" }) ?? false,
isAlignCenter: ctx.editor.isActive({ textAlign: "center" }) ?? false,
isAlignRight: ctx.editor.isActive({ textAlign: "right" }) ?? false,
isAlignJustify: ctx.editor.isActive({ textAlign: "justify" }) ?? false,
// Block types
isParagraph: ctx.editor.isActive("paragraph") ?? false,
isHeading1: ctx.editor.isActive("heading", { level: 1 }) ?? false,
isHeading2: ctx.editor.isActive("heading", { level: 2 }) ?? false,
isHeading3: ctx.editor.isActive("heading", { level: 3 }) ?? false,
};
},
});
const options: {
icon: React.ReactNode;
onClick: () => void;
pressed: boolean;
}[] = [
{
icon: ,
onClick: () => editor.chain().focus().toggleBulletList().run(),
pressed: editor.isActive("bulletList"),
},
{
icon: