1.0.6 • Published 2 months ago

react-highlight-element v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

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.

1.0.6

2 months ago

1.0.5

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.0

2 months ago