GithubHelp home page GithubHelp logo

vadko / draft-js-multi-inline-highlight Goto Github PK

View Code? Open in Web Editor NEW

This project forked from buchslava/draft-js-multi-inline-highlight

0.0 0.0 0.0 916 KB

License: MIT License

JavaScript 70.53% TypeScript 29.47%

draft-js-multi-inline-highlight's Introduction

Multi-inline highlighting for DraftJS editor

Allows to do multi selections in DraftJS editor via a custom decorator.

The source for full demo example is here. Also, you can try working example.

Install

npm i draft-js-multi-inline-highlight

or

yarn add draft-js-multi-inline-highlight

Usage

Import

import {
  MultiHighlightDecorator,
  WordMatcher,
  SentenceMatcher,
  MultiHighlightConfig,
} from "draft-js-multi-inline-highlight";

Configuration

const initHighlightConfig: MultiHighlightConfig = {
  rules: [
    {
      content: ["His back begins to ache, but he knows he can bear it."],
      style: "yellow",
      matcher: SentenceMatcher,
    },
    {
      content: ["and"],
      style: "red",
      matcher: WordMatcher,
    },
    {
      content: ["pulled", "knows"],
      style: "blue",
      matcher: WordMatcher,
    },
  ],
  styles: hightlightStyles,
};

Initialization

const [highlightConfig, setHighlightConfig] = useState<MultiHighlightConfig>(
  initHighlightConfig
);
const [editorState, setEditorState] = useState(
  EditorState.createWithContent(
    contentState,
    MultiHighlightDecorator(highlightConfig)
  )
);

Chage highlighting state according to the new configuration

useEffect(() => {
  if (highlightConfig) {
    setEditorState(
      EditorState.set(editorState, {
        decorator: MultiHighlightDecorator(highlightConfig),
      })
    );
  }
}, [highlightConfig]);

draft-js-multi-inline-highlight's People

Contributors

buchslava avatar vadko 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.