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-change-highlight

v1.3.1

Published

React component to highlight the changed content immediately and bring focus of the user into the changed part

Downloads

3,036

Readme

react-change-highlight

All Contributors GitHub license npm version PRs Welcome

React Change Highlight is a react component to highlight changes in the wrapped component to enhance the UX and grab the focus of the user into the changed value of some parts like the cart in an e-commerce application for example.

This is a real use case I'm using in a project UseCase

You can play around with it on this sandbox codesandbox.io/react-change-highlight .. or clone the repo and play around with the all examples in the examples folder

Install

yarn add react-change-highlight

or

npm install react-change-highlight

Usage

Basically you need to wrap the components you want to highlight on change inside ChangeHighlight element (default import) then add ref attribute to each child in this component which you want to highlight when they got their content changed.

In the following example the count variable comes from state, so when ever that function setCount() is called with any different value the background of that wrapped div will be changed as a default action, but actually it can be any kind of animation you make into the class you will pass to highlightStyle attribute.

import ChangeHighlight from "react-change-highlight";

export default () => {
  const [count, setCount] = useState(0);

  return (
    <ChangeHighlight>
      <div ref={React.createRef()}>{count}</div>
    </ChangeHighlight>
  );
};

Default styling for highlighting in case the user didn't use a custom styling using the highlightStyle property is rc-highlight class and it is as follow:

.rc-highlight {
  background-color: #f8ffb4;
  transition: all 0.5s ease-in-out;
}

SSR (server-side rendering)

In case of using this module in a server-side rendering app, you should make sure to create and pass your own className to the highlightStyle attribute, and to make some hint for you, add ssr attribute to the ChangeHighlight element, so it can give you a hint to add a class in your console as a warning like this.

⚠️ "react-change-highlight", As you're using server-side rendering, it's a must to create and pass your css class to the highlightStyle attribute for "ChangeHighlight" component

Props

| Property | Type | Default | Descriptio| | -------------------- | ------- | ------- | --------------------------------------------------------- | | showAfter | number | 500 | number of milli seconds before start highlighting| | hideAfter | number | 2500 | number of milli seconds before ending highlighting| | mode | change or newOnly |change| mode of the detection, either change which is the default one to detect the changes in the parsed elements or newOnly which is useful in case of newly added element highlight (check todo example) | | disabled | boolean | false | whether you need to disable highlighting | | ssr | boolean | false | you need to pass this in case of using it with server-side rendering. (gives a hint for adding style) | | highlightClassName | string | | className for highlighing content (a must in case of SSR)| | containerClassName | string | | className for component container |


Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!