# rn-highlight-words

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

Latest version **1.1.0** (published 2019-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install rn-highlight-words
pnpm add rn-highlight-words
yarn add rn-highlight-words
bun add rn-highlight-words
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-02-01 |
| First published | 2019-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Aditya Sonel |
| Maintainers | heisenbrg |
| Keywords | react-native, react, reactjs, react-component, highlighter, highlight, text, words, matches, substring, occurrences, search |

## Links

- npm: https://www.npmjs.com/package/rn-highlight-words
- Repository: https://github.com/adityasonel/rn-highlight-words
- Issues: https://github.com/adityasonel/rn-highlight-words/issues
- npm.io page: https://npm.io/package/rn-highlight-words

## Dependencies (2)

- [prop-types](https://npm.io/package/prop-types.md) ^15.5.7
- [highlight-words-core](https://npm.io/package/highlight-words-core.md) ^1.0.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-02-01
- 1.0.2 — 2019-02-01
- 1.0.1 — 2019-02-01

## README

# RN Highlight Words

React Native component used to highlight words within a larger body of text. This is a port of [react-highlight-words](https://github.com/bvaughn/react-highlight-words).

## Changelog

-   [x] OnPress event added for Normal/Highlighted text

## Installation

Using [npm](https://www.npmjs.com/package/rn-highlight-words):

```
npm i --save rn-highlight-words
```

## Usage

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

```jsx
import Highlighter from "rn-highlight-words";

<Highlighter
    highlightStyle={{ backgroundColor: "yellow" }}
    searchWords={["and", "or", "the"]}
    textToHighlight="The dog is chasing the cat. Or perhaps they are just playing?"
    onPressNormalText={() => console.log("normal text is clickeddd!")}
    onPressHighlightedText={() => console.log("highlighted text is clickeddd!")}
/>;
```

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

<img width="368" alt="screen shot 2015-12-19 at 8 23 43 am" src="https://cloud.githubusercontent.com/assets/29597/11914033/e3c319f6-a629-11e5-896d-1a5ce22c9ea2.png">

And if you want to get highlighted text that clicked, get in `onPressHighlightedText` as

```
onPressHighlightedText = {text => console.log("highlighted text that click: " + text)}
```

## Props

| Property               | Type          | Required? | Description                                                                                                             |
| :--------------------- | :------------ | :-------: | :---------------------------------------------------------------------------------------------------------------------- |
| autoEscape             | Boolean       |           | Escape characters which are meaningful in regular expressions                                                           |
| highlightStyle         | Object        |           | Styles applied to highlighted text                                                                                      |
| sanitize               | Function      |           | Process each search word and text to highlight before comparing (eg remove accents); signature `(text: string): string` |
| searchWords            | Array<String> |     ✓     | Array of search words                                                                                                   |
| style                  | Object        |           | Styles applied to the text wrapper                                                                                      |
| textToHighlight        | String        |     ✓     | Text to highlight matches in                                                                                            |
| onPressNormalText      | Function      |           | onPress event for normal text                                                                                           |
| onPressHighlightedText | Function      |           | onPress event for highlighted text (returns text that clicked)                                                          |

## License

[MIT License](LICENSE)

---
_Source: https://npm.io/package/rn-highlight-words · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
