Skip to content

Commit 1c6cf3c

Browse files
fix: respect reduced motion preference in BrandParticles
1 parent 6ede310 commit 1c6cf3c

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

components/BrandParticles.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { motion } from 'framer-motion';
3+
import { motion, useReducedMotion } from 'framer-motion';
44
import { useEffect, useState } from 'react';
55

66
// Generates an array of particles
@@ -41,7 +41,7 @@ interface Particle {
4141
export default function BrandParticles() {
4242
const [particles] = useState<Particle[]>(() => generateParticles(40));
4343
const [mounted, setMounted] = useState(false);
44-
44+
const shouldReduceMotion = useReducedMotion();
4545
useEffect(() => {
4646
// eslint-disable-next-line react-hooks/set-state-in-effect
4747
setMounted(true);
@@ -66,17 +66,25 @@ export default function BrandParticles() {
6666
boxShadow: `0 0 ${particle.size * 2}px ${particle.color}`,
6767
borderRadius: particle.borderRadius,
6868
}}
69-
animate={{
70-
y: [0, -150, 150, 0], // Float up and around
71-
x: [0, particle.xAnimStart, particle.xAnimEnd, 0],
72-
rotate: [0, 360 * particle.rotateDirection],
73-
}}
74-
transition={{
75-
duration: particle.duration,
76-
delay: particle.delay,
77-
repeat: Infinity,
78-
ease: 'linear',
79-
}}
69+
animate={
70+
shouldReduceMotion
71+
? {}
72+
: {
73+
y: [0, -150, 150, 0],
74+
x: [0, particle.xAnimStart, particle.xAnimEnd, 0],
75+
rotate: [0, 360 * particle.rotateDirection],
76+
}
77+
}
78+
transition={
79+
shouldReduceMotion
80+
? {}
81+
: {
82+
duration: particle.duration,
83+
delay: particle.delay,
84+
repeat: Infinity,
85+
ease: 'linear',
86+
}
87+
}
8088
/>
8189
))}
8290
</div>

0 commit comments

Comments
 (0)