npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-multi-highlite

v2.0.3

Published

React multi highlite component for text

Downloads

11

Readme


Demo

Check out the live demo here.

Demo

react-multi-highlite

react-multi-highlite is a lightweight React component that allows you to highlight specific words or phrases within a block of text. This component is very lightweight as it doesn't use highlight.js or lowlight and doesn't include bulky coding languages. It's a basic text highlighter designed to be simple and efficient.

Why 'Lite'?

react-multi-highlite is designed to be lightweight and efficient. It doesn't bring in large dependencies, making it ideal for projects where performance and bundle size are critical considerations.

Installation

You can install the library using npm, Yarn, pnpm, or Bun:

npm

npm install react-multi-highlite

Yarn

yarn add react-multi-highlite

pnpm

pnpm add react-multi-highlite

Bun

bun add react-multi-highlite

Usage

To use the MultiHighLite component, import it and pass the text you want to highlight along with an array of matcher objects. Each matcher object should contain the text to highlight and the class name to apply to the highlighted text.

import React from 'react';
import MultiHighLite from 'react-multi-highlite';

const App = () => {
  const text = "In software development, highlighting important pieces of information can greatly improve readability and comprehension. For instance, highlighting code snippets, errors, or important notes in documentation can make a significant difference.";
  const matchers = [
    { text: "highlighting", classname: "bg-red-200 text-black" },
    { text: "important", classname: "bg-green-300 text-black" },
    { text: "information", classname: "bg-gray-600 text-white" },
  ];

  return (
    <div>
      <MultiHighLite matchers={matchers}>{text}</MultiHighLite>
    </div>
  );
};

export default App;

Props

MultiHighLite

The MultiHighLite component accepts the following props:

  • children: The text to search for matches (required).
  • matchers: Array of matcher objects containing text and classname (required).
    • text: The text to match and highlight.
    • classname: The class name to apply to the highlighted text.
  • className: The class name of the entire line div (optional).
  • caseSensitive: (optional) Whether the matching should be case-sensitive. Defaults to false.
  • wrapperElement: (optional) Custom wrapper element for the highlighted text. This should be a function that returns a React element.

Examples

Basic Usage

import React from 'react';
import BasicUsage from '~/components/BasicUsage';

export default function HomePage() {
  return (
    <main className="flex flex-col items-center justify-center bg-[#f0f4f8] text-gray-800 space-y-8 p-6 min-h-screen">
      <section className="w-full max-w-3xl">
        <BasicUsage />
      </section>
    </main>
  );
}

Dynamic Highlighting

import React, { useState } from 'react';
import DynamicHighlighting from '~/components/DynamicHighlighting';

export default function HomePage() {
  return (
    <main className="flex flex-col items-center justify-center bg-[#f0f4f8] text-gray-800 space-y-8 p-6 min-h-screen">
      <section className="w-full max-w-3xl">
        <DynamicHighlighting />
      </section>
    </main>
  );
}

Case-Sensitive Highlighting

import React from 'react';
import CaseSensitiveHighlighting from '~/components/CaseSensitiveHighlighting';

export default function HomePage() {
  return (
    <main className="flex flex-col items-center justify-center bg-[#f0f4f8] text-gray-800 space-y-8 p-6 min-h-screen">
      <section className="w-full max-w-3xl">
        <CaseSensitiveHighlighting />
      </section>
    </main>
  );
}

Custom Wrapper Element

import React from 'react';
import CustomWrapperElement from '~/components/CustomWrapperElement';

export default function HomePage() {
  return (
    <main className="flex flex-col items-center justify-center bg-[#f0f4f8] text-gray-800 space-y-8 p-6 min-h-screen">
      <section className="w-full max-w-3xl">
        <CustomWrapperElement />
      </section>
    </main>
  );
}

License

MIT