react-highlight-element
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

react-hightlight-text

npm version

Highlight a keyword in a piece of text and return a React element.

image

Installation

npm i react-highlight-element

Basic Usage

import React from 'react';
import HighlightText from 'react-highlight-element';

export default function Demo() {
  return (
    <HighlightText text="This is react component" highlight="react" />
  );
}
import React, { useState, Fragment } from 'react';
import HighlightText from 'react-highlight-element';

export default function Demo() {
  const [value, setValue] = useState('react');
  return (
    <Fragment>
      <input value={value} onChange={(evn) => setValue(evn.target.value)} />
      <HighlightText text="This is react component" highlight={value} />
    </Fragment>
  );
}

Color

import React, { useState, Fragment } from 'react';
import HighlightText from 'react-highlight-element';

export default function Demo() {
  const [value, setValue] = useState('react');
  return (
    <Fragment>
      <input value={value} onChange={(evn) => setValue(evn.target.value)} />
      <HighlightText text="This is react component" highlight={value} color="red" />
    </Fragment>
  );
}

Background Color

import React, { useState, Fragment } from 'react';
import HighlightText from 'react-highlight-element';

export default function Demo() {
  const [value, setValue] = useState('react');
  return (
    <Fragment>
      <input value={value} onChange={(evn) => setValue(evn.target.value)} />
      <HighlightText text="This is react component" highlight={value} backgroundColor="white" />
    </Fragment>
  );
}

API

export interface HighlightTextI {
    text: string,
    highlight: string,
    color?: string,
    backgroundColor?: string
}

License

Licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i react-highlight-element

Weekly Downloads

5

Version

1.0.6

License

MIT

Unpacked Size

207 kB

Total Files

13

Last publish

Collaborators

  • yogameleniawan