fix: setting modal should be resizable from bottomRight only (#769)

This commit is contained in:
Kaffi Y.
2024-10-06 14:29:00 +08:00
committed by GitHub
parent 8d951436df
commit 7ef5dfc036
3 changed files with 23 additions and 7 deletions
@@ -1,3 +1,4 @@
import type { Enable } from "re-resizable"
import type { Context, PropsWithChildren } from "react"
import { memo, useContext } from "react"
@@ -7,3 +8,21 @@ export const InjectContext = (context: Context<any>) => {
<context.Provider value={ctxValue}>{children}</context.Provider>
))
}
export function resizableOnly(...positions: (keyof Enable)[]) {
const enable: Enable = {
top: false,
right: false,
bottom: false,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
}
for (const position of positions) {
enable[position] = true
}
return enable
}
@@ -24,6 +24,7 @@ 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"
@@ -358,9 +359,7 @@ export const ModalInternal = memo(
}}
>
<ResizeSwitch
enable={{
bottomRight: true,
}}
enable={resizableOnly("bottomRight")}
onResizeStart={handleResizeEnable}
defaultSize={resizeDefaultSize}
className="flex grow flex-col"
@@ -8,7 +8,7 @@ import { useUISettingSelector } from "~/atoms/settings/ui"
import { m } from "~/components/common/Motion"
import { Logo } from "~/components/icons/logo"
import { LetsIconsResizeDownRightLight } from "~/components/icons/resize"
import { useResizeableModal } from "~/components/ui/modal"
import { resizableOnly, useResizeableModal } from "~/components/ui/modal"
import { ElECTRON_CUSTOM_TITLEBAR_HEIGHT } from "~/constants"
import { preventDefault } from "~/lib/dom"
import { cn, getOS } from "~/lib/utils"
@@ -94,9 +94,7 @@ export function SettingModalLayout(
<SettingContext.Provider value={defaultCtx}>
<Resizable
onResizeStart={handlePointDown}
enable={{
bottomRight: true,
}}
enable={resizableOnly("bottomRight")}
style={{ ...resizeableStyle, position: "static" }}
defaultSize={{
width: 800,