Skip to content

Commit

Permalink
style: add animation to modal
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Jan 4, 2024
1 parent 37a0736 commit 7823dc7
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AnimatePresence } from 'framer-motion';
import { AnimatePresence, motion } from 'framer-motion';
import { IoClose } from 'react-icons/io5/index';

import { fade, mix, slideY } from '@/lib/motion';

import styles from './modal.module.css';

interface ModalProps {
Expand All @@ -10,23 +12,38 @@ interface ModalProps {
}

export function Modal({ children, onClose, show }: ModalProps) {
const variants = {
modal: mix(fade(), slideY(20)),
overlay: fade(),
};

return (
<AnimatePresence>
{show && (
<>
<div
<motion.div
animate="show"
className={styles.overlay}
exit="hidden"
initial="hidden"
variants={variants.overlay}
onClick={onClose}
onKeyDown={onClose}
/>
<div className={styles.modal}>
<div className={styles.content}>
<motion.div
animate="show"
className={styles.content}
exit="hidden"
initial="hidden"
variants={variants.modal}
>
<button className={styles.close} onClick={onClose}>
<IoClose />
</button>

{children}
</div>
</motion.div>
</div>
</>
)}
Expand Down

0 comments on commit 7823dc7

Please sign in to comment.