This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
EditorField.js
executable file
·59 lines (58 loc) · 1.56 KB
/
EditorField.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
/* @flow */
import React, { Component } from 'react';
// $FlowIssue
import { convertFromHTML } from 'draft-convert';
// $FlowIssue
import { convertToRaw, EditorState } from 'draft-js';
import Editor from '../../../../../../components/BoldrEditor';
export type Props = {
input: Object,
placeholder: string,
};
const editorStyle = {
minHeight: 400,
};
type State = {
editorState: EditorState,
};
export default class EditorField extends Component {
constructor(props: Props) {
super(props);
let editorState = EditorState.createEmpty();
if (props.input.value) {
editorState = EditorState.createWithContent(convertFromHTML(props.input.value));
}
this.state = {
editorState,
};
}
state: State;
props: Props;
onChange = (editorState: Object) => {
const { input } = this.props;
input.onChange(convertToRaw(editorState.getCurrentContent()));
this.setState({ editorState });
};
render() {
const { input, placeholder } = this.props;
const { editorState } = this.state;
return (
<Editor
{...input}
editorStyle={editorStyle}
onEditorStateChange={this.onChange}
editorState={editorState}
toolbarClassName="playground-toolbar"
wrapperClassName="playground-wrapper"
editorClassName="playground-editor"
toolbar={{
history: { inDropdown: true },
inline: { inDropdown: false },
list: { inDropdown: true },
link: { showOpenOptionOnHover: true },
textAlign: { inDropdown: true },
}}
/>
);
}
}