@@ -3,10 +3,88 @@ Embed a local image in your draft-js editor
33
44* This is a plugin for the ` draft-js-plugins-editor ` .*
55
6- Usage:
6+ ## Installation
7+ ```
8+ npm install draft-js-select-image-plugin
9+ ```
710
11+ ## Usage
12+ This plugin exposes a button that integrates with the side toolbar.
13+ Render the image is out of the scope, but in the next example you can see how integrate ` draft-js-image-plugin ` .
14+
15+ ``` js
16+ import createSelectImagePlugin from ' draft-js-select-image-plugin' ;
17+ const selectImagePlugin = createSelectImagePlugin ({});
18+ ```
19+
20+ ## Configuration
21+ | Param | Default | Description |
22+ | -----------| ---------| --------------------------------------------------------------------------------------------------------------|
23+ | imageType | IMAGE | Type of entity created when insert the atomic block. By default is the same value as ` draft-js-image-plugin ` |
24+
25+ ## Integration
826``` js
27+ import React from ' react' ;
28+ import ReactDOM from ' react-dom' ;
29+
30+ import Editor from ' draft-js-plugins-editor' ;
31+ import { EditorState } from ' draft-js' ;
32+ import createSideToolbarPlugin from ' draft-js-side-toolbar-plugin' ;
33+ import BlockTypeSelect from ' draft-js-side-toolbar-plugin/lib/components/BlockTypeSelect' ;
34+
35+ import createImagePlugin from ' draft-js-image-plugin' ;
936import createSelectImagePlugin from ' draft-js-select-image-plugin' ;
37+ import ' draft-js-side-toolbar-plugin/lib/plugin.css' ;
1038
39+ const imagePlugin = createImagePlugin ();
1140const selectImagePlugin = createSelectImagePlugin ();
12- ```
41+ const DefaultBlockTypeSelect = ({ getEditorState, setEditorState, theme }) => (
42+ < BlockTypeSelect
43+ getEditorState= {getEditorState}
44+ setEditorState= {setEditorState}
45+ theme= {theme}
46+ structure= {[
47+ selectImagePlugin .SelectImageButton
48+ ]}
49+ / >
50+ );
51+ const sideToolbarPlugin = createSideToolbarPlugin ({
52+ structure: [DefaultBlockTypeSelect],
53+ });
54+ const { SideToolbar } = sideToolbarPlugin;
55+
56+ class MyEditor extends React .Component {
57+ constructor (props ) {
58+ super (props);
59+ this .state = {
60+ editorState: EditorState .createEmpty ()
61+ };
62+ this .plugins = [
63+ sideToolbarPlugin,
64+ imagePlugin
65+ ];
66+ }
67+
68+ onChange = (editorState ) => {
69+ this .setState ({ editorState });
70+ }
71+
72+ render () {
73+ return (
74+ < div className= " editor" >
75+ < Editor
76+ editorState= {this .state .editorState }
77+ onChange= {this .onChange }
78+ plugins= {this .plugins }
79+ placeholder= " Tell a story" / >
80+ < SideToolbar / >
81+ < / div>
82+ );
83+ }
84+ }
85+
86+ ReactDOM .render (< MyEditor / > , document .getElementById (' root' ));
87+ ```
88+
89+ # Acknowledge
90+ * Icon by: https://www.iconfinder.com/icons/290132/gallery_image_photo_photography_picture_pictures_icon
0 commit comments