2023-08-02 17:34:55 +00:00
|
|
|
import Placeholder from '@tiptap/extension-placeholder';
|
|
|
|
import { useEditor, EditorContent } from '@tiptap/react';
|
|
|
|
import StarterKit from '@tiptap/starter-kit';
|
|
|
|
import { EditorBubbleMenu } from './EditorBubbleMenu';
|
2023-08-02 18:45:02 +00:00
|
|
|
import { TiptapExtensions } from './extensions';
|
2023-08-02 17:34:55 +00:00
|
|
|
import { TiptapEditorProps } from "./props";
|
|
|
|
|
|
|
|
type TiptapProps = {
|
|
|
|
value: string;
|
|
|
|
noBorder?: boolean;
|
|
|
|
borderOnFocus?: boolean;
|
|
|
|
customClassName?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Tiptap = ({ value, noBorder, borderOnFocus, customClassName }: TiptapProps) => {
|
|
|
|
const editor = useEditor({
|
|
|
|
editorProps: TiptapEditorProps,
|
2023-08-02 18:45:02 +00:00
|
|
|
extensions: TiptapExtensions,
|
|
|
|
// extensions: [
|
|
|
|
// StarterKit,
|
|
|
|
// Placeholder.configure({
|
|
|
|
// placeholder: 'Description...',
|
|
|
|
// })
|
|
|
|
// ],
|
2023-08-02 17:34:55 +00:00
|
|
|
content: value,
|
|
|
|
});
|
|
|
|
|
|
|
|
const editorClassNames = `mt-2 p-3 relative focus:outline-none rounded-md focus:border-custom-border-200
|
|
|
|
${noBorder ? '' : 'border border-custom-border-200'
|
|
|
|
} ${borderOnFocus ? 'focus:border border-custom-border-200' : 'focus:border-0'
|
|
|
|
} ${customClassName}`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
editor?.chain().focus().run();
|
|
|
|
}}
|
|
|
|
className={`tiptap-editor-container relative min-h-[150px] ${editorClassNames}`}
|
|
|
|
>
|
2023-08-02 18:45:02 +00:00
|
|
|
{editor && <EditorBubbleMenu editor={editor} />}
|
2023-08-02 17:34:55 +00:00
|
|
|
<EditorContent editor={editor} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Tiptap;
|