Introduction
react-draft-wysiwyg is a 3rd party plugin to Create RichTextEditor in React.
Properties
Styling the editor
The editor by default will use DraftJS editor, as it is without any styling and will occupy 100% width of the container. Some styling to add border to editor and set width would be nice.
- wrapperClassName: class applied around both the editor and the toolbar
- editorClassName: class applied around the editor
- toolbarClassName: class applied around the toolbar
- wrapperStyle: style object applied around both the editor and the toolbar
- editorStyle: style object applied around the editor
- toolbarStyle: style object applied around the toolbar
Editor state
The editor can be implemented as a controlled component using EditorState or un-controlled component using EditorState or RawDraftContentState.
- defaultEditorState: Property to initialize editor state once when its created.
- editorState: Property to update editor state in a controlled way.
- onEditorStateChange: Function is called each time there is a change in the state of the editor. A function argument passed is an object of EditorState.
- defaultContentState: Property to initialize editor state once when its created.
- contentState: Property to update editor state in a controlled way.
- onChange: Function is called each time there is a change in state of the editor. The function argument passed is an object of type RawDraftContentState.
- onContentStateChange: Function is called each time there is a change in state of the editor, function argument passed is object of type RawDraftContentState.
toolbar
The toolbar property provides a lot of parameters to customize the pre-built option in the toolbar. The default value of toolbar property is as shown below:
- {
- options: ['inline', 'blockType', 'fontSize', 'fontFamily', 'list', 'textAlign', 'colorPicker', 'link', 'embedded', 'emoji', 'image', 'remove', 'history'],
- inline: {
- inDropdown: false,
- className: undefined,
- component: undefined,
- dropdownClassName: undefined,
- options: ['bold', 'italic', 'underline', 'strikethrough', 'monospace', 'superscript', 'subscript'],
- bold: { icon: bold, className: undefined },
- italic: { icon: italic, className: undefined },
- underline: { icon: underline, className: undefined },
- strikethrough: { icon: strikethrough, className: undefined },
- monospace: { icon: monospace, className: undefined },
- superscript: { icon: superscript, className: undefined },
- subscript: { icon: subscript, className: undefined },
- },
- blockType: {
- inDropdown: true,
- options: ['Normal', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Blockquote', 'Code'],
- className: undefined,
- component: undefined,
- dropdownClassName: undefined,
- },
- fontSize: {
- icon: fontSize,
- options: [8, 9, 10, 11, 12, 14, 16, 18, 24, 30, 36, 48, 60, 72, 96],
- className: undefined,
- component: undefined,
- dropdownClassName: undefined,
- },
- fontFamily: {
- options: ['Arial', 'Georgia', 'Impact', 'Tahoma', 'Times New Roman', 'Verdana'],
- className: undefined,
- component: undefined,
- dropdownClassName: undefined,
- },
- list: {
- inDropdown: false,
- className: undefined,
- component: undefined,
- dropdownClassName: undefined,
- options: ['unordered', 'ordered', 'indent', 'outdent'],
- unordered: { icon: unordered, className: undefined },
- ordered: { icon: ordered, className: undefined },
- indent: { icon: indent, className: undefined },
- outdent: { icon: outdent, className: undefined },
- },
- textAlign: {
- inDropdown: false,
- className: undefined,
- component: undefined,
- dropdownClassName: undefined,
- options: ['left', 'center', 'right', 'justify'],
- left: { icon: left, className: undefined },
- center: { icon: center, className: undefined },
- right: { icon: right, className: undefined },
- justify: { icon: justify, className: undefined },
- },
- colorPicker: {
- icon: color,
- className: undefined,
- component: undefined,
- popupClassName: undefined,
- colors: ['#61bd6d', '#1abc9c', '#54acd2', '#2c82c9',
- '#9365b8', '#475577', '#cccccc', '#41a85f', '#00a885',
- '#3d8eb9', '#2969b0', '#553982', '#28324e', '#000000',
- '#f7da64', '#fba026', '#eb6b56', '#e25041', '#a38f84',
- '#efefef', '#ffffff', '#fac51c', '#f37934', '#d14841',
- '#b8312f', '#7c706b', '#d1d5d8'],
- },
- link: {
- inDropdown: false,
- className: undefined,
- component: undefined,
- popupClassName: undefined,
- dropdownClassName: undefined,
- showOpenOptionOnHover: true,
- defaultTargetOption: '_self',
- options: ['link', 'unlink'],
- link: { icon: link, className: undefined },
- unlink: { icon: unlink, className: undefined },
- linkCallback: undefined
- },
- emoji: {
- icon: emoji,
- className: undefined,
- component: undefined,
- popupClassName: undefined,
- emojis: [
- '😀', '😁', '😂', '😃', '😉', '😋', '😎', '😍', '😗', '🤗', '🤔', '😣', '😫', '😴', '😌', '🤓',
- '😛', '😜', '😠', '😇', '😷', '😈', '👻', '😺', '😸', '😹', '😻', '😼', '😽', '🙀', '🙈',
- '🙉', '🙊', '👼', '👮', '🕵', '💂', '👳', '🎅', '👸', '👰', '👲', '🙍', '🙇', '🚶', '🏃', '💃',
- '⛷', '🏂', '🏌', '🏄', '🚣', '🏊', '⛹', '🏋', '🚴', '👫', '💪', '👈', '👉', '👉', '👆', '🖕',
- '👇', '🖖', '🤘', '🖐', '👌', '👍', '👎', '✊', '👊', '👏', '🙌', '🙏', '🐵', '🐶', '🐇', '🐥',
- '🐸', '🐌', '🐛', '🐜', '🐝', '🍉', '🍄', '🍔', '🍤', '🍨', '🍪', '🎂', '🍰', '🍾', '🍷', '🍸',
- '🍺', '🌍', '🚑', '⏰', '🌙', '🌝', '🌞', '⭐', '🌟', '🌠', '🌨', '🌩', '⛄', '🔥', '🎄', '🎈',
- '🎉', '🎊', '🎁', '🎗', '🏀', '🏈', '🎲', '🔇', '🔈', '📣', '🔔', '🎵', '🎷', '💰', '🖊', '📅',
- '✅', '❎', '💯',
- ],
- },
- embedded: {
- icon: embedded,
- className: undefined,
- component: undefined,
- popupClassName: undefined,
- embedCallback: undefined,
- defaultSize: {
- height: 'auto',
- width: 'auto',
- },
- },
- image: {
- icon: image,
- className: undefined,
- component: undefined,
- popupClassName: undefined,
- urlEnabled: true,
- uploadEnabled: true,
- alignmentEnabled: true,
- uploadCallback: undefined,
- previewImage: false,
- inputAccept: 'image/gif,image/jpeg,image/jpg,image/png,image/svg',
- alt: { present: false, mandatory: false },
- defaultSize: {
- height: 'auto',
- width: 'auto',
- },
- },
- remove: { icon: eraser, className: undefined, component: undefined },
- history: {
- inDropdown: false,
- className: undefined,
- component: undefined,
- dropdownClassName: undefined,
- options: ['undo', 'redo'],
- undo: { icon: undo, className: undefined },
- redo: { icon: redo, className: undefined },
- },
- }
Various parameters and their uses are:


Michael Feng WanPosted Jul 1, 2024, 8:53 PM
Thanks for sharing, looks great. Do you have updated code can work in [email protected], [email protected]?
Julio MunozPosted Jun 28, 2021, 3:36 PM
Thank you for sharing, Only I have a question, I am testing this control and work fine, but when I set the HTML value in its state using `htmlToDraft`I can assign a html markup as a value because lost the markup, i.e, I assigne `<p class="ms-rteElement-Note-default">Hello I am here</p>` but when I see the value, only I found `<p>Hello I am here</p>` Do you have any ideat how to do that? Thanks in advace to answer me :)
Bharath Radhekrishna ChennuPosted Dec 9, 2019, 1:17 PM
Thanks for nice post