-
-
Save brunosabot/fb6ef1864549f741938ad093bb8b0e1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.ModalAnimated { | |
bottom: 0; | |
left: 0; | |
pointer-events: initial; | |
position: absolute; | |
right: 0; | |
top: 0; | |
} | |
.ModalAnimated:global(.modal-enter) { | |
opacity: 0; | |
transform: translateY(100px) scale(0.9); | |
} | |
.ModalAnimated:global(.modal-enter-active) { | |
opacity: 1; | |
transform: translateY(0) scale(1); | |
transition: all cubic-bezier(0, 0, 0.2, 1) 300ms; | |
} | |
.ModalAnimated:global(.modal-exit) { | |
opacity: 1; | |
transform: translateY(0) scale(1); | |
} | |
.ModalAnimated:global(.modal-exit-active) { | |
opacity: 0; | |
transform: translateY(-100px) scale(0.9); | |
transition: all cubic-bezier(0, 0, 0.2, 1) 300ms; | |
} | |
@media screen and (prefers-reduced-motion: reduce) { | |
.ModalAnimated:global(.modal-enter-active) { | |
transition: none; | |
} | |
.ModalAnimated:global(.modal-exit-active) { | |
transition: none; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { CSSTransition } from "react-transition-group"; | |
import classes from "./ModalAnimated.module.css"; | |
import ModalPortal from "./ModalPortal"; | |
import ModalView from "./ModalView"; | |
import useEchap from "./useEchap"; | |
type ViewComponentType = React.FunctionComponent<{ | |
children: React.ReactNode, | |
onClose: () => void, | |
}>; | |
interface Props { | |
active: boolean; | |
children: React.ReactNode; | |
onClose: () => void; | |
view?: ViewComponentType; | |
} | |
const ModalAnimated: React.FC<Props> = ({ | |
active, | |
children, | |
onClose, | |
view: ViewComponent = ModalView, | |
}) => { | |
useEscape(active, onClose); | |
return ( | |
<CSSTransition in={active} timeout={300} classNames="modal"> | |
<ModalPortal active={active}> | |
<div className={classes.ModalAnimated}> | |
<ViewComponent onClose={onClose}>{children}</ViewComponent> | |
</div> | |
</ModalPortal> | |
</CSSTransition> | |
); | |
}; | |
export default ModalAnimated; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment