similiquedicta
Version:
A Plugin Architecture on top of Draft.JS
50 lines (44 loc) ⢠1.3 kB
JavaScript
import React, { Component } from 'react';
import Editor, { createEditorStateWithText } from '@draft-js-plugins/editor';
import createEmojiPlugin from '@draft-js-plugins/emoji';
import editorStyles from './editorStyles.module.css';
const emojiPlugin = createEmojiPlugin({
useNativeArt: true,
});
const { EmojiSuggestions, EmojiSelect } = emojiPlugin;
const plugins = [emojiPlugin];
const text = `Cool, we can have all sorts of Emojis here. š
šæāļøšš aaaand maybe a few more here š²āļøš» Quite fun!`;
export default class CustomEmojiEditor 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;
}}
/>
<EmojiSuggestions />
</div>
<div className={editorStyles.options}>
<EmojiSelect closeOnEmojiSelect />
</div>
</div>
);
}
}