/
App.js
66 lines (59 loc) · 1.85 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { Component } from 'react';
import Editor, { createEditorStateWithText } from 'draft-js-plugins-editor';
import {
HeadlineOneButton,
HeadlineTwoButton,
BlockquoteButton,
CodeBlockButton,
UnorderedListButton,
OrderedListButton,
} from 'draft-js-buttons';
import createSideToolbarPlugin from 'draft-js-side-toolbar-plugin';
import editorStyles from './editorStyles.css';
const sideToolbarPlugin = createSideToolbarPlugin();
const { SideToolbar } = sideToolbarPlugin;
const plugins = [sideToolbarPlugin];
const text = 'Once you click into the text field the sidebar plugin will show up …';
export default class SimpleSideToolbarEditor extends Component {
state = {
editorState: createEditorStateWithText(text),
};
onChange = (editorState) => {
this.setState({
editorState,
});
};
focus = () => {
this.editor.focus();
};
render() {
return (
<div className={editorStyles.editor} onClick={this.focus}>
<Editor
editorState={this.state.editorState}
onChange={this.onChange}
plugins={plugins}
ref={(element) => { this.editor = element; }}
/>
<SideToolbar>{
(getEditorState, setEditorState, theme) => {
const buttonProps = {
getEditorState,
setEditorState,
theme
};
// may be use React.Fragment instead of div to improve perfomance after React 16
return (<div>
<HeadlineOneButton {...buttonProps} />
<HeadlineTwoButton {...buttonProps} />
<BlockquoteButton {...buttonProps} />
<CodeBlockButton {...buttonProps} />
<UnorderedListButton {...buttonProps} />
<OrderedListButton {...buttonProps} />
</div>);
}
}</SideToolbar>
</div>
);
}
}