import React, { ReactElement, useRef, useState } from 'react'; import Editor, { createEditorStateWithText } from '@draft-js-plugins/editor'; import createInlineToolbarPlugin from '@draft-js-plugins/inline-toolbar'; import editorStyles from './editorStyles.css'; const inlineToolbarPlugin = createInlineToolbarPlugin(); const { InlineToolbar } = inlineToolbarPlugin; const plugins = [inlineToolbarPlugin]; const text = 'In this editor a toolbar shows up once you select part of the text …'; const SimpleInlineToolbarEditor = (): ReactElement => { const [editorState, setEditorState] = useState( createEditorStateWithText(text) ); const editor = useRef(); const onChange = (value): void => { setEditorState(value); }; const focus = (): void => { editor.current.focus(); }; return (
{ editor.current = element; }} />
); }; export default SimpleInlineToolbarEditor;