1.0.6 • Published 7 years ago

react-annotated-paragraph v1.0.6

Weekly downloads
37
License
-
Repository
github
Last release
7 years ago

react-annotated-paragraph

React component that displays annotations on a text.

Installation

You can install react-annotated-paragraph from npm:

npm install --save react-annotated-paragraph

Dependencies

react-annotated-paragraph depends on:

Usage

Import the component:

import Paragraph from 'react-annotated-paragraph'

Render it like this:

<Paragraph
  paragraph={{
    text: "Hello World!",
    annotations: [
      { offset: 6, length: 5, tooltip: "Welt" }  // 'offset' and 'length', required.
    ]
  }}
  tooltipRenderer={ mySimpleRenderer } />

tooltipRenderer specifies a function that returns the text for the tooltip (explanation) and the content to highlight (highlighted, so you can format it).

/*
 * 'text': the whole text, 'Hello World!'
 * 'annotation': { offset: 6, length: 5, tooltip: "Welt" }
 */
const mySimpleRenderer = (text, annotation) => {
  let explanation = annotation.tooltip
  let highlighted = text.substr(annotation.offset, annotation.length);
  return {
    explanation,
    highlighted
  }
}

More

Please see the project on Github to play a demo that uses the component.

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago