({ children, onClose, isOpen, isScroll = false }: ModalType)
| 56 | `; |
| 57 | |
| 58 | function Modal({ children, onClose, isOpen, isScroll = false }: ModalType) { |
| 59 | const [open, setOpen] = useState(false); |
| 60 | const [fadeOutAnimation, setFadeOutAnimation] = useState( |
| 61 | `${fadeIn} 0.3s forwards` |
| 62 | ); |
| 63 | const [backgroundAnimation, setBackgroundAnimation] = useState( |
| 64 | `${fadeInBackground} 0.3s forwards` |
| 65 | ); |
| 66 | |
| 67 | const handleClose = (e: any) => { |
| 68 | if (e.target.id != "modal") { |
| 69 | return false; |
| 70 | } |
| 71 | setFadeOutAnimation(`${fadeOut} 0.3s forwards`); |
| 72 | setBackgroundAnimation(`${fadeOutBackground} 0.3s forwards`); |
| 73 | |
| 74 | setTimeout(() => { |
| 75 | onClose(); |
| 76 | setOpen(false); |
| 77 | }, 280); |
| 78 | }; |
| 79 | |
| 80 | useEffect(() => { |
| 81 | if (isOpen) { |
| 82 | setOpen(true); |
| 83 | setFadeOutAnimation(`${fadeIn} 0.3s forwards`); |
| 84 | setBackgroundAnimation(`${fadeInBackground} 0.3s forwards`); |
| 85 | } else { |
| 86 | setFadeOutAnimation(`${fadeOut} 0.3s forwards`); |
| 87 | setBackgroundAnimation(`${fadeOutBackground} 0.3s forwards`); |
| 88 | |
| 89 | setTimeout(() => { |
| 90 | onClose(); |
| 91 | setOpen(false); |
| 92 | }, 280); |
| 93 | } |
| 94 | }, [isOpen]); |
| 95 | |
| 96 | return ( |
| 97 | <div |
| 98 | onClick={handleClose} |
| 99 | id="modal" |
| 100 | css={css({ |
| 101 | display: open ? "flex" : "none", |
| 102 | justifyContent: "center", |
| 103 | alignItems: "center", |
| 104 | width: "100%", |
| 105 | height: "100%", |
| 106 | position: "fixed", |
| 107 | top: "0", |
| 108 | left: "0", |
| 109 | backdropFilter: "brightness(70%)", |
| 110 | animation: backgroundAnimation, |
| 111 | scrollbarWidth: "none", |
| 112 | zIndex: 3000, |
| 113 | transition: "0.1s", |
| 114 | })} |
| 115 | > |
nothing calls this directly
no outgoing calls
no test coverage detected