Skip to content

Commit

Permalink
feat: use AnimatePresence for modal out
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOliveiraM committed Nov 17, 2022
1 parent e081934 commit 6427fef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"react",
"typescript"
],
"version": "2.1.6",
"version": "2.1.7",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
Expand Down
51 changes: 19 additions & 32 deletions src/components/molecules/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ModalPortalDedupleContext,
ModalPortalDedupleProvider,
} from 'contexts/ModalPortalDedupleContext'
import { motion } from 'framer-motion'
import { motion, AnimatePresence } from 'framer-motion'

import { FlexProps } from 'components/atoms'
import { Portal } from 'components/hocs/Portal'
Expand All @@ -39,18 +39,6 @@ export type ModalProps = {
disableUseOnClickOutside?: boolean
} & Omit<CardProps, 'children'>

const motionBackgroundVariants = {
hidden: {
opacity: 0,
transitionEnd: {
display: 'none',
},
},
visible: {
opacity: 1,
},
}

const ModalBase = ({
render,
externalIsOpen,
Expand Down Expand Up @@ -87,25 +75,24 @@ const ModalBase = ({

<ModalPortalDedupleProvider>
<Portal enabled={!hasParentModal}>
<motion.div
variants={motionBackgroundVariants}
initial='hidden'
animate={modalIsOpen ? 'visible' : 'hidden'}
transition={{
default: { duration: 0.3 },
}}
style={{
...(modalIsOpen && {
display: 'block',
}),
}}
>
<ModalBackground variant='center' {...backgroundProps}>
<ModalCard ref={modalMainRef} {...props}>
{render({ isOpen: modalIsOpen, setIsOpen, excludeRef })}
</ModalCard>
</ModalBackground>
</motion.div>
<AnimatePresence>
{modalIsOpen ? (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{
default: { duration: 0.3 },
}}
>
<ModalBackground variant='center' {...backgroundProps}>
<ModalCard ref={modalMainRef} {...props}>
{render({ isOpen: modalIsOpen, setIsOpen, excludeRef })}
</ModalCard>
</ModalBackground>
</motion.div>
) : null}
</AnimatePresence>
</Portal>
</ModalPortalDedupleProvider>
</>
Expand Down

0 comments on commit 6427fef

Please sign in to comment.