40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import clsx from 'clsx';
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import styles from './style.module.scss';
|
|
import { RippleWaveProps } from './types';
|
|
|
|
export function RippleWave({ style, onDone }: RippleWaveProps) {
|
|
const [isMouseUp, setIsMouseUp] = useState(false);
|
|
const [isAnimationEnd, setIsAnimationEnd] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const mouseUpListener = () => setIsMouseUp(true);
|
|
document.addEventListener('mouseup', mouseUpListener, { once: true });
|
|
document.addEventListener('touchend', mouseUpListener, { once: true });
|
|
}, []);
|
|
|
|
const visible = !isMouseUp || !isAnimationEnd;
|
|
|
|
const className = clsx(
|
|
styles.wave,
|
|
visible ? styles.visible : styles.invisible,
|
|
);
|
|
|
|
const handleAnimationEnd = (event: React.AnimationEvent) => {
|
|
if (event.animationName === styles.fadein) {
|
|
setIsAnimationEnd(true);
|
|
} else {
|
|
onDone();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div
|
|
className={className}
|
|
onAnimationEnd={handleAnimationEnd}
|
|
style={style}
|
|
/>
|
|
);
|
|
}
|