Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icelab/draft-js-block-breakout-plugin
A plugin for draft-js that allows you to break out of block types as you type.
https://github.com/icelab/draft-js-block-breakout-plugin
Last synced: 2 months ago
JSON representation
A plugin for draft-js that allows you to break out of block types as you type.
- Host: GitHub
- URL: https://github.com/icelab/draft-js-block-breakout-plugin
- Owner: icelab
- License: mit
- Created: 2016-06-08T05:59:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-10T12:25:03.000Z (over 6 years ago)
- Last Synced: 2024-10-30T19:23:42.561Z (3 months ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 40
- Watchers: 6
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-draft-js - Block Breakout - Break out of block types as you type. (Plugins and Decorators Built for Draft.js)
README
# Draft.js Block Breakout plugin
*This is a plugin for the [`draft-js-plugins-editor`](https://www.draft-js-plugins.com/), 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
```js
import createBlockBreakoutPlugin from 'draft-js-block-breakout-plugin'
const blockBreakoutPlugin = createBlockBreakoutPlugin()
```This can then be passed into a `draft-js-plugins-editor` component:
```js
import createBlockBreakoutPlugin from 'draft-js-block-breakout-plugin'
const blockBreakoutPlugin = createBlockBreakoutPlugin()
import Editor from 'draft-js-plugins-editor'const plugins = [blockBreakoutPlugin]
```
## Options
You can pass options to the plugin as you call it:
```js
const options = {
breakoutBlockType: 'unordered-list-item',
breakoutBlocks: ['header-one', 'header-two']
}
const blockBreakoutPlugin = createBlockBreakoutPlugin(options)
```The options and their defaults are:
| Option | Type | Description | Default |
| --- | --- | --- | --- |
| `breakoutBlockType` | `String` | Block type to insert when breaking out | `'unstyled'`
| `breakoutBlocks` | `Array` | List of block types to break out from | `['header-one', 'header-two', 'header-three', 'header-four', 'header-five', 'header-six']`
| `doubleBreakoutBlocks` | `Array` | List of block types to that require return on a blank line in order to break | `['blockquote', 'unordered-list-item', 'ordered-list-item', 'code-block']`## Developing
```
npm install
npm run test
```