1.0.2 • Published 4 years ago

@sanar/react-native-highlight-text v1.0.2

Weekly downloads
1,082
License
MIT
Repository
github
Last release
4 years ago

React Native Highlight Text

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

Installation

With npm:

npm i --save @sanar/react-native-highlight-text

With yarn:

yarn add @sanar/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 HighlightText from '@sanar/react-native-highlight-text';

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

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

Props

You can pass all Text style props like style to the Text component that is used as a wrapper.

PropertyTypeRequired?Description
searchWordsArrayArray of search words
textToHighlightStringText to highlight matches in
autoEscapeBooleanEscape characters which are meaningful in regular expressions; defaults to false
caseSensitiveBooleanSearch should be case sensitive; defaults to false
sanitizeFunctionProcess each search word and text to highlight before comparing (eg remove accents); signature (text: string): string; defaults to undefined
highlightStyleObjectStyles applied to highlighted text; defaults to undefined
textComponentComponentCustom Text component to use instead of the default Text from React Native for the text. Should be TextProps compatible; defaults to undefined
highlightComponentComponentCustom Text component to use instead of the default Text from React Native for the highlight. Should be TextProps compatible; defaults to undefined

License

MIT License