Skip to content

Commit 8a0703b

Browse files
committed
added support for reduced motion
1 parent 14b3891 commit 8a0703b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/components/SnippetList.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { motion, AnimatePresence } from "motion/react";
1+
import { motion, AnimatePresence, useReducedMotion } from "motion/react";
22
import { useState } from "react";
33

44
import { useAppContext } from "@contexts/AppContext";
@@ -13,6 +13,8 @@ const SnippetList = () => {
1313
const { fetchedSnippets } = useSnippets();
1414
const [isModalOpen, setIsModalOpen] = useState(false);
1515

16+
const shouldReduceMotion = useReducedMotion();
17+
1618
if (!fetchedSnippets)
1719
return (
1820
<div>
@@ -38,27 +40,27 @@ const SnippetList = () => {
3840
return (
3941
<motion.li
4042
key={currentSnippet.title + idx}
41-
initial={{ opacity: 0, y: 20 }}
4243
layoutId={currentSnippet.title + (idx + 1).toString()}
44+
initial={{ opacity: 0, y: 20 }}
4345
animate={{
4446
opacity: 1,
4547
y: 0,
4648
transition: {
47-
delay: 0.09 + idx * 0.05,
48-
duration: 0.2,
49+
delay: shouldReduceMotion ? 0 : 0.09 + idx * 0.05,
50+
duration: shouldReduceMotion ? 0 : 0.2,
4951
},
5052
}}
5153
exit={{
5254
opacity: 0,
5355
y: -20,
5456
transition: {
5557
delay: idx * 0.01,
56-
duration: 0.09,
58+
duration: shouldReduceMotion ? 0 : 0.09,
5759
},
5860
}}
5961
transition={{
6062
type: "spring",
61-
duration: 0.5,
63+
duration: shouldReduceMotion ? 0 : 0.5,
6264
}}
6365
>
6466
<motion.button

src/components/SnippetModal.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { motion } from "motion/react";
1+
import { motion, useReducedMotion } from "motion/react";
22
import React from "react";
33
import ReactDOM from "react-dom";
44

@@ -23,6 +23,8 @@ const SnippetModal: React.FC<Props> = ({
2323
}) => {
2424
const modalRoot = document.getElementById("modal-root");
2525

26+
const shouldReduceMotion = useReducedMotion();
27+
2628
useEscapeKey(handleCloseModal);
2729

2830
if (!modalRoot) {
@@ -41,14 +43,14 @@ const SnippetModal: React.FC<Props> = ({
4143
initial={{ opacity: 0 }}
4244
animate={{ opacity: 1 }}
4345
exit={{ opacity: 0 }}
44-
transition={{ duration: 0.2 }}
46+
transition={{ duration: shouldReduceMotion ? 0 : 0.2 }}
4547
>
4648
<motion.div
4749
key="modal-content"
4850
className="modal | flow"
4951
data-flow-space="lg"
5052
layoutId={snippet.title + snippet.idx?.toString()}
51-
transition={{ type: "spring", duration: 0.5 }}
53+
transition={{ type: "spring", duration: shouldReduceMotion ? 0 : 0.5 }}
5254
>
5355
<div className="modal__header">
5456
<h2 className="section-title">{snippet.title}</h2>

0 commit comments

Comments
 (0)