# react-highlight-colors

> React component that allows users to select text and highlight it in whichever color they choose.

Latest version **1.0.2** (published 2020-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-highlight-colors
pnpm add react-highlight-colors
yarn add react-highlight-colors
bun add react-highlight-colors
```

## 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.0.2 |
| Published | 2020-03-05 |
| First published | 2020-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 257.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | aqualad11 |
| Maintainers | kreatore |
| Keywords | text, highlight, highlighter, colors |

## Links

- npm: https://www.npmjs.com/package/react-highlight-colors
- Repository: https://github.com/aqualad11/react-highlight-colors
- Homepage: https://github.com/aqualad11/react-highlight-colors#readme
- Issues: https://github.com/aqualad11/react-highlight-colors/issues
- npm.io page: https://npm.io/package/react-highlight-colors

## Dependencies (4)

- [webpack](https://npm.io/package/webpack.md) ^4.41.5
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [@material-ui/core](https://npm.io/package/@material-ui/core.md) ^4.9.5
- [react-text-selection-popover](https://npm.io/package/react-text-selection-popover.md) ^1.3.2

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-03-05
- 1.0.1 — 2020-03-05

## README

# react-highlight-colors

![demo](demo.gif)

React component that allows users to select text and highlight it in whichever color they choose. Uses [juliankrispel's](https://github.com/juliankrispel)  [__Selection Popover__](https://github.com/juliankrispel/react-text-selection-popover).
# Installation
```bash
npm install react-highlight-colors
```

# Usage
## Importing Component
```jsx
import Highlighter from 'react-hightlight-colors'
```

# Simplest Usage
The simplest way of getting started is by just including the component with text you want to make highlightable.
```jsx
<Highlighter text={yourText} />
```


## Exporting Highlighted Text
If you wanna store the highlighted data you must pass in a callback function to the `export` prop.

Here is one way of using the export prop:
```jsx
<Highlighter text={yourText} export={(highlightedText) => {
  this.setState({
    exportedText: highlightedText
  })
}} />
```

## Importing Highlighted Text
Once you have exported your text and want to import it back to your Highlighter component, just set the `import` prop to `True`.

## Colors
### Format
In order to choose colors for the highlighter component you must pass in a list of color strings in one of the following formats:
```
'#FFF'
'#FFFFFF'
'rgb(255,255,255)'
```

### Color List
Here is an example of how you can pass in a list of colors.
```jsx
const chosenColors = [
 '#B80000', 
 '#DB3E00', 
 '#008B02', 
 '#FC0',
 'rgb(109,163,182)'
]
```

```jsx
<Highlighter text={yourText} colors={chosenColors} />
```

This is the result of the code above.

![Unlabeled Colors](unlabeledColors.png)

### Labeled Colors
You can add labels to your colors, by modifying the list of colors and adding the label after each color in its own list.

Here is an example of a color list with labels:
```jsx
const labeledColors = [
  ['#B80000', 'Label 1'], 
  ['#DB3E00',  'Label 2'],
  ['#008B02'  'Label 3'],
  ['#FC0', 'Label 4'],
  ['rgb(109,163,182)', 'Label 5'],
]
```

```jsx
<Highlighter text={yourText} colors={labeledColors} />
```

Result:

![Labeled Colors](labeledColors.png)


# Props
| Property | Type | Is Required | Default Value | Description |
| - | - | - | - | - |
| `text` | `PropTypes.string` | `required` | n/a | The text that will be highlightable. |
| `style` | `PropTypes.object` | optional | `null` | CSS style applied to text. |
| `colors` | `PropTypes.array` | optional | `['#B80000', '#DB3E00', '#FCCB00', '#008B02', '#006B76', '#1273DE', '#004DCF', '#5300EB', '#EB9694', '#FAD0C3', '#FEF3BD', '#C1E1C5', '#BEDADC', '#C4DEF6', '#BED3F3', '#D4C4FB']` | Color options for the highlighter. |
| `export` | `PropTypes.func` | optional | `null` | Callback function that passes the exported format of the text. Callback is called each time text is highlighted. |
| `import` | `PropTypes.bool` | optional | `false` | Boolean variable which determines if the text being passed in is imported. Text must be exported before being able to import it. |
| `cols` | `PropTypes.number` | optional | `8` | Number of columns of colors per row in color popover. |

# License
MIT © [Jonathan](https://github.com/aqualad11)

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