mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 17:04:15 +00:00
style: add animation to modal
This commit is contained in:
parent
37a0736a0e
commit
7823dc7ff4
1 changed files with 21 additions and 4 deletions
|
|
@ -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>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue