mirror of
https://github.com/remvze/moodist.git
synced 2025-11-04 11:33:06 -05:00
style: add scroll lock in modals
This commit is contained in:
parent
69cb45bff7
commit
def69de6e4
@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
import { IoClose } from 'react-icons/io5/index';
|
import { IoClose } from 'react-icons/io5/index';
|
||||||
|
|
||||||
@ -8,17 +9,32 @@ import styles from './modal.module.css';
|
|||||||
|
|
||||||
interface ModalProps {
|
interface ModalProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
lockBody?: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
show: boolean;
|
show: boolean;
|
||||||
wide?: boolean;
|
wide?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Modal({ children, onClose, show, wide }: ModalProps) {
|
export function Modal({
|
||||||
|
children,
|
||||||
|
lockBody = true,
|
||||||
|
onClose,
|
||||||
|
show,
|
||||||
|
wide,
|
||||||
|
}: ModalProps) {
|
||||||
const variants = {
|
const variants = {
|
||||||
modal: mix(fade(), slideY(20)),
|
modal: mix(fade(), slideY(20)),
|
||||||
overlay: fade(),
|
overlay: fade(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (show && lockBody) {
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
} else if (lockBody) {
|
||||||
|
document.body.style.overflow = 'auto';
|
||||||
|
}
|
||||||
|
}, [show, lockBody]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{show && (
|
{show && (
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export function Setting({ onChange, onClose, show, times }: SettingProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal show={show} onClose={onClose}>
|
<Modal lockBody={false} show={show} onClose={onClose}>
|
||||||
<h2 className={styles.title}>Change Times</h2>
|
<h2 className={styles.title}>Change Times</h2>
|
||||||
|
|
||||||
<form className={styles.form} onSubmit={handleSubmit}>
|
<form className={styles.form} onSubmit={handleSubmit}>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user