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

redux-hover

v0.1.0-alpha.3

Published

Track hover state in Redux

Downloads

2

Readme

redux-hover

Why store hover state in Redux?

Let's say you have a line chart and a table, and when the user hovers over a table cell, you want to highlight the related point. We can do this with redux-hover.

function Chart() {
  return (
    <g>
      <HoverEffect id="example">
        {show => (
          <circle
            className={classNames(
              styles.point,
              show && styles['point--highlight']
            )}
          />
        )}
      </HoverEffect>
    </g>
  );
}

function Table() {
  return (
    <table>
      <tbody>
        <tr>
          <Hoverable id="example">
            <td>
              Table cell
            </td>
          </Hoverable>
        </tr>
      </tbody>
    </table>
  );
}

Hoverable and HoverEffect are Redux containers.

  • Hoverable attaches mouseenter and mouseleave listeners to its child.
  • HoverEffect shows or hides its child based on whether the user is currently hovering the related Hoverable.

The nice thing about this model is that a single Hoverable can trigger any number of related HoverEffects. For example, let's say the chart is split into two views of the same data. You can use two HoverEffects to highlight the related data point in each view.

This library also supports toggles (when a component is clicked, the flag is flipped). This is useful for things like dropdowns and inline dialogs. The API for hovers and toggles is very similar.

Usage

import { Hoverable, HoverEffect, reducer, Toggleable, ToggleEffect } from 'redux-hover';

// configureStore
const reducer = combineReducers({
  hover: reducer,
});

// hover trigger
<Hoverable id="hover">
  <div>
    Hover me
  </div>
</Hoverable>

// hover effect (pass flag to child function)
<HoverEffect id="hover">
  {show => (
    <div
      style={{ opacity: show ? 1 : 0.5 }}
    >
      Hover effect
    </div>
  )}
</HoverEffect>

// hover effect (show or hide child)
// If HoverEffect's child is a function, the hover state is passed to the child as a flag. This is the most flexible option.
// If HoverEffect's child is a node, the child is shown or hidden based on the hover state. This can be used to implement tooltips.
<HoverEffect id="tooltip">
  <div>
    Tooltip
  </div>
</HoverEffect>

// toggle trigger
<Toggleable id="dropdown">
  <div>
    Dropdown button
  </div>
</Toggleable>

// toggle effect
<ToggleEffect id="dropdown">
  <div>
    Dropdown panel
  </div>
</ToggleEffect>

Setup

npm install
npm start
# Visit http://localhost:8080