MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / usePanelLayout

Function usePanelLayout

packages/studio/src/hooks/usePanelLayout.ts:20–116  ·  view source on GitHub ↗
(initialState?: InitialPanelLayoutState)

Source from the content-addressed store, hash-verified

18}
19
20export function usePanelLayout(initialState?: InitialPanelLayoutState) {
21 const [leftWidth, setLeftWidth] = useState(240);
22 const [rightWidth, setRightWidth] = useState(400);
23 const [leftCollapsed, setLeftCollapsed] = useState(
24 () => readStudioUiPreferences().leftCollapsed ?? false,
25 );
26 const [rightCollapsed, setRightCollapsed] = useState(initialState?.rightCollapsed ?? true);
27 const [rightPanelTab, setRightPanelTab] = useState<RightPanelTab>(
28 initialState?.rightPanelTab ?? "renders",
29 );
30 const [rightInspectorPanes, setRightInspectorPanes] = useState<RightInspectorPanes>(() =>
31 getInitialRightInspectorPanes(initialState?.rightPanelTab),
32 );
33 const panelDragRef = useRef<{
34 side: "left" | "right";
35 startX: number;
36 startW: number;
37 } | null>(null);
38
39 const toggleLeftSidebar = useCallback(() => {
40 setLeftCollapsed((collapsed) => {
41 writeStudioUiPreferences({ leftCollapsed: !collapsed });
42 trackStudioEvent("panel_toggle", { panel: "left_sidebar", collapsed: !collapsed });
43 return !collapsed;
44 });
45 }, []);
46
47 const handlePanelResizeStart = useCallback(
48 (side: "left" | "right", e: React.PointerEvent) => {
49 e.preventDefault();
50 (e.target as HTMLElement).setPointerCapture(e.pointerId);
51 panelDragRef.current = {
52 side,
53 startX: e.clientX,
54 startW: side === "left" ? leftWidth : rightWidth,
55 };
56 },
57 [leftWidth, rightWidth],
58 );
59
60 const handlePanelResizeMove = useCallback((e: React.PointerEvent) => {
61 const drag = panelDragRef.current;
62 if (!drag) return;
63 const delta = e.clientX - drag.startX;
64 const maxLeft = Math.floor(window.innerWidth * 0.5);
65 const newW = Math.max(
66 160,
67 Math.min(
68 drag.side === "left" ? maxLeft : 600,
69 drag.startW + (drag.side === "left" ? delta : -delta),
70 ),
71 );
72 if (drag.side === "left") setLeftWidth(newW);
73 else setRightWidth(newW);
74 }, []);
75
76 const handlePanelResizeEnd = useCallback(() => {
77 panelDragRef.current = null;

Callers 1

StudioAppFunction · 0.90

Calls 4

readStudioUiPreferencesFunction · 0.90
writeStudioUiPreferencesFunction · 0.90
trackStudioEventFunction · 0.90

Tested by

no test coverage detected