GithubHelp home page GithubHelp logo

tomkelsey / draft-js-single-line-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from icelab/draft-js-single-line-plugin

0.0 2.0 0.0 17 KB

Restrict a draft-js editor to a single line of input.

License: MIT License

JavaScript 100.00%

draft-js-single-line-plugin's Introduction

Draft.js Single Line plugin

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

This plugin adds support restricting Facebook’s Draft.js editor 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

import createSingleLinePlugin from 'draft-js-single-line-plugin'
const singleLinePlugin = createSingleLinePlugin()

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

import createSingleLinePlugin from 'draft-js-single-line-plugin'
const singleLinePlugin = createSingleLinePlugin()
import Editor from 'draft-js-plugins-editor'

const plugins = [singleLinePlugin]

<Editor plugins={plugins}
    blockRenderMap={singleLinePlugin.blockRenderMap} />

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:

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

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.