Skip to content

Commit

Permalink
feat: add usePreferredMotionIntensity
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Oct 24, 2019
1 parent 0bbdd62 commit eaed758
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/web-api-hooks/src/usePreferredMotionIntensity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import useMedia from './useMedia';

/**
* Tracks motion intensity preference of the user.
*
* @returns Preferred motion intensity.
*
* @example
* function Component() {
* const preferReducedMotion = usePreferredMotionIntensity() === 'reduce';
* // ...
* }
*/
export default function usePreferredMotionIntensity():
| 'no-preference'
| 'reduce' {
const isReduce = useMedia('(prefers-reduced-motion: reduce)');

if (isReduce) return 'reduce';
return 'no-preference';
}

0 comments on commit eaed758

Please sign in to comment.