Code Monkey home page Code Monkey logo

react-highlight's Introduction

Build Status

Highlight component for ReactJS

ReactJS component that help you highlight ranges of text and give you callbacks to detect user text selection.

Installation

  npm install highlightable

Features

  • Pass ranges and the component will highlight the text for you
  • Callback function that give you the start and end of the user highlited text
  • Customisable renderRange function that allow you to add tooltip on the top of user selection for exemple
  • Convert url string into link

Getting started

<Highlightable ranges={ranges}
               enabled={true}
               onTextHighlighted={onTextHighlightedCallback}
               id={uniqueId}
               onMouseOverHighlightedWord={onMouseOverHighlightedWordCallback}
               highlightStyle={{
                 backgroundColor: '#ffcc80'
               }}
               text={'text'}
/>

Props:

  • ranges -> array: of Range objects (see Range object below).

  • text -> string: the all text that the user can highlight.

  • enabled -> bool: The user can't highlight text if false.

  • onMouseOverHighlightedWord -> func: Callback function when the user mouse is over an highlighted text. (range) => {}

  • onTextHighlighted -> func: Callback function when the user highlight new text. (range) => {}

  • highlightStyle -> obj: Style of the text when the text is highlighted.

  • style -> obj: The style of the main div container

  • rangeRenderer -> func: Use this function to customise the render of the highlighted text. (currentRenderedNodes, currentRenderedRange, currentRenderedIndex, onMouseOverHighlightedWord) => {return node}

Range object:

The range object attributes:

  • start -> int: the index of the character where the range start.
  • end -> int: the index of the character where the range stop.
  • text -> string: the highlighted text.
  • data -> object: extra data (the props of the highlight component)

Development

  • npm run build - produces production version
  • npm run dev - produces development version
  • npm test - run the tests

react-highlight's People

Contributors

ydeshayes avatar chops318 avatar

Watchers

James Cloos 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.