Prefers reduced motion is a package that tells you whether a user prefers reduced motion. It's based on the CSS @media (prefers-reduced-motion), which is part of Media Queries Level 5. It's around 700 bytes minified, 300 bytes gzipped.
Add the dependency from NPM:
npm install prefers-reduced-motionImport the package:
import prefersReducedMotion from "prefers-reduced-motion";Then call the function:
const motionPreference = prefersReducedMotion();
// Returns "reduce" or "no-preference"This package only works in browsers that natively support @media (prefers-reduced-motion), so it just returns "no-preference" in unsupported browsers. Current browser support
By passing false as the argument, you can get "unsupported" as the value for unsupported browsers:
const motionPreference = prefersReducedMotion(false);
// Returns "reduce", "no-preference", or "unsupported"Install dependencies:
yarnCompile Typescript to ES6 before publishing to NPM:
yarn build- π
prefers-reduced-motionΒ· GitHub Β· NPM - π¨
prefers-color-schemeΒ· GitHub Β· NPM - πΆοΈ
prefers-contrastΒ· GitHub Β· NPM - ποΈ
prefers-reduced-transparencyΒ· GitHub Β· NPM - π
inverted-colorsΒ· GitHub Β· NPM - π§
environment-blendingΒ· GitHub Β· NPM - π‘
light-levelΒ· GitHub Β· NPM
MIT
