Skip to content

Commit ed60af5

Browse files
committed
docs(api): create lib doc
update README with lib installation, setup and APIs
1 parent e17090a commit ed60af5

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
11
# react-highlight-pop
2+
> React component for "medium-like" text highlight
3+
4+
[![](https://img.shields.io/npm/v/react-highlight-pop.svg?style=popout)](https://www.npmjs.com/package/react-highlight-pop)
25
[![](https://img.shields.io/travis/codeshifu/react-highlight-pop.svg?style=popout)](https://travis-ci.org/codeshifu/react-highlight-pop)
36
[![](https://img.shields.io/coveralls/github/codeshifu/react-highlight-pop.svg?style=popout)](https://coveralls.io/github/codeshifu/react-highlight-pop)
7+
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8+
9+
A configurable text highlight component with zero dependencies.
10+
11+
## Installation
12+
```bash
13+
npm install react-highlight-pop
14+
```
15+
16+
## Usage
17+
1. Import/require `react-highlight-pop` after installation
18+
```javascript
19+
import HighlightPop from 'react-highlight-pop';
20+
```
21+
or
22+
```javascript
23+
const HighlightPop = require('react-highlight-pop');
24+
```
25+
2. Wrap the text you want to be highlightable with `react-highlight-pop`
26+
```javascript
27+
const App = () => {
28+
return (
29+
<HighlightPop>
30+
<p>You can highlight me</p>
31+
<p>I will show a popover when you highlight me</p>
32+
</HighlightPop>
33+
)
34+
}
35+
```
36+
37+
### Custom popover items
38+
You can define custom popover items by defining the `popoverItems` prop, whose value is a function that returns jsx.
39+
40+
NOTE: You should always pass your custom popover items.
41+
42+
Example
43+
```javascript
44+
const App = () => {
45+
return (
46+
<HighlightPop
47+
popoverItems={itemClass => (
48+
<Fragment>
49+
<span
50+
className={itemClass} onClick={() => alert('sharing')}>
51+
share
52+
</span>
53+
</Fragment>
54+
)}>
55+
<p>You can highlight me</p>
56+
<p>I will show a popover when you highlight me</p>
57+
</HighlightPop>
58+
)
59+
}
60+
```
61+
62+
# API
63+
## Props
64+
prop|value|description
65+
---|---|---
66+
popoverItems|function| A function that returns jsx. Returned jsx display as popover items when a text is highlighted.
67+
onHighlightPop|function| Callback function that's invoked whenever a text is highlighted.
68+
children|node| The text/group of text that's highlightable
69+
70+
## Contributing
71+
1. Fork the repo
72+
2. Create your feature branch (`git checkout -b my-awesome-feature`)
73+
3. Make changes to the lib file `src/lib/index.js`
74+
4. Write test for changes/features added in `__tests__/HighlightPop.test.js`
75+
5. Commit your changes (`git commit -am 'Awesome feature added'`)
76+
6. Push to the branch (`git push origin my-awesome-feature`)
77+
7. Raise a Pull Request
478

5-
React component for "medium-like" text highlight
79+
## License
80+
[MIT](https://github.com/codeshifu/react-highlight-pop/blob/master/LICENSE.md)

0 commit comments

Comments
 (0)