similiquedicta
Version:
A Plugin Architecture on top of Draft.JS
53 lines (43 loc) • 1.31 kB
JavaScript
import React, { Component } from 'react';
import Editor, { createEditorStateWithText } from '@draft-js-plugins/editor';
import createImagePlugin from '@draft-js-plugins/image';
import ImageAdd from './ImageAdd';
import editorStyles from './editorStyles.module.css';
const imagePlugin = createImagePlugin();
const plugins = [imagePlugin];
const text =
'Click on the + button below and insert "/images/canada-landscape-small.jpg" to add the landscape image. Alternativly you can use any image url on the web.';
export default class CustomImageEditor extends Component {
state = {
editorState: createEditorStateWithText(text),
};
onChange = (editorState) => {
this.setState({
editorState,
});
};
focus = () => {
this.editor.focus();
};
render() {
return (
<div>
<div className={editorStyles.editor} onClick={this.focus}>
<Editor
editorState={this.state.editorState}
onChange={this.onChange}
plugins={plugins}
ref={(element) => {
this.editor = element;
}}
/>
</div>
<ImageAdd
editorState={this.state.editorState}
onChange={this.onChange}
modifier={imagePlugin.addImage}
/>
</div>
);
}
}