import React, { useEffect, useRef } from 'react' import withDefaults from '../utils/with-defaults' interface Props { x: number y: number onCompleted: () => void color: string } const defaultProps = { x: 0, y: 0, } export type ButtonDrip = Props & typeof defaultProps const ButtonDrip: React.FC = ({ x, y, color, onCompleted }) => { const dripRef = useRef(null) /* istanbul ignore next */ const top = Number.isNaN(+y) ? 0 : y - 10 /* istanbul ignore next */ const left = Number.isNaN(+x) ? 0 : x - 10 useEffect(() => { /* istanbul ignore next */ if (!dripRef.current) return dripRef.current.addEventListener('animationend', onCompleted) return () => { /* istanbul ignore next */ if (!dripRef.current) return dripRef.current.removeEventListener('animationend', onCompleted) } }) return (
) } const MemoButtonDrip = React.memo(ButtonDrip) export default withDefaults(MemoButtonDrip, defaultProps)