1.0.0 • Published 6 years ago

@bam.tech/react-native-text-highlight v1.0.0

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

React Native Highlight Text

React Native component used to highlight words within a larger body of text. This is a fork of react-native-highlight-words which is a port of react-highlight-words.

Installation

Using npm:

yarn add @bam.tech/react-native-highlight-text

Usage

To use it, just provide it with an array of search terms and a body of text to highlight:

import HighlighText from 'r@bam.tech/react-native-highlight-text';

<HighlighText
  highlightStyle={{backgroundColor: 'yellow'}}
  searchWords={['and', 'or', 'the']}
  textToHighlight='The dog is chasing the cat. Or perhaps they're just playing?'
/>

And the HighlighText component will highlight all occurrences of search terms within the text:

Props

PropertyTypeRequired?Description
autoEscapeBooleanEscape characters which are meaningful in regular expressions
styleObjectStyles applied to the text wrapper
sanitizeFunctionProcess each search word and text to highlight before comparing (eg remove accents) signature (text: string): string
searchWordsArrayArray of search words
textToHighlightStringText to highlight matches in
highlightStyleObjectStyles applied to highlighted text
secondarySearchWordsArrayXArray of search words for a secondary kind of highlights
secondaryHighlightStyleObjectXStyles applied to the text wrapper for a secondary kind of highlights
secondaryTextToHighlightStringXText to highlight matches in for a secondary kind of highlights

License

MIT License - fork, modify and use however you want.