
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
draft-js-richbuttons-plugin
Advanced tools
Rich Editing Buttons Plugin for DraftJS Plugins Editor
This is a plugin for the draft-js-plugins-editor
.
This plugin allows you to add essential rich formatting buttons (inline and block styles) to your plugins-enabled editor.
First instantiate the plugin:
import createRichButtonsPlugin from 'draft-js-richbuttons-plugin';
const richButtonsPlugin = createRichButtonsPlugin();
Now get any desired components for inline or block formatting buttons from the instance:
/* import only the ones you need; all available shown */
const {
// inline buttons
ItalicButton, BoldButton, MonospaceButton, UnderlineButton,
// block buttons
ParagraphButton, BlockquoteButton, CodeButton, OLButton, ULButton, H1Button, H2Button, H3Button, H4Button, H5Button, H6Button
} = richButtonsPlugin;
Render these where desired in your component:
<div className="myToolbar">
<BoldButton/>
<ItalicButton/>
<H2Button/>
<ULButton/>
<OLButton/>
</div>
The default buttons are intentionally plain, but will pass the needed props down to their child, allowing you to customize rendering to your needs.
Props passed to both inline and block buttons:
Props unique to inline buttons:
Props unique to block buttons:
Example:
/*
Stateless component for inline style buttons, using the passed props as well as a custom prop "iconName"
*/
const MyIconButton = ({iconName, toggleInlineStyle, isActive, label, inlineStyle, onMouseDown, title}) =>
<a onClick={toggleInlineStyle} onMouseDown={onMouseDown}>
<span
className={`fa fa-${iconName}`}
title={title ? title : label}
style={{ color: isActive ? '#000' : '#777' }}
/>
</a>;
The above presentational component could then be used this way:
<BoldButton>
<MyIconButton iconName="bold"/>
</BoldButton>
<ItalicButton>
<MyIconButton iconName="italic" title="Italicize" />
</ItalicButton>
The draft-js-plugins
project is approaching a v2 milestone, currently in beta. Use the 2.x branch of this repository if moving to the lastest version of that project; otherwise, 1.x is stable for the current release of draft-js-plugins
.
The plugin automatically applies default key bindings from draft's RichUtils
, including Tab / Shift-Tab behavior for nested lists.
MIT
2.2.0 - 2018-01-26
Buttons for custom block types or custom inline styles can now easily be generated; see the example at /example/CustomBlocksAndStyles.js
.
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.