From 7ef5dfc036dcfba1e5c5e6d5569ca1178b0d890a Mon Sep 17 00:00:00 2001 From: "Kaffi Y." Date: Sun, 6 Oct 2024 14:29:00 +0800 Subject: [PATCH] fix: setting modal should be resizable from bottomRight only (#769) --- .../components/ui/modal/stacked/helper.tsx | 19 +++++++++++++++++++ .../src/components/ui/modal/stacked/modal.tsx | 5 ++--- .../src/modules/settings/modal/layout.tsx | 6 ++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/apps/renderer/src/components/ui/modal/stacked/helper.tsx b/apps/renderer/src/components/ui/modal/stacked/helper.tsx index e6167e1b1..04659fc2b 100644 --- a/apps/renderer/src/components/ui/modal/stacked/helper.tsx +++ b/apps/renderer/src/components/ui/modal/stacked/helper.tsx @@ -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) => { {children} )) } + +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 +} diff --git a/apps/renderer/src/components/ui/modal/stacked/modal.tsx b/apps/renderer/src/components/ui/modal/stacked/modal.tsx index dfad4edb2..8bfcbe70b 100644 --- a/apps/renderer/src/components/ui/modal/stacked/modal.tsx +++ b/apps/renderer/src/components/ui/modal/stacked/modal.tsx @@ -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( }} >