style: add scroll lock in modals

This commit is contained in:
MAZE 2024-02-28 23:03:35 +03:30
parent 69cb45bff7
commit def69de6e4
2 changed files with 18 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import { useEffect } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import { IoClose } from 'react-icons/io5/index';
@ -8,17 +9,32 @@ import styles from './modal.module.css';
interface ModalProps {
children: React.ReactNode;
lockBody?: boolean;
onClose: () => void;
show: boolean;
wide?: boolean;
}
export function Modal({ children, onClose, show, wide }: ModalProps) {
export function Modal({
children,
lockBody = true,
onClose,
show,
wide,
}: ModalProps) {
const variants = {
modal: mix(fade(), slideY(20)),
overlay: fade(),
};
useEffect(() => {
if (show && lockBody) {
document.body.style.overflow = 'hidden';
} else if (lockBody) {
document.body.style.overflow = 'auto';
}
}, [show, lockBody]);
return (
<AnimatePresence>
{show && (

View File

@ -27,7 +27,7 @@ export function Setting({ onChange, onClose, show, times }: SettingProps) {
};
return (
<Modal show={show} onClose={onClose}>
<Modal lockBody={false} show={show} onClose={onClose}>
<h2 className={styles.title}>Change Times</h2>
<form className={styles.form} onSubmit={handleSubmit}>