import React, { useState, useRef, ReactElement } from 'react'; import Editor, { createEditorStateWithText } from '@draft-js-plugins/editor'; import createInlineToolbarPlugin from '@draft-js-plugins/inline-toolbar'; import createLinkPlugin from '@draft-js-plugins/anchor'; import { EditorState } from 'draft-js'; import { ItalicButton, BoldButton, UnderlineButton, } from '@draft-js-plugins/buttons'; import editorStyles from './editorStyles.css'; const linkPlugin = createLinkPlugin(); const inlineToolbarPlugin = createInlineToolbarPlugin(); const { InlineToolbar } = inlineToolbarPlugin; const plugins = [inlineToolbarPlugin, linkPlugin]; const text = 'Try selecting a part of this text and click on the link button in the toolbar that appears …'; const SimpleLinkPluginEditor = (): ReactElement => { const [editorState, setEditorState] = useState( createEditorStateWithText(text) ); const editor = useRef(); const onChange = (value: EditorState): void => { setEditorState(value); }; const focus = (): void => editor.current.focus(); return (
{ editor.current = element; }} /> {(externalProps) => ( <> )}
); }; export default SimpleLinkPluginEditor;