Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

highlightable

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

highlightable

Component that help highlighting text

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
decreased by-2.3%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 25 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc