From b11ad9354bfbeea724eabf666e0809be034ac4f3 Mon Sep 17 00:00:00 2001 From: Ategon Date: Mon, 20 Jan 2025 00:57:59 -0500 Subject: [PATCH] Add prefers reduced motion handling --- .../link-components/ButtonAction.tsx | 24 +++++++++++++-- src/components/link-components/ButtonLink.tsx | 28 ++++++++++++++++-- src/components/link-components/IconLink.tsx | 24 +++++++++++++-- src/components/link-components/Link.tsx | 23 ++++++++++++++- src/components/navbar/PCNavbar.tsx | 19 +++++++++++- src/components/posts/LikeButton.tsx | 25 ++++++++++++++-- src/components/theme-toggle/index.tsx | 29 ++++++++++++++++--- 7 files changed, 156 insertions(+), 16 deletions(-) diff --git a/src/components/link-components/ButtonAction.tsx b/src/components/link-components/ButtonAction.tsx index 29ed37d..1b498b0 100644 --- a/src/components/link-components/ButtonAction.tsx +++ b/src/components/link-components/ButtonAction.tsx @@ -1,5 +1,7 @@ +"use client"; + import { Button } from "@nextui-org/react"; -import { ReactNode } from "react"; +import { ReactNode, useEffect, useState } from "react"; interface ButtonActionProps { icon?: ReactNode; @@ -12,10 +14,28 @@ export default function ButtonAction({ onPress, name, }: ButtonActionProps) { + const [reduceMotion, setReduceMotion] = useState(false); + + useEffect(() => { + const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)"); + setReduceMotion(mediaQuery.matches); + + const handleChange = (event: MediaQueryListEvent) => { + setReduceMotion(event.matches); + }; + mediaQuery.addEventListener("change", handleChange); + + return () => { + mediaQuery.removeEventListener("change", handleChange); + }; + }, []); + return (