@bung87/react-use-ripple
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

react-use-ripple

A react hook to implement Material Design ripple overlays

NPM JavaScript Style Guide

Demo

Edit react-use-ripple demo

Install

npm install --save react-use-ripple

Usage

useRipple only requires the ref of the DOM element that the ripple should be applied too.

import React from 'react';
import { useRipple } from 'react-use-ripple';
import { useRef } from 'react';

const App = () => {
  const ref = useRef();
  useRipple(ref);

  return (
    <button className="btn" ref={ref}>
      Button
    </button>
  );
};

export default App;

FAQ

Q. Can useRipple be used more than once in a component?
A. useRipple can be used as many times as neccessary inside a component.

Q. Can the useRipple hook be conditionally rendered?
A. No. Keep the rules-of-hooks in mind when using use useRipple and do not conditionally render it.

Q. What happens when the JSX with the ref is conditionally rendered? Will the ripple still work when the component mounts?
A. useRipple can handle null references, so if an element using a the ripple effect is conditionally rendered, the effect will applied when the component mounts.

Q. How does adding a ripple to an element affect its css?
A. useRipple does two things to an element's css:

  • If an element's position is not set (i.e. its position is initial or static) than position: relative is added to the element.
  • useRipple sets the overflow of the element to hidden, to prevent the ripple from extending outside the element.

NOTE: If your using child or descendant selectors to style span elements, it may affect the css of the ripple. To avoid this, use specificity to target span elements that you wish to style.

License

MIT © Charles Badger

Package Sidebar

Install

npm i @bung87/react-use-ripple

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

18.9 kB

Total Files

8

Last publish

Collaborators

  • bung87