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-toggle

v0.1.0-alpha.10

Published

Track toggle state in Redux

Downloads

25

Readme

redux-toggle

redux-toggle is a portal for hover and click events.

What can this be used for?

  • Tooltips

    When the user hovers an element, you want the tooltip to appear. Wrap the element with a <Toggleable showOnHover /> and wrap the tooltip with a <ToggleEffect />.

  • Dropdowns

    When the user clicks a button, you want a panel to appear. Wrap the button with a <Toggleable toggleOnClick /> and wrap the panel with a <ToggleEffect />.

  • Modals

    When the user clicks a button, you want a modal to appear. Wrap the button with a <Toggleable showOnClick /> and wrap the modal with a <ToggleEffect />. Inside the <ToggleEffect />, wrap the modal close button with a <Toggleable hideOnClick />.

  • Charts

    Let's say you have a line chart. When the user hovers a point in the line, you want to increase the size of the point and highlight the related date. Wrap the point with a <Toggleable showOnHover /> and <ToggleEffect /> and wrap the date with a <ToggleEffect />.

The basic idea is to take the idea of CSS :hover and allow it to work on distant components.

Demo

Try it

Usage

import {
  reducer as toggleReducer,
  Toggleable,
  ToggleEffect,
} from 'redux-toggle';

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

// Tooltip example
// Group identifies a group of ids that are exclusive.
// In this case, we only want a single tooltip to appear at a time (all tooltip ids are exclusive).
// So all tooltips belong to a single group.
<Toggleable
  group="tooltip"
  id="tooltip"
  showOnHover
>
  <div>
    Hover me
  </div>
</Toggleable>

// The child is shown or hidden based on whether the Toggleable is hovered.
<ToggleEffect
  group="tooltip"
  id="tooltip"
>
  <div>
    Tooltip
  </div>
</Toggleable>

// There are a number of options available for triggering the toggle.
// To trigger the toggle when the user hovers the Toggleable, use showOnHover. This is useful for a tooltip.
// To flip the toggle when the user clicks the Toggleable, use toggleOnClick. This is useful for a dropdown button.
// To set the toggle when the user hovers the Toggleable, use showOnClick. This is useful for a modal open button.
// To unset the toggle when the user hovers the Toggleable, use hideOnClick. This is useful for a modal close button.
<Toggleable
  showOnHover
  toggleOnClick
  showOnClick
  hideOnClick
>
  {/* ... */}
</Toggleable>

// If you want more control over the child, pass a function as the child.
// This allows you to set conditional styles on the child based on whether the Toggleable is hovered.
<ToggleEffect
  group="tooltip"
  id="tooltip"
>
  (({ active }) => (
    <div>
      {active ? 'It is active' : 'It is not active'}
    </div>
  ))
</Toggleable>

// You can pass custom data from a source Toggleable to a destination ToggleEffect.
// The custom data will be spread onto the ToggleEffect child's props.
// If you want to populate the ToggleEffect child with Redux, you can use data to pass ids, then use Redux to look up the full objects from the state based on these ids.
<Toggleable
  data={{ userId: 1 }}
  group="modal"
  id="modal"
  showOnClick
>
  <div>
    Click me
  </div>
</Toggleable>

<ToggleEffect
  group="modal"
  id="modal"
>
  <Modal />
</Toggleable>

function Modal({ userId }) {
  return (
    <div>
      The user is {userId}.
    </div>
  );
}

// Let's say you have multiple Toggleables but one ToggleEffect (for example, different items in a list can trigger the same edit modal).
// In the Toggleable, pass different data for different items.
// In the ToggleEffect, omit the id.
// In the modal, you will receive the data for the item that triggered the modal. This allows you to determine which item the user is editing.
<ToggleEffect group="modal">
  <Modal />
</Toggleable>

Setup

yarn
yarn start
# Visit http://localhost:8080