Coder Social home page Coder Social logo

luismahou / draft-js-block-breakout-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from icelab/draft-js-block-breakout-plugin

0.0 1.0 0.0 9 KB

A plugin for draft-js that allows you to break out of block types as you type.

License: MIT License

JavaScript 100.00%

draft-js-block-breakout-plugin's Introduction

Draft.js Block Breakout plugin

This is a plugin for the draft-js-plugins-editor, a plugin system that sits on top of Draft.js.

By default draft carries the current block type over to the next line when you press return, which is an undesired behaviour for some of the default block types (headers mostly).

This plugin adds behaviour to the editor to "break out" of certain block types if the user presses return at the start or end of the block. Where "break out" means changing the inserted block to the default type (usually unstyled)

Usage

import createBlockBreakoutPlugin from 'draft-js-block-breakout-plugin'
const blockBreakoutPlugin = createBlockBreakoutPlugin()

This can then be passed into a draft-js-plugins-editor component:

import createBlockBreakoutPlugin from 'draft-js-block-breakout-plugin'
const blockBreakoutPlugin = createBlockBreakoutPlugin()
import Editor from 'draft-js-plugins-editor'

const plugins = [blockBreakoutPlugin]

<Editor plugins={plugins} />

Options

You can pass options to the plugin as you call it:

const options = {
  defaultBlockType: 'unordered-list-item',
  breakoutBlockTypes: ['header-one', 'header-two']
}
const blockBreakoutPlugin = createBlockBreakoutPlugin(options)

The options and their defaults are:

Option Type Description Default
defaultBlockType String Block type to insert when breaking out 'unstyled'
breakoutBlockTypes Array List of block types to break out from ['header-one', 'header-two', 'header-three', 'header-four', 'header-five', 'header-six']

Developing

npm install
npm run test

draft-js-block-breakout-plugin's People

Contributors

makenosound avatar

Watchers

luismahou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.