test(button): add testcase

This commit is contained in:
unix
2020-04-15 21:56:54 +08:00
parent 3f2957de65
commit 30c66c997b
4 changed files with 173 additions and 3 deletions

View File

@@ -2,8 +2,8 @@ import React, { useEffect, useRef } from 'react'
import withDefaults from '../utils/with-defaults'
interface Props {
x?: number
y?: number
x: number
y: number
color?: string
onCompleted?: Function
}
@@ -20,10 +20,17 @@ const ButtonDrip: React.FC<ButtonDrip> = React.memo(({
x, y, color, onCompleted
}) => {
const dripRef = useRef<HTMLDivElement>(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)
}
@@ -32,7 +39,7 @@ const ButtonDrip: React.FC<ButtonDrip> = React.memo(({
return (
<div ref={dripRef} className="drip">
<svg width="20" height="20" viewBox="0 0 20 20"
style={{ top: y - 10, left: x - 10 }}>
style={{ top, left }}>
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
<g fill={color}><rect width="100%" height="100%" rx="10" /></g>
</g>