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

useripple

v1.0.4

Published

A React Hook for adding ripple effect

Downloads

184

Readme

About

useRipple is a React Hook that adds an animated ripple effect to a clicked element.

Usage

Step 1 - install the module

npm install useripple

Step 2 - add CSS keyframes
@keyframes useRippleAnimation {
  to {
    transform: scale(15);
    opacity: 0;
  }
}

☝️This is the animation that ripples use to ripple. It makes them grow and then disappear. Tweak it however you want and add to your stylesheet.

Step 3 - add the Hook
import React from 'react'
import useRipple from 'useripple'

function App() {
  const [
    addRipple, // Attach this to any mouse event listener
    ripples // Render this to see the ripples
  ] = useRipple({
    // You can pass ripples` CSS here (no worries, it's optional)
    background: 'pink'
  })

  // Look how simple it is!
  return (
    <div onClick={addRipple} style={{ position: 'relative', overflow: 'hidden' }}>
      {ripples}
      Look at them ripplin'!
    </div>
  )
}

FAQ

Q: Where should I attach addRipple?
A: Any MouseEvent listener will do, but your first bet is onClick, onMouseDown or onMouseUp.

Q: What if I want to do something more in my mouse event handler than just add ripples?
A: That's simple! Instead of doing <div onClick={addRipple}> do <div onClick={handleClick}> and then declare handleClick function:

function handleClick(event) {
  console.log("I'm gonna ripple!") // 👈 Do anything you want here
  addRipple(event) // Don't forget to feed `addRipple` with `event` 👌
}

Q: What is ripples variable?
A: It's an array that gets filled with ripple components anytime you call addRipple function with a valid MouseEvent. Each ripple is an absolutely positioned <div>, so make sure their container has position: relative; or something other than default static (overflow: hidden; may come in handy too).

Q: What styles can I attach to ripples?
A: Anything that's valid in React terms. See here what styles do ripples use. These are probably the ones you may want to override. If you want to override animationName, make sure you change it in Step 2 as well.

Enjoy! 💙

npm version Bundle size GitHub license