@shhhplus/react-highlight-words
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

react-highlight-words

GitHub license npm version codecov build status

A component that can highlight words in the text with custom styles. It is a lightweight wrapper based on react-text-matcher.

If you want more customization capabilities, please use react-text-matcher.

Install

npm install @shhhplus/react-highlight-words --save

Usage

Single word

import Highlightwords from '@shhhplus/react-highlight-words';

const Demo = () => {
  return (
    <Highlightwords words="nice" style={{ color: 'green' }}>
      The weather is nice today.
    </Highlightwords>
  );
};

Multi words

import Highlightwords from '@shhhplus/react-highlight-words';

const Demo = () => {
  return (
    <Highlightwords
      words={['weather', new RegExp('nice')]}
      style={{ color: 'green' }}
    >
      The weather is nice today.
    </Highlightwords>
  );
};

Use global style

import Highlightwords from '@shhhplus/react-highlight-words';

HighlightWords.config({ color: 'green' });

const Demo = () => {
  return (
    <>
      <Highlightwords words="birthday">
        Welcome to come my birthday party.
      </Highlightwords>
      <Highlightwords words="nice">
        The weather is so nice today.
      </Highlightwords>
    </>
  );
};

Package Sidebar

Install

npm i @shhhplus/react-highlight-words

Weekly Downloads

0

Version

3.0.1

License

MIT

Unpacked Size

4.9 kB

Total Files

5

Last publish

Collaborators

  • shhhplus