A burst of particles around an element, for likes, stars and other celebrations.
Installation
Usage
import { Particles, ParticlesEffect } from '@animate-ui/react/primitives/effects/particles';
export function LikeButton({ liked }: { liked: boolean }) {
return (
<Particles animate={liked}>
<button>Like</button>
<ParticlesEffect className="size-1 rounded-full bg-red-500" />
</Particles>
);
}The burst plays when animate becomes true. Remount Particles (with a key) to replay it.
Animation
countparticles shoot out from a point on one side of the element, spread overspreaddegrees, then shrink and fade out (800ms, ease-out). Each startsholdDelayseconds after the previous one.- Particles are absolutely positioned: the layout never moves.
- With
inView, the burst waits for the element to be on screen. - Under reduced motion, the burst is skipped: it's decorative.
API Reference
Particles
| Prop | Type | Default |
|---|---|---|
asChild? | boolean | false |
animate? | boolean | true |
children | React.ReactNode | - |
inView? | boolean | false |
inViewOnce? | boolean | true |
inViewMargin? | string | '0px' |
...props? | HTMLMotionProps<'div'> | - |
ParticlesEffect
Each particle is rendered with these props: style it with className.
| Prop | Type | Default |
|---|---|---|
side? | 'top' | 'bottom' | 'left' | 'right' | 'top' |
sideOffset? | number | 0 |
align? | 'start' | 'center' | 'end' | 'center' |
alignOffset? | number | 0 |
count? | number | 6 |
radius? | number | 30 |
spread? | number | 360 |
duration? | number | 0.8 |
holdDelay? | number | 0.05 |
delay? | number | 0 |
transition? | Transition | - |
...props? | HTMLMotionProps<'div'> | - |
Credits
- Inspired by SHSF UI.