mirror of
https://github.com/codeaashu/claude-code.git
synced 2026-04-08 22:28:48 +03:00
claude-code
This commit is contained in:
27
web/hooks/useReducedMotion.ts
Normal file
27
web/hooks/useReducedMotion.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
/**
|
||||
* Returns true when the user has requested reduced motion via OS settings.
|
||||
* Use this to disable or simplify animations for users who need it.
|
||||
*
|
||||
* @example
|
||||
* const reducedMotion = useReducedMotion();
|
||||
* <div className={reducedMotion ? "" : "animate-fade-in"}>...</div>
|
||||
*/
|
||||
export function useReducedMotion(): boolean {
|
||||
const [reducedMotion, setReducedMotion] = useState(() => {
|
||||
if (typeof window === "undefined") return false;
|
||||
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
const handler = (e: MediaQueryListEvent) => setReducedMotion(e.matches);
|
||||
mq.addEventListener("change", handler);
|
||||
return () => mq.removeEventListener("change", handler);
|
||||
}, []);
|
||||
|
||||
return reducedMotion;
|
||||
}
|
||||
Reference in New Issue
Block a user