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

babel-plugin-react-add-cursor-pointer

v1.0.0

Published

This babel plugin styles any enabled JSX element that has an onClick prop with cursor: pointer.

Downloads

11

Readme

babel-plugin-react-add-cursor-pointer

This babel plugin styles any enabled JSX element that has an onClick prop with cursor: pointer.

The problem

As your project grows, styling each and every clickable element with a repeating cursor: pointer can become a tedious task.

The solution

This plugin will style all of your enabled clickable elements with cursor: pointer automatically.

Getting started

Installation

Install the plugin:

$ npm install --save-dev babel-plugin-react-add-cursor-pointer

Usage

via .babelrc

Add "react-add-cursor-pointer" to "plugins" in your .babelrc:

"plugins": ["react-add-cursor-pointer"]

via package.json

Add "react-add-cursor-pointer" to "babel": { "plugins": [] } inside your package.json. It should end up looking something like the following:

 "babel": {
    "plugins": ["react-add-cursor-pointer"]
 }

How does it work?

  • This babel plugin visits any JSX element you have in your code and checks if it has an onClick prop.
  • If it does, the plugin then checks if the value of the onClick prop is a function (e.g. arrow function, class method, function declaration...) or an identifier.
  • If the onClick prop passes this check, then the plugin will add a data-react-add-cursor-pointer__is-clickable-element attribute to the element.
  • If the onClick prop doesn't pass the function or identifier check, no attribute is added to the element.
  • At the entry point of your program (e.g. your App.js or index.js file), the plugin will add an import declaration for css file that looks like this:
[data-react-add-cursor-pointer__is-clickable-element] {
    cursor: pointer;
}

:disabled {
    cursor: auto;
}
  • This will style all of the elements that got injected with the data attribute.
  • The cursor for any elements that are disabled at the moment will be reset back to auto.
  • You can easily override the plugin's styles with a single class and style your element with a different cursor if need be.

Example

Your clickable element:

In

class Button extends Component {
    handleClick = () => {};
    
    render() {
        return (
            <button onClick={this.handleClick}>
                I have an onClick prop
            </button>
        );
    }
}

Out

class Button extends Component {
    handleClick = () => {};
    
    render() {
        return (
            <button onClick={this.handleClick} data-react-add-cursor-pointer__is-clickable-element>
                I have an onClick prop
            </button>
        );
    }
}

Your app's entry point:

In

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";

ReactDOM.render(<App />, document.getElementById("root"));

Out

import "babel-plugin-react-add-cursor-pointer/index.min.css";
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";

ReactDOM.render(<App />, document.getElementById("root"));

License

MIT, see LICENSE for details.