File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 1
- import { motion , AnimatePresence } from "motion/react" ;
1
+ import { motion , AnimatePresence , useReducedMotion } from "motion/react" ;
2
2
import { useState } from "react" ;
3
3
4
4
import { useAppContext } from "@contexts/AppContext" ;
@@ -13,6 +13,8 @@ const SnippetList = () => {
13
13
const { fetchedSnippets } = useSnippets ( ) ;
14
14
const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
15
15
16
+ const shouldReduceMotion = useReducedMotion ( ) ;
17
+
16
18
if ( ! fetchedSnippets )
17
19
return (
18
20
< div >
@@ -38,27 +40,27 @@ const SnippetList = () => {
38
40
return (
39
41
< motion . li
40
42
key = { currentSnippet . title + idx }
41
- initial = { { opacity : 0 , y : 20 } }
42
43
layoutId = { currentSnippet . title + ( idx + 1 ) . toString ( ) }
44
+ initial = { { opacity : 0 , y : 20 } }
43
45
animate = { {
44
46
opacity : 1 ,
45
47
y : 0 ,
46
48
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 ,
49
51
} ,
50
52
} }
51
53
exit = { {
52
54
opacity : 0 ,
53
55
y : - 20 ,
54
56
transition : {
55
57
delay : idx * 0.01 ,
56
- duration : 0.09 ,
58
+ duration : shouldReduceMotion ? 0 : 0.09 ,
57
59
} ,
58
60
} }
59
61
transition = { {
60
62
type : "spring" ,
61
- duration : 0.5 ,
63
+ duration : shouldReduceMotion ? 0 : 0.5 ,
62
64
} }
63
65
>
64
66
< motion . button
Original file line number Diff line number Diff line change 1
- import { motion } from "motion/react" ;
1
+ import { motion , useReducedMotion } from "motion/react" ;
2
2
import React from "react" ;
3
3
import ReactDOM from "react-dom" ;
4
4
@@ -23,6 +23,8 @@ const SnippetModal: React.FC<Props> = ({
23
23
} ) => {
24
24
const modalRoot = document . getElementById ( "modal-root" ) ;
25
25
26
+ const shouldReduceMotion = useReducedMotion ( ) ;
27
+
26
28
useEscapeKey ( handleCloseModal ) ;
27
29
28
30
if ( ! modalRoot ) {
@@ -41,14 +43,14 @@ const SnippetModal: React.FC<Props> = ({
41
43
initial = { { opacity : 0 } }
42
44
animate = { { opacity : 1 } }
43
45
exit = { { opacity : 0 } }
44
- transition = { { duration : 0.2 } }
46
+ transition = { { duration : shouldReduceMotion ? 0 : 0.2 } }
45
47
>
46
48
< motion . div
47
49
key = "modal-content"
48
50
className = "modal | flow"
49
51
data-flow-space = "lg"
50
52
layoutId = { snippet . title + snippet . idx ?. toString ( ) }
51
- transition = { { type : "spring" , duration : 0.5 } }
53
+ transition = { { type : "spring" , duration : shouldReduceMotion ? 0 : 0.5 } }
52
54
>
53
55
< div className = "modal__header" >
54
56
< h2 className = "section-title" > { snippet . title } </ h2 >
You can’t perform that action at this time.
0 commit comments