bvaughn / react-highlight-words

React component to highlight words within a larger body of text
https://bvaughn.github.io/react-highlight-words/
MIT License
2.16k stars 170 forks source link

Multiple colors #61

Closed Chris-Gillis closed 6 years ago

Chris-Gillis commented 6 years ago

This change introduces a new prop called textColors. This new prop is a mapping of words to css classes and is used to apply these classes to the words.

For example: { the: 'green', of: 'blue', hello: 'orange' }

In the example, instances of the will have the class green applied to them instead of highlightClassName.

Note: I had trouble running the tests due to an npm install problem, probably with phantomjs. I'm happy to take some advice on that to make sure that the tests still pass, because I was unable to do that.

Chris-Gillis commented 6 years ago

I think you have some good points @bvaughn. I hadn't considered reusing the existing prop.

If you are interested in the change, I can make these changes to make it more palatable for you.

Regarding testing, I agree that it needs some new tests for this. Again if you want the change I can work on tests as well.

Thank you for reviewing my PR :)

bvaughn commented 6 years ago

No problem 😄 Thanks for the contribution and for being open to feedback.

If you make the suggested changes, and write a test or two, I'll accept the request!

Chris-Gillis commented 6 years ago

I made the changes you suggested @bvaughn. I could only think of one test case, but I'm certainly open to writing more tests if you have other cases you would like me to test for.

Chris-Gillis commented 6 years ago

I will edit the readme and push a new commit in a little bit.

bvaughn commented 6 years ago

Released as 0.12 !