Skip to content

Commit

Permalink
refactor(SLB-405): enhance reduced motion detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Luqmaan Essop committed Jun 5, 2024
1 parent c881d78 commit 38d9481
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/ui/src/components/Molecules/FadeUp.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
'use client';
import { motion, useReducedMotion } from 'framer-motion';
import React, { PropsWithChildren } from 'react';
import { motion } from 'framer-motion';
import React, { PropsWithChildren, useEffect, useState } from 'react';

export function FadeUp({
yGap,
children,
className,
}: PropsWithChildren<{ yGap: number; className?: string }>) {
const reducedMotion = useReducedMotion();
const [reducedMotion, setReducedMotion] = useState(false);

useEffect(() => {
const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');

const handleChange = () => {
setReducedMotion(mediaQuery.matches);
};

// Set the initial value
handleChange();

// Add the event listener
mediaQuery.addEventListener('change', handleChange);

return () => {
// Clean up the event listener on unmount
mediaQuery.removeEventListener('change', handleChange);
};
}, [reducedMotion]);

return (
<motion.div
Expand Down

0 comments on commit 38d9481

Please sign in to comment.