|
| 1 | +import styles from "@/style/addquestion.module.css"; |
| 2 | + |
| 3 | +import React from "react"; |
| 4 | +import { Editor } from "@tiptap/core"; |
| 5 | +import { |
| 6 | + Bold, |
| 7 | + Code, |
| 8 | + Italic, |
| 9 | + List, |
| 10 | + ListOrdered, |
| 11 | + Redo, |
| 12 | + RemoveFormatting, |
| 13 | + Strikethrough, |
| 14 | + Underline, |
| 15 | + Undo, |
| 16 | +} from "lucide-react"; |
| 17 | +import Tooltip from "./Tooltip"; |
| 18 | + |
| 19 | +type Props = { |
| 20 | + editor: Editor | null; |
| 21 | +}; |
| 22 | + |
| 23 | +export const MenuBar = ({ editor }: Props) => { |
| 24 | + if (!editor) { |
| 25 | + return null; |
| 26 | + } |
| 27 | + |
| 28 | + return ( |
| 29 | + <div className={styles.buttonGroup}> |
| 30 | + <Tooltip text="Clear formatting"> |
| 31 | + <button |
| 32 | + onClick={() => editor.commands.unsetAllMarks()} |
| 33 | + className={styles.button} |
| 34 | + > |
| 35 | + <RemoveFormatting className="h-5 w-5" /> |
| 36 | + </button> |
| 37 | + </Tooltip> |
| 38 | + <Tooltip text="Bold"> |
| 39 | + <button |
| 40 | + onClick={() => editor.chain().focus().toggleBold().run()} |
| 41 | + className={`${styles.button} ${editor.isActive("bold") ? styles.isActive : ""}`} |
| 42 | + > |
| 43 | + <Bold className="h-5 w-5" /> |
| 44 | + </button> |
| 45 | + </Tooltip> |
| 46 | + |
| 47 | + <Tooltip text="Italics"> |
| 48 | + <button |
| 49 | + onClick={() => editor.chain().focus().toggleItalic().run()} |
| 50 | + className={`${styles.button} ${editor.isActive("italic") ? styles.isActive : ""}`} |
| 51 | + > |
| 52 | + <Italic className="h-5 w-5" /> |
| 53 | + </button> |
| 54 | + </Tooltip> |
| 55 | + |
| 56 | + <Tooltip text="Underline"> |
| 57 | + <button |
| 58 | + onClick={() => editor.chain().focus().toggleUnderline().run()} |
| 59 | + className={`${styles.button} ${editor.isActive("underline") ? styles.isActive : ""}`} |
| 60 | + > |
| 61 | + <Underline className="h-5 w-5" /> |
| 62 | + </button> |
| 63 | + </Tooltip> |
| 64 | + |
| 65 | + <Tooltip text="Strikethrough"> |
| 66 | + <button |
| 67 | + onClick={() => editor.chain().focus().toggleStrike().run()} |
| 68 | + className={`${styles.button} ${editor.isActive("strike") ? styles.isActive : ""}`} |
| 69 | + > |
| 70 | + <Strikethrough className="h-5 w-5" /> |
| 71 | + </button> |
| 72 | + </Tooltip> |
| 73 | + |
| 74 | + <Tooltip text="Code"> |
| 75 | + <button |
| 76 | + onClick={() => editor.chain().focus().toggleCode().run()} |
| 77 | + className={`${styles.button} ${editor.isActive("code") ? styles.isActive : ""}`} |
| 78 | + > |
| 79 | + <Code className="h-5 w-5" /> |
| 80 | + </button> |
| 81 | + </Tooltip> |
| 82 | + |
| 83 | + <Tooltip text="CodeBlock"> |
| 84 | + <button |
| 85 | + onClick={() => editor.chain().focus().toggleCode().run()} |
| 86 | + className={`${styles.button} ${editor.isActive("code") ? styles.isActive : ""}`} |
| 87 | + > |
| 88 | + <Code className="h-5 w-5" /> |
| 89 | + </button> |
| 90 | + </Tooltip> |
| 91 | + |
| 92 | + <Tooltip text="Numbered list"> |
| 93 | + <button |
| 94 | + onClick={() => editor.chain().focus().toggleOrderedList().run()} |
| 95 | + className={styles.button} |
| 96 | + > |
| 97 | + <ListOrdered className="h-5 w-5" /> |
| 98 | + </button> |
| 99 | + </Tooltip> |
| 100 | + |
| 101 | + <Tooltip text="Bullet list"> |
| 102 | + <button |
| 103 | + onClick={() => editor.chain().focus().toggleBulletList().run()} |
| 104 | + className={styles.button} |
| 105 | + > |
| 106 | + <List className="h-5 w-5" /> |
| 107 | + </button> |
| 108 | + </Tooltip> |
| 109 | + |
| 110 | + <Tooltip text="Undo"> |
| 111 | + <button |
| 112 | + onClick={() => editor.chain().focus().undo().run()} |
| 113 | + disabled={!editor.can().undo()} |
| 114 | + className={styles.button} |
| 115 | + > |
| 116 | + <Undo className="h-5 w-5" /> |
| 117 | + </button> |
| 118 | + </Tooltip> |
| 119 | + |
| 120 | + <Tooltip text="Redo"> |
| 121 | + <button |
| 122 | + onClick={() => editor.chain().focus().redo().run()} |
| 123 | + disabled={!editor.can().redo()} |
| 124 | + className={styles.button} |
| 125 | + > |
| 126 | + <Redo className="h-5 w-5" /> |
| 127 | + </button> |
| 128 | + </Tooltip> |
| 129 | + </div> |
| 130 | + ); |
| 131 | +}; |
0 commit comments