application/components/common/rich-editor/horizontal-rule.js
import React from 'react';
import {AtomicBlockUtils, Entity} from 'draft-js';
import {info} from './../../../util/console';
import BaseView from './../../base-view';
/**
* Render a horizontal rule
*/
class HorizontalRuleBlock extends BaseView {
render() {
return (
<hr className='block-RichEditor-hr' />
);
}
}
/**
* Simple callback to insert the hr wrapper into the editor
*/
const insertHorizontalRule = (editorState) => {
const newContentState = editorState.getCurrentContent().createEntity(
'TOKEN',
'IMMUTABLE',
{customType: 'horizontal-rule'}
);
const entityKey = newContentState.getLastCreatedEntityKey();
return AtomicBlockUtils.insertAtomicBlock(
editorState,
entityKey,
' '
);
};
export {HorizontalRuleBlock as default, insertHorizontalRule};