Skip to content

Commit

Permalink
feat: add Dynamic Modal Animation Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOliveiraM committed Mar 5, 2023
1 parent 3bf399d commit ed4c34f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 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.19",
"version": "2.1.20",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
Expand Down
26 changes: 19 additions & 7 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, AnimatePresence } from 'framer-motion'
import { motion, AnimatePresence, AnimationProps } from 'framer-motion'

import { FlexProps } from 'components/atoms'
import { Portal } from 'components/hocs/Portal'
Expand All @@ -32,6 +32,12 @@ type ModalFunctionNotation = {
}

export type ModalProps = {
animation?: {
initial?: AnimationProps['initial']
transition?: AnimationProps['transition']
in?: AnimationProps['animate']
out?: AnimationProps['exit']
}
render: (params: ModalFunctionNotation) => ReactNode
onClickOutside?: () => void
children?: (params: ModalFunctionNotation) => ReactNode
Expand All @@ -42,6 +48,7 @@ export type ModalProps = {
} & Omit<CardProps, 'children'>

const ModalBase = ({
animation,
render,
onClickOutside,
externalIsOpen,
Expand Down Expand Up @@ -86,13 +93,17 @@ const ModalBase = ({
<AnimatePresence>
{modalIsOpen ? (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{
default: { duration: 0.3 },
}}
{...motionContainerProps}
initial={animation?.initial ? animation.initial : { opacity: 0 }}
animate={animation?.in ? animation.in : { opacity: 1 }}
exit={animation?.out ? animation.out : { opacity: 0 }}
transition={
animation?.transition
? animation.transition
: {
default: { duration: 0.3 },
}
}
>
<ModalBackground variant='center' {...backgroundProps}>
<ModalCard ref={modalMainRef} {...props}>
Expand All @@ -110,6 +121,7 @@ const ModalBase = ({

ModalBase.defaultProps = {
children: undefined,
animation: undefined,
onClickOutside: undefined,
externalIsOpen: undefined,
backgroundProps: undefined,
Expand Down

0 comments on commit ed4c34f

Please sign in to comment.