1.1.35 • Published 6 years ago

react-text-highlights v1.1.35

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

React-Text-Highlights Build NPM Package

This is a React component to highlight phrases or a group of phrases within text. You can find a demo here


Installation

npm i --save react-text-highlights

Important Concept

This library allows you to highlight a variety of phrases or 'phrase sets' in any color you'd like. Even phrases that collide or overlap can be highlighted! This library priorities phrases and their highlight in order from lowest-highest.

Taking the example from below in the Usage section, phrases that are blue are the lowest priority and phrases that are red are the highest priority. Our red phrase 'highlight' will overlap the blue phrase 'highlight effect' and when you hover over the word 'highlight' red will be of highest priority and blue (or any other colliding phrases) will go transparent.

TLDR: order your phrases from lowest priority - highest priority and the component will handle collisions / overlapping, always favoring the higher priority highlights.


Usage

import '../node_modules/react-text-highlights/styles.css';
import {TextController} from 'react-text-highlights';

class App extends Component {
  
  render() {
    return (
    
  <TextController  phrases={{ 'blue':['highlight effect'], 'yellow':['text highlighting'], 'red':['highlight', 'non-highlighted'] }} 
    noWhiteSpace={true} inputField={true} textAreaCols={50} textAreaRows={5} autoStart={true} 
    defaultText="this is an example of text highlighting! some text can be highlighted and some non-highlighted. hover over phrases to isolate their highlight effect."/>

    );
  }
}

export default App;

Props

PropertyTypeRequired?Description
phrasesDictionaryyesa dictionary of phrases to highlight (priority lowest-highest)
noWhiteSpaceBooleannoSpecifies if you want additional white space around highlighted text (default false)
inputFieldBooleannoWill component display textarea for string input? (default false)
autoStartBooleannoIf true component will automatically highlight text on render (default false)
defaultTextStringnotext to be highlighted (can be modified if inputField enabled)
textAreaRowsNumbernoif inputField enabled this sets rows of the TextArea
textAreaColsNumbernoif inputField enabled this sets columns of the TextArea

License

MIT License - modify, fork, clone and use this however you want or need friends.


1.1.35

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.92

6 years ago

1.0.91

6 years ago

1.0.9

6 years ago

1.0.81

6 years ago

1.0.8

6 years ago

1.0.72

6 years ago

1.0.71

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

0.1.4

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago