fix: modal overlay

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2024-10-13 18:20:54 +08:00
parent 22c0ddd14b
commit df05044c0e
2 changed files with 21 additions and 6 deletions
@@ -24,7 +24,6 @@ import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
import { SafeFragment } from "~/components/common/Fragment"
import { m } from "~/components/common/Motion"
import { ErrorComponentType } from "~/components/errors/enum"
import { resizableOnly } from "~/components/ui/modal"
import { ElECTRON_CUSTOM_TITLEBAR_HEIGHT, isElectronBuild } from "~/constants"
import { useSwitchHotKeyScope } from "~/hooks/common"
import { nextFrame, stopPropagation } from "~/lib/dom"
@@ -52,10 +51,14 @@ export const ModalInternal = memo(
index: number
isTop: boolean
isBottom: boolean
overlayOptions?: ModalOverlayOptions
onClose?: (open: boolean) => void
} & PropsWithChildren
>(function Modal({ item, overlayOptions, onClose: onPropsClose, children, isTop }, ref) {
>(function Modal(
{ item, overlayOptions, onClose: onPropsClose, children, isTop, isBottom },
ref,
) {
const {
CustomModalComponent,
modalClassName,
@@ -273,7 +276,7 @@ export const ModalInternal = memo(
<ModalOverlay
blur={overlayOptions?.blur}
className={cn(overlayOptions?.className, {
hidden: item.overlay ? false : !modalSettingOverlay,
invisible: item.overlay ? false : !(modalSettingOverlay && isBottom),
})}
/>
)
@@ -371,7 +374,7 @@ export const ModalInternal = memo(
}}
>
<ResizeSwitch
enable={resizableOnly("bottomRight")}
// enable={resizableOnly("bottomRight")}
onResizeStart={handleResizeStart}
onResizeStop={handleResizeStop}
defaultSize={resizeDefaultSize}
@@ -1,6 +1,7 @@
import { AnimatePresence } from "framer-motion"
import { useAtomValue } from "jotai"
import type { FC, PropsWithChildren } from "react"
import { useEffect } from "react"
import { modalStackAtom } from "./atom"
import { ModalInternal } from "./modal"
@@ -18,14 +19,25 @@ const ModalStack = () => {
const topModalIndex = stack.findLastIndex((item) => item.modal)
const overlayIndex = stack.findLastIndex((item) => item.overlay || item.modal)
const overlayOptions = stack[overlayIndex]?.overlayOptions
const hasModalStack = stack.length > 0
useEffect(() => {
// NOTE: document.body is being used by radix's dismissable,
// and using that will cause radix to get the value of `none` as the store value,
// and then revert to `none` instead of `auto` after a modal dismiss.
document.documentElement.style.pointerEvents = hasModalStack ? "none" : "auto"
document.documentElement.dataset.hasModal = hasModalStack.toString()
}, [hasModalStack])
return (
<AnimatePresence mode="popLayout">
{stack.map((item, index) => (
<ModalInternal
key={item.id}
item={item}
index={index * 2}
isTop={index === topModalIndex * 2}
index={index}
isTop={index === topModalIndex}
isBottom={index === 0}
overlayOptions={overlayOptions}
/>
))}