我遵循了有关安装内联和静态工具栏插件的文档,但它们似乎不存在。
我正在使用 Create React App CLI。
组件:
import React from 'react';
import {EditorState} from 'draft-js';
import Editor from 'draft-js-plugins-editor';
import createInlineToolbarPlugin from 'draft-js-inline-toolbar-plugin';
import createToolbarPlugin from 'draft-js-static-toolbar-plugin';
import 'draft-js/dist/Draft.css';
import 'draft-js-inline-toolbar-plugin/lib/plugin.css';
import 'draft-js-static-toolbar-plugin/lib/plugin.css';
const inlineToolbarPlugin = createInlineToolbarPlugin({
//I read somewhere that this plug-in needs this structure passed to it,
//but the example in the docs did not use it, and they are undefined anyway
// structure: [
// BoldButton,
// ItalicButton,
// UnderlineButton,
// CodeButton,
// Separator,
// ],
});
const toolbarPlugin = createToolbarPlugin();
class TextEditor extends React.Component {
constructor(props) {
super(props);
this.state = {editorState: EditorState.createEmpty()};
this.onChange = (editorState) => this.setState({editorState});
}
render() {
return (
<Editor
editorState={this.state.editorState}
onChange={this.onChange}
plugins={[inlineToolbarPlugin, toolbarPlugin]}
/>
);
}
}
export default TextEditor;
然后将该组件传递给另一个组件,该组件只呈现编辑器,不做任何其他事情。
我一定是遗漏了一些东西,或者没有给插件他们需要的东西,我只是不知道是什么。我猜我的代码不足以首先开始添加插件?