overlay reduced motion support
This commit is contained in:
1 parent
bdde0f79c1
commit
fbcf204642
3 files changed
+15
-1
No files matched your search
@@ -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<ITransitionProps> = 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<ITransitionProps> = props => {
|
||||
style={{
|
||||
...props.extraStyle,
|
||||
opacity,
|
||||
transition: 'all 250ms',
|
||||
transition,
|
||||
}}
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
>
|
||||
|
||||
@@ -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<IOverlayProps> = props => {
|
||||
const motionDisabled = useReducedMotion()
|
||||
const duration = motionDisabled ? 0 : 250
|
||||
|
||||
const onClick = React.useCallback((event: React.MouseEvent<HTMLDivElement>) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
props.onClickOverlay()
|
||||
@@ -19,6 +23,7 @@ export const Overlay: React.FC<IOverlayProps> = props => {
|
||||
|
||||
return (
|
||||
<Transition
|
||||
duration={duration}
|
||||
show={props.show}
|
||||
extraStyle={{
|
||||
zIndex: 1000000,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import useMedia from 'use-media'
|
||||
|
||||
export function useReducedMotion(): boolean {
|
||||
return useMedia('(prefers-reduced-motion: reduce)')
|
||||
}
|
||||
Reference in new issue
Block a user