From bd2d2927ff3005c7f301bd19b8d22e94c051ac50 Mon Sep 17 00:00:00 2001 From: renardeinside Date: Sat, 23 Nov 2024 23:51:49 +0100 Subject: [PATCH] rework menu, underlines and input --- package.json | 1 + src/components/Editor.tsx | 2 +- src/components/EditorMenu.tsx | 56 +++++++++++++++++++++++++-------- src/components/ui/separator.tsx | 29 +++++++++++++++++ yarn.lock | 7 +++++ 5 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 src/components/ui/separator.tsx diff --git a/package.json b/package.json index b058924..b9fc2c1 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2", "@radix-ui/react-label": "^2.1.0", + "@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-toast": "^1.2.2", "@tailwindcss/typography": "^0.5.15", diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx index ef406f4..440b61a 100644 --- a/src/components/Editor.tsx +++ b/src/components/Editor.tsx @@ -39,7 +39,7 @@ const Editor = () => { {loaded ? ( editor && (
- +
) diff --git a/src/components/EditorMenu.tsx b/src/components/EditorMenu.tsx index 68a645d..ed187ee 100644 --- a/src/components/EditorMenu.tsx +++ b/src/components/EditorMenu.tsx @@ -1,14 +1,11 @@ import { useState } from "react"; import { Button } from "@/components/ui/button"; import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu"; -import { + AlignCenter, + AlignJustify, + AlignLeft, + AlignRight, Bold, - Edit3, Italic, Link, Strikethrough, @@ -16,11 +13,34 @@ import { } from "lucide-react"; import { Editor } from "@tiptap/core"; import LinkInput from "./LinkInput"; +import { Separator } from "@/components/ui/separator"; export default function EditorMenu({ editor }: { editor: Editor }) { - const [isOpen, setIsOpen] = useState(false); const [openLinkInput, setOpenLinkInput] = useState(false); + const alignOptions = [ + { + icon: AlignLeft, + title: "Align Left", + action: () => editor.chain().focus().setTextAlign("left").run(), + }, + { + icon: AlignCenter, + title: "Align Center", + action: () => editor.chain().focus().setTextAlign("center").run(), + }, + { + icon: AlignRight, + title: "Align Right", + action: () => editor.chain().focus().setTextAlign("right").run(), + }, + { + icon: AlignJustify, + title: "Align Justify", + action: () => editor.chain().focus().setTextAlign("justify").run(), + }, + ]; + const formatOptions = [ { icon: Bold, @@ -56,6 +76,20 @@ export default function EditorMenu({ editor }: { editor: Editor }) { )}
+ {alignOptions.map((option) => ( + + ))} + {formatOptions.map((option) => (