npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

draft-js-richbuttons-plugin

v2.2.0

Published

Rich Editing Buttons Plugin for DraftJS Plugins Editor

Downloads

477

Readme

DraftJS RichButtons Plugin

npm version Build Status

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.

Usage

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>

Rendering Your Own Buttons

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:

  • isActive (bool) - true if style / blocktype active in selection
  • label (string) - default label

Props unique to inline buttons:

  • toggleInlineStyle (func) - to be attached to your click event
  • inlineStyle (string) - the draft code for the style
  • onMouseDown (func) - attach this to the onMouseDown event of your custom controls; important for preventing focus from leaving the editor when toggling an inline style with a click

Props unique to block buttons:

  • toggleBlockType (func) - to be attached to your click event
  • blockType (string) - the draft code for the block type

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>

Version 2.x.x

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.

Key Bindings

The plugin automatically applies default key bindings from draft's RichUtils, including Tab / Shift-Tab behavior for nested lists.

License

MIT