Skip to content

Instantly share code, notes, and snippets.

@Temzasse
Created April 27, 2017 13:33
Show Gist options
  • Save Temzasse/fe49eb042e69190499787ac9f99c9dba to your computer and use it in GitHub Desktop.
Save Temzasse/fe49eb042e69190499787ac9f99c9dba to your computer and use it in GitHub Desktop.
A Higher-Order React component that provides the Material Design ripple effect.
import React, { Component } from 'react';
import styled from 'styled-components';
const RippleWrapper = styled.div`
position: relative;
overflow: hidden;
transform: translate3d(0, 0, 0);
&:after {
content: "";
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
pointer-events: none;
background-image: radial-gradient(circle, #000 10%, transparent 10.01%);
background-repeat: no-repeat;
background-position: 50%;
transform: scale(10,10);
opacity: 0;
transition: transform .5s, opacity 1s;
}
&:active:after {
transform: scale(0,0);
opacity: .2;
transition: 0s;
}
`;
const withRipple = (Comp) => {
return class RippleProvider extends Component {
render() {
return (
<RippleWrapper>
<Comp {...this.props} />
</RippleWrapper>
);
}
};
};
export default withRipple;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment