Blame view

天文台pc/tianwentai-ui/node_modules/framer-motion/dist/es/utils/reduced-motion/use-reduced-motion.mjs 1.63 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  "use client";
  import { hasReducedMotionListener, initPrefersReducedMotion, prefersReducedMotion } from 'motion-dom';
  import { warnOnce } from 'motion-utils';
  import { useState } from 'react';
  
  /**
   * A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
   *
   * This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
   * `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
   *
   * It will actively respond to changes and re-render your components with the latest setting.
   *
   * ```jsx
   * export function Sidebar({ isOpen }) {
   *   const shouldReduceMotion = useReducedMotion()
   *   const closedX = shouldReduceMotion ? 0 : "-100%"
   *
   *   return (
   *     <motion.div animate={{
   *       opacity: isOpen ? 1 : 0,
   *       x: isOpen ? 0 : closedX
   *     }} />
   *   )
   * }
   * ```
   *
   * @return boolean
   *
   * @public
   */
  function useReducedMotion() {
      /**
       * Lazy initialisation of prefersReducedMotion
       */
      !hasReducedMotionListener.current && initPrefersReducedMotion();
      const [shouldReduceMotion] = useState(prefersReducedMotion.current);
      if (process.env.NODE_ENV !== "production") {
          warnOnce(shouldReduceMotion !== true, "You have Reduced Motion enabled on your device. Animations may not appear as expected.", "reduced-motion-disabled");
      }
      /**
       * TODO See if people miss automatically updating shouldReduceMotion setting
       */
      return shouldReduceMotion;
  }
  
  export { useReducedMotion };
  //# sourceMappingURL=use-reduced-motion.mjs.map