Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icelab/draft-js-single-line-plugin
Restrict a draft-js editor to a single line of input.
https://github.com/icelab/draft-js-single-line-plugin
Last synced: 3 months ago
JSON representation
Restrict a draft-js editor to a single line of input.
- Host: GitHub
- URL: https://github.com/icelab/draft-js-single-line-plugin
- Owner: icelab
- License: mit
- Created: 2016-05-30T07:49:01.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-04T04:08:48.000Z (almost 2 years ago)
- Last Synced: 2024-04-27T03:23:32.753Z (7 months ago)
- Language: JavaScript
- Size: 185 KB
- Stars: 43
- Watchers: 7
- Forks: 9
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-draft-js - Single Line - Restrict to a single line of input. (Plugins and Decorators Built for Draft.js)
README
# Draft.js Single Line 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.*
This plugin adds support restricting [Facebook’s Draft.js editor](https://facebook.github.io/draft-js/) to a single line of content. It will condense any blocks into a single block, and (optionally) strip any rich entities.
## What, why?!
Madness I know, however there places you want to allow _some_ rich styling yet the underlying value should still be a single line. Allowing titles for things like blog posts or pages to contain strong/emphasis is our main use-case.
## Usage
```js
import createSingleLinePlugin from 'draft-js-single-line-plugin'
const singleLinePlugin = createSingleLinePlugin()
```This can then be passed into a `draft-js-plugins-editor` component:
```js
import createSingleLinePlugin from 'draft-js-single-line-plugin'
const singleLinePlugin = createSingleLinePlugin()
import Editor from 'draft-js-plugins-editor'const plugins = [singleLinePlugin]
```
The plugin export a custom `blockRenderMap` that overrides the draft-js defaults and restricts the editor from rendering anything _except_ an `unstyled` block. You’ll need to manually pass it as above as the `draft-js-plugins-editor` doesn’t yet support this.
## Options
You can pass options to the plugin as you call it:
```js
const options = {
stripEntities: false
}
const singleLinePlugin = createSingleLinePlugin(options)
```There’s only one option so far: `stripEntities: true/false`.
## Developing
```
npm install
npm install react react-dom draft-js
npm run test
```