Skip to content

Instantly share code, notes, and snippets.

@DmitryOlkhovoi
Created January 21, 2020 10:51
Show Gist options
  • Save DmitryOlkhovoi/237c1437634766187a0938e0040e4bcc to your computer and use it in GitHub Desktop.
Save DmitryOlkhovoi/237c1437634766187a0938e0040e4bcc to your computer and use it in GitHub Desktop.
function onRippleClick(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
var rect = event.currentTarget.getBoundingClientRect();
const d = Math.max(event.currentTarget.clientWidth, event.currentTarget.clientHeight);
const left = event.clientX - rect.left - d/2 + 'px';
const top = event.clientY - rect.top - d/2 + 'px';
const rippleElement = newRippleElement(d, left, top);
setRippleElements([...rippleElements, rippleElement]);
}
function newRippleElement(d: number, left: string, top: string) {
const key = uuid();
return (
<div
key={key}
className="ripple"
style={{width: d, height: d, left, top}}
onAnimationEnd={() => onAnimationEnd(key)}
>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment