Adds open/close animations to dialogs and modals

This commit is contained in:
Josh Perez 2021-09-29 16:59:37 -04:00 committed by GitHub
parent fc066e05df
commit b6cfe0933d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 635 additions and 224 deletions

View file

@ -0,0 +1,34 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { useEffect, useState } from 'react';
function getReducedMotionQuery(): MediaQueryList {
return window.matchMedia('(prefers-reduced-motion: reduce)');
}
// Inspired by <https://github.com/infiniteluke/react-reduce-motion>.
export function useReducedMotion(): boolean {
const initialQuery = getReducedMotionQuery();
const [prefersReducedMotion, setPrefersReducedMotion] = useState(
initialQuery.matches
);
useEffect(() => {
const query = getReducedMotionQuery();
function changePreference() {
setPrefersReducedMotion(query.matches);
}
changePreference();
query.addEventListener('change', changePreference);
return () => {
query.removeEventListener('change', changePreference);
};
});
return prefersReducedMotion;
}