Summernote (Super simple WYSIWYG editor) adaptation for react
npm install react-summernote
#### Install
```
npm install react-summernote
#### Configure Webpack
Add ProvidePlugin to your webpack config
`javascript`
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
`javascript
import React, { Component } from 'react';
import ReactSummernote from 'react-summernote';
import 'react-summernote/dist/react-summernote.css'; // import styles
import 'react-summernote/lang/summernote-ru-RU'; // you can import any other locale
// Import bootstrap(v3 or v4) dependencies
import 'bootstrap/js/modal';
import 'bootstrap/js/dropdown';
import 'bootstrap/js/tooltip';
import 'bootstrap/dist/css/bootstrap.css';
class RichTextEditor extends Component {
onChange(content) {
console.log('onChange', content);
}
render() {
return (
options={{
lang: 'ru-RU',
height: 350,
dialogsInBody: true,
toolbar: [
['style', ['style']],
['font', ['bold', 'underline', 'clear']],
['fontname', ['fontname']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['view', ['fullscreen', 'codeview']]
]
}}
onChange={this.onChange}
/>
);
}
}
export default RichTextEditor;
`
| Property | Type | Description |
|------------|--------|---------------|
| value | String | Default value |Boolean
| codeview | | Option to render in codeview mode |Object
| options | | Options object. More info about options http://summernote.org/deep-dive |Function
| onInit | | Being invoked when summernote is launched |Function
| onEnter | | Enter/Return button pressed |Function
| onFocus | | Editable area receives the focus |Function
| onBlur | | Editable area loses the focus |Function
| onKeyDown | | e.keyCode is pressed |Function
| onKeyUp | | e.keyCode is released |Function
| onPaste | | Triggers when event paste's been called |Function
| onChange | | handler: function(contents, $editable) {}, invoked, when content's been changed |Function
| onImageUpload | | handler: function(files) {} |
`javascript`
reset() // Clear contents and remove all stored history
insertImage(url, filenameOrCallback) // Insert a image
insertNode(node) // Insert a element or textnode
insertText(text) // Insert a text
##### Example
`javascript/resources/getImage?imageGuid=${image.imageGuid}
ReactSummernote.insertImage(, $image => {``
$image.css("width", Math.floor($image.width() / 2));
$image.attr("alt", image.name);
});