style: add animation to modal

This commit is contained in:
MAZE 2024-01-04 19:58:16 +03:30
parent 37a0736a0e
commit 7823dc7ff4

View file

@ -1,6 +1,8 @@
import { AnimatePresence } from 'framer-motion'; import { AnimatePresence, motion } from 'framer-motion';
import { IoClose } from 'react-icons/io5/index'; import { IoClose } from 'react-icons/io5/index';
import { fade, mix, slideY } from '@/lib/motion';
import styles from './modal.module.css'; import styles from './modal.module.css';
interface ModalProps { interface ModalProps {
@ -10,23 +12,38 @@ interface ModalProps {
} }
export function Modal({ children, onClose, show }: ModalProps) { export function Modal({ children, onClose, show }: ModalProps) {
const variants = {
modal: mix(fade(), slideY(20)),
overlay: fade(),
};
return ( return (
<AnimatePresence> <AnimatePresence>
{show && ( {show && (
<> <>
<div <motion.div
animate="show"
className={styles.overlay} className={styles.overlay}
exit="hidden"
initial="hidden"
variants={variants.overlay}
onClick={onClose} onClick={onClose}
onKeyDown={onClose} onKeyDown={onClose}
/> />
<div className={styles.modal}> <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}> <button className={styles.close} onClick={onClose}>
<IoClose /> <IoClose />
</button> </button>
{children} {children}
</div> </motion.div>
</div> </div>
</> </>
)} )}