- Notifications
You must be signed in to change notification settings - Fork16
A rich text editor built using draft js
License
AlastairTaft/draft-js-editor
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repo is not maintained, I would encourage not using it.
A rich text editor built using facebook'sdraft.js.
Takes inspiration from the text editors onmedium andfacebook notes.
npm install draft-js-editor --save
Import theEditor
class into your file. The example below usesES6 but it's not mandatory.
//...importEditorfrom'draft-js-editor'classMyClassextendsReact.Component{state={};render(){return<div> A sample text editor<EditoronChange={(editorState)=>this.setState({ editorState})}editorState={this.state.editorState}/></div>}}
The Editor component accepts all thedraft-js Editor props with the following additional ones.
iconColor
The color of the iconsiconSelectedColor
The color of the icon when selectedpopoverStyle
Override the inline styles for the popover menu controlsinlineButtons
This should be an array of React elements that will be rendered. Use this to customise the popover inline buttons. There's a 'Custom Inline Buttons' example under examples. Each element that gets rendered gets passed the following props: updateEditorState (call this after doing any editor state manipulations), editorState (the editor state), iconColor, iconSelectedColor.blockButtons
Customise the block buttons. See the custom block button exampleblockTypes
An object mapping custom types to components. Simpler than using draft-js's native blockRenderFn property.showInlineButtons
Set to false to prevent showing the inline buttons.SideControl
Override the side control to completely customise the interface. See the demo for an example.
If you need to persist the editor state somewhere there are two useful methods that are part of the draft-js library that will let you convert to and from a string,convertFromRaw
andconvertToRaw
These methods require aContentState
which you can obtain by callinggetCurrentContent
on theeditorState
object returned from theonChange
event.
You can use the staticcreateWithContent
method to obtain an editor state that can be passed in as a parameter to the Editor.
import { EditorState, convertFromRaw } from 'draft-js'const contentState = convertFromRaw(rawContent)const editorState = EditorState.createWithContent(contentState)
About
A rich text editor built using draft js
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.