similiquedicta
Version:
A Plugin Architecture on top of Draft.JS
49 lines (42 loc) • 1.14 kB
JavaScript
import React, { Component } from 'react';
import { EditorState } from 'draft-js';
import Editor from '@draft-js-plugins/editor';
import createVideoPlugin from '@draft-js-plugins/video';
import VideoAdd from './VideoAdd';
import editorStyles from './editorStyles.module.css';
const videoPlugin = createVideoPlugin();
const plugins = [videoPlugin];
export default class CustomVideoEditor extends Component {
state = {
editorState: EditorState.createEmpty(),
};
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>
<VideoAdd
editorState={this.state.editorState}
onChange={this.onChange}
modifier={videoPlugin.addVideo}
/>
</div>
);
}
}