| 1 |
import { useEffect } from '@wordpress/element' |
| 2 |
import confetti from 'canvas-confetti' |
| 3 |
|
| 4 |
export const useConfetti = (config = {}, time = 0, ready = false) => { |
| 5 |
useEffect(() => { |
| 6 |
if (!ready) return |
| 7 |
const secondsFromNow = Date.now() + time |
| 8 |
const frame = () => { |
| 9 |
confetti({ |
| 10 |
...config, |
| 11 |
disableForReducedMotion: true, |
| 12 |
zIndex: 100000, |
| 13 |
}) |
| 14 |
if (Date.now() < secondsFromNow) { |
| 15 |
requestAnimationFrame(frame) |
| 16 |
} |
| 17 |
} |
| 18 |
frame() |
| 19 |
}, [config, time, ready]) |
| 20 |
} |
| 21 |
|