MCPcopy Create free account
hub / github.com/esengine/esengine / ResizablePanel

Function ResizablePanel

packages/editor-app/src/components/ResizablePanel.tsx:15–172  ·  view source on GitHub ↗
({
    direction,
    leftOrTop,
    rightOrBottom,
    defaultSize = 250,
    minSize = 150,
    maxSize = 600,
    side = 'left',
    storageKey
}: ResizablePanelProps)

Source from the content-addressed store, hash-verified

13}
14
15export function ResizablePanel({
16 direction,
17 leftOrTop,
18 rightOrBottom,
19 defaultSize = 250,
20 minSize = 150,
21 maxSize = 600,
22 side = 'left',
23 storageKey
24}: ResizablePanelProps) {
25 const getInitialSize = () => {
26 if (storageKey) {
27 const saved = localStorage.getItem(storageKey);
28 if (saved) {
29 const parsedSize = parseInt(saved, 10);
30 if (!isNaN(parsedSize)) {
31 return Math.max(minSize, Math.min(maxSize, parsedSize));
32 }
33 }
34 }
35 return defaultSize;
36 };
37
38 const [size, setSize] = useState(getInitialSize);
39 const [isDragging, setIsDragging] = useState(false);
40 const containerRef = useRef<HTMLDivElement>(null);
41
42 useEffect(() => {
43 if (storageKey && !isDragging) {
44 localStorage.setItem(storageKey, size.toString());
45 }
46 }, [size, isDragging, storageKey]);
47
48 useEffect(() => {
49 if (!isDragging) return;
50
51 const handleMouseMove = (e: MouseEvent) => {
52 if (!containerRef.current) return;
53
54 const rect = containerRef.current.getBoundingClientRect();
55 let newSize: number;
56
57 if (direction === 'horizontal') {
58 if (side === 'right') {
59 newSize = rect.right - e.clientX;
60 } else {
61 newSize = e.clientX - rect.left;
62 }
63 } else {
64 if (side === 'bottom') {
65 newSize = rect.bottom - e.clientY;
66 } else {
67 newSize = e.clientY - rect.top;
68 }
69 }
70
71 newSize = Math.max(minSize, Math.min(maxSize, newSize));
72 setSize(newSize);

Callers

nothing calls this directly

Calls 3

toStringMethod · 0.45
addEventListenerMethod · 0.45
removeEventListenerMethod · 0.45

Tested by

no test coverage detected