react-centauro-ripple
v1.0.7
Published
A react hook to create material design ripples for components
Downloads
5
Readme
react-use-ripple
A react hook to implement Material Design ripple overlays
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
orstatic
) thanposition: relative
is added to the element. useRipple
sets the overflow of the element tohidden
, 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