+
+ {isSidebarOpen ? "«" : "»"}
+
+
+
+
+ {pages?.map((item) => (
+
+ handlePageSelect(item.id, true)} />
+
+ ))}
+
+
+
+
+
);
};
diff --git a/client/src/constants/size.ts b/client/src/constants/size.ts
index 88385233..9cdfb739 100644
--- a/client/src/constants/size.ts
+++ b/client/src/constants/size.ts
@@ -7,5 +7,6 @@ export const PAGE = {
};
export const SIDE_BAR = {
+ MIN_WIDTH: 40,
WIDTH: 300,
};
diff --git a/client/src/features/page/hooks/usePage.ts b/client/src/features/page/hooks/usePage.ts
index ee5c3690..30defcd6 100644
--- a/client/src/features/page/hooks/usePage.ts
+++ b/client/src/features/page/hooks/usePage.ts
@@ -1,6 +1,7 @@
+import { useEffect, useState } from "react";
import { PAGE, SIDE_BAR } from "@constants/size";
import { SPACING } from "@constants/spacing";
-import { useState } from "react";
+import { useIsSidebarOpen } from "src/stores/useSidebarStore";
import { Position, Size } from "src/types/page";
const PADDING = SPACING.MEDIUM * 2;
@@ -12,6 +13,35 @@ export const usePage = ({ x, y }: Position) => {
height: PAGE.HEIGHT,
});
+ const isSidebarOpen = useIsSidebarOpen();
+
+ const getSidebarWidth = () => (isSidebarOpen ? SIDE_BAR.WIDTH : SIDE_BAR.MIN_WIDTH);
+
+ useEffect(() => {
+ // x 범위 넘어가면 x 위치 조정
+ const sidebarWidth = getSidebarWidth();
+ if (position.x > window.innerWidth - size.width - sidebarWidth - PADDING) {
+ // 만약 최대화 상태라면(사이드바 열었을때, 사이드바가 화면을 가린다면), 포지션 0으로 바꾸고 width도 재조정
+ // 만약 최대화가 아니라면, 포지션만 조정하고, 사이즈는 그대로
+ if (size.width > window.innerWidth - sidebarWidth - PADDING) {
+ setPosition({ x: 0, y: position.y });
+ setSize({
+ width: window.innerWidth - sidebarWidth - PADDING,
+ height: size.height,
+ });
+ } else {
+ setPosition({
+ x: position.x - sidebarWidth + PADDING,
+ y: position.y,
+ });
+ setSize({
+ width: size.width,
+ height: size.height,
+ });
+ }
+ }
+ }, [isSidebarOpen]);
+
const pageDrag = (e: React.PointerEvent) => {
e.preventDefault();
const startX = e.clientX - position.x;
@@ -20,7 +50,7 @@ export const usePage = ({ x, y }: Position) => {
const handleDragMove = (e: PointerEvent) => {
const newX = Math.max(
0,
- Math.min(window.innerWidth - size.width - SIDE_BAR.WIDTH - PADDING, e.clientX - startX),
+ Math.min(window.innerWidth - size.width - getSidebarWidth() - PADDING, e.clientX - startX),
);
const newY = Math.max(
0,
@@ -51,7 +81,7 @@ export const usePage = ({ x, y }: Position) => {
const newWidth = Math.max(
PAGE.MIN_WIDTH,
- Math.min(startWidth + deltaX, window.innerWidth - position.x - SIDE_BAR.WIDTH - PADDING),
+ Math.min(startWidth + deltaX, window.innerWidth - position.x - getSidebarWidth() - PADDING),
);
const newHeight = Math.max(
@@ -81,7 +111,7 @@ export const usePage = ({ x, y }: Position) => {
const pageMaximize = () => {
setPosition({ x: 0, y: 0 });
setSize({
- width: window.innerWidth - SIDE_BAR.WIDTH - PADDING,
+ width: window.innerWidth - getSidebarWidth() - PADDING,
height: window.innerHeight - PADDING,
});
};
diff --git a/client/src/stores/useSidebarStore.ts b/client/src/stores/useSidebarStore.ts
new file mode 100644
index 00000000..59d8f220
--- /dev/null
+++ b/client/src/stores/useSidebarStore.ts
@@ -0,0 +1,18 @@
+import { create } from "zustand";
+
+interface SidebarStore {
+ isSidebarOpen: boolean;
+ actions: {
+ toggleSidebar: () => void;
+ };
+}
+
+const useSidebarStore = create