@carbon/ibm-products
Version:
Carbon for IBM Products
36 lines (34 loc) • 1.28 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
require("../../../_virtual/_rolldown/runtime.js");
const require_useIsomorphicEffect = require("./useIsomorphicEffect.js");
let react = require("react");
//#region src/global/js/hooks/usePrefersReducedMotion.js
/**
* Copyright IBM Corp. 2024, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const usePrefersReducedMotion = () => {
const [prefersReducedMotion, setPrefersReducedMotion] = (0, react.useState)(false);
require_useIsomorphicEffect.useIsomorphicEffect(() => {
const mediaQueryList = window.matchMedia("(prefers-reduced-motion: no-preference)");
const { matches } = window.matchMedia("(prefers-reduced-motion: no-preference)");
setPrefersReducedMotion(!matches);
const listener = (event) => {
setPrefersReducedMotion(!event.matches);
};
mediaQueryList.addEventListener("change", listener);
return () => {
mediaQueryList.removeEventListener("change", listener);
};
}, []);
return prefersReducedMotion;
};
//#endregion
exports.usePrefersReducedMotion = usePrefersReducedMotion;