diff --git a/components/ClickToEdit.tsx b/components/ClickToEdit.tsx index e3f8aa3..c4e8c28 100644 --- a/components/ClickToEdit.tsx +++ b/components/ClickToEdit.tsx @@ -1,6 +1,6 @@ 'use client'; -import { RichTextEditor, Link } from '@mantine/tiptap'; +import { Link, RichTextEditor, useRichTextEditorContext } from '@mantine/tiptap'; import { useEditor } from '@tiptap/react'; import Highlight from '@tiptap/extension-highlight'; import StarterKit from '@tiptap/starter-kit'; @@ -8,7 +8,44 @@ import Underline from '@tiptap/extension-underline'; import TextAlign from '@tiptap/extension-text-align'; import Superscript from '@tiptap/extension-superscript'; import SubScript from '@tiptap/extension-subscript'; -import { useFocusWithin } from '@mantine/hooks'; +import { useDisclosure, useFocusWithin } from '@mantine/hooks'; +import { IconEdit } from '@tabler/icons-react'; +import { useState } from 'react'; +import { Button, Modal, Stack, Textarea } from '@mantine/core'; + +function EditHtmlControl() { + const { editor } = useRichTextEditorContext(); + const [content, setContent] = useState(''); + const [opened, { open, close }] = useDisclosure(false); + + function onEdit() { + editor?.setEditable(false); + setContent(editor?.getHTML() || ''); + open(); + } + + function saveEdit() { + close(); + editor?.commands.setContent(content); + editor?.setEditable(true); + } + + return ( + <> + + + + { editor?.setEditable(true); close(); }} centered withCloseButton={false}> + +