Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding reduced motion media query to disable notification animations. #34

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/components/toast-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { Toast, ToastPosition, resolveValueOrFunction } from '../core/types';
import { Indicator } from './indicator';
import { AnimatedIconWrapper } from './icon-wrapper';


const prefersReducedMotion = () => {
// Grab the prefers reduced media query.
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
// Check if the media query matches or is not available.
return (!mediaQuery || mediaQuery.matches) ? true : false;
}

const enterAnimation = (factor: number) => `
0% {transform: translate3d(0,${factor * -80}px,0) scale(.6); opacity:.5;}
100% {transform: translate3d(0,0,0) scale(1); opacity:1;}
Expand Down Expand Up @@ -69,7 +77,7 @@ const getPositionStyle = (
};
return {
position: 'fixed',
transition: 'all 230ms cubic-bezier(.21,1.02,.73,1)',
transition: `${!prefersReducedMotion() && 'all 230ms cubic-bezier(.21,1.02,.73,1)'}`,
transform: `translateY(${offset * (top ? 1 : -1)}px)`,
...verticalStyle,
...horizontalStyle,
Expand All @@ -84,14 +92,14 @@ const getAnimationStyle = (
const factor = top ? 1 : -1;
return visible
? {
animation: `${keyframes`${enterAnimation(
animation: `${!prefersReducedMotion() && `${keyframes `${enterAnimation(
factor
)}`} 0.35s cubic-bezier(.21,1.02,.73,1) forwards`,
)}`} 0.35s cubic-bezier(.21,1.02,.73,1) forwards`}`,
}
: {
animation: `${keyframes`${exitAnimation(
animation: `${!prefersReducedMotion() && `${keyframes `${exitAnimation(
factor
)}`} 0.8s forwards cubic-bezier(.06,.71,.55,1)`,
)}`} 0.8s forwards cubic-bezier(.06,.71,.55,1)`}`,
pointerEvents: 'none',
};
};
Expand Down