diff --git a/src/components/Overlay/Transition.tsx b/src/components/Overlay/Transition.tsx index 69184d51..a071fca0 100644 --- a/src/components/Overlay/Transition.tsx +++ b/src/components/Overlay/Transition.tsx @@ -1,6 +1,7 @@ import * as React from 'react' export interface ITransitionProps { + duration: number extraStyle?: React.CSSProperties show: boolean } @@ -13,6 +14,9 @@ export const Transition: React.FC = props => { setMounted(false) } }, [opacity]) + const transition = React.useMemo( + () => `all ${props.duration}ms`, + [props.duration]) React.useEffect(() => { if (!props.show) { @@ -35,7 +39,7 @@ export const Transition: React.FC = props => { style={{ ...props.extraStyle, opacity, - transition: 'all 250ms', + transition, }} onTransitionEnd={onTransitionEnd} > diff --git a/src/components/Overlay/index.tsx b/src/components/Overlay/index.tsx index 8dc124bf..b48d1f9c 100644 --- a/src/components/Overlay/index.tsx +++ b/src/components/Overlay/index.tsx @@ -1,5 +1,6 @@ import * as React from 'react' import { Transition } from './Transition' +import { useReducedMotion } from '../../hooks/useReducedMotion' export interface IOverlayProps { show: boolean @@ -7,6 +8,9 @@ export interface IOverlayProps { } export const Overlay: React.FC = props => { + const motionDisabled = useReducedMotion() + const duration = motionDisabled ? 0 : 250 + const onClick = React.useCallback((event: React.MouseEvent) => { if (event.target === event.currentTarget) { props.onClickOverlay() @@ -19,6 +23,7 @@ export const Overlay: React.FC = props => { return (