forked from shapeshift/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedCheck.tsx
More file actions
76 lines (71 loc) · 1.91 KB
/
AnimatedCheck.tsx
File metadata and controls
76 lines (71 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import type { BoxProps } from '@chakra-ui/react'
import { Box } from '@chakra-ui/react'
import { motion } from 'framer-motion'
import { useMemo } from 'react'
export const AnimatedCheck = ({
defaultDuration = 1000,
boxSize = 24,
color = 'green.500',
}: {
defaultDuration?: number
boxSize?: BoxProps['boxSize']
color?: BoxProps['color']
}) => {
const placeholderDuration = useMemo(() => defaultDuration / 1000 + 2, [defaultDuration])
const draw = useMemo(() => {
const drawDelay = placeholderDuration / 1.5 > 10 ? 5 : placeholderDuration / 1.5
return {
hidden: { pathLength: 0, opacity: 0 },
visible: () => ({
pathLength: 1,
opacity: 1,
transition: {
pathLength: {
delay: drawDelay,
type: 'spring',
duration: 2,
bounce: 0,
},
opacity: { delay: drawDelay, duration: 2 },
},
}),
}
}, [placeholderDuration])
const border = useMemo(() => {
return {
hidden: { pathLength: 0 },
visible: () => ({
pathLength: 1,
transition: {
pathLength: {
type: 'spring',
duration: placeholderDuration > 10 ? 10 : placeholderDuration,
bounce: 0,
},
},
}),
}
}, [placeholderDuration])
return (
<Box boxSize={boxSize} color={color}>
<motion.svg
xmlns='http://www.w3.org/2000/svg'
width='100%'
height='100%'
viewBox='0 0 24 24'
fill='none'
stroke='currentColor'
strokeWidth='1.5'
strokeLinecap='round'
strokeLinejoin='round'
initial='hidden'
animate='visible'
>
{/* Outer circle */}
<motion.path d='M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0' variants={border} />
{/* Checkmark */}
<motion.path d='M9 12l2 2l4 -4' variants={draw} />
</motion.svg>
</Box>
)
}