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-click-handler

v1.0.7

Published

A React component that helps assign and remove focus to components based on click events.

Downloads

5

Readme

react-click-handler NPM version

A React wrapper component that helps assign and remove focus to components based on click events.

Often, it is necessary to apply styling rules to a page based on where the user has clicked. React-click-handler can be used to wrap any component and track the ‘focus’ of any of its child components, by setting a corresponding variable on its state at the exclusion of other tracked components.

For example:

const pageClickSelectors = [
    {
        selector: '#first-component',
        focusState: 'firstComponentFocussed',
        toggle: true,
        sideEffect: false
    },
    {
        selector: '#second-component',
        focusState: 'secondComponentFocussed',
        toggle: false,
        sideEffect: false
    }
];

<ReactClickHandler
    wrapperClass={'page-wrapper'}
    parentState={this.state}
    setParentState={this.setState}
    selectors={pageClickSelectors}
>
    <div id={'first-component'} className={this.state.firstComponentFocussed && 'open'}></div>
    <div id={'second-component'} className={this.state.secondComponentFocussed && 'open'}></div>
</ReactClickHandler>

Clicking on the first div will set its corresponding focus state variable to true and ensure that the second div's focus state variable is false.

PageClickSelectors

In addition to a classname to apply to the wrapper, and the state and setState methods of your parent component, this wrapper component expects to receive an array of selector objects of the form:

{
    selector: // a STRING representing, in CSS selector syntax, the element we want to attach a focus handler on
    focusState: // a STRING indicating the state property that deals with this elements focus
    toggle: // a BOOLEAN indicating whether this element toggles focus, or just sets it
    sideEffect: // an optional FUNCTION to be called when this element is clicked
}

When a click event occurs, this component calls the given handlers for the selector that is closest in the DOM tree to the event source. The associated focus property on the parent state (boolean) is either toggled or set to true. All other focus properties on the page are set to false.