Spaces:
Sleeping
Sleeping
Download frontend/src/hooks/usePanelResize.js from FrictionAI/SokratesAI: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/FrictionAI/SokratesAI/resolve/f444dc0a5b1008baf052d99628565dfd4db662ee/frontend/src/hooks/usePanelResize.js
- Command line
-
hf download hf://spaces/FrictionAI/SokratesAI@f444dc0a5b1008baf052d99628565dfd4db662ee/frontend/src/hooks/usePanelResize.js
-
curl -L -o usePanelResize.js https://huggingface.co/spaces/FrictionAI/SokratesAI/resolve/f444dc0a5b1008baf052d99628565dfd4db662ee/frontend/src/hooks/usePanelResize.js
1.37 kB
| import { useState, useEffect, useRef } from 'react'; | |
| export const usePanelResize = (initialWidth = 40) => { | |
| const [leftPanelWidth, setLeftPanelWidth] = useState(initialWidth); | |
| const [isDragging, setIsDragging] = useState(false); | |
| const containerRef = useRef(null); | |
| const handleMouseDown = (e) => { | |
| setIsDragging(true); | |
| e.preventDefault(); | |
| }; | |
| const handleMouseMove = (e) => { | |
| if (!isDragging || !containerRef.current) return; | |
| const containerRect = containerRef.current.getBoundingClientRect(); | |
| const newLeftWidth = ((e.clientX - containerRect.left) / containerRect.width) * 100; | |
| if (newLeftWidth >= 20 && newLeftWidth <= 80) { | |
| setLeftPanelWidth(newLeftWidth); | |
| } | |
| }; | |
| const handleMouseUp = () => { | |
| setIsDragging(false); | |
| }; | |
| useEffect(() => { | |
| if (isDragging) { | |
| document.addEventListener('mousemove', handleMouseMove); | |
| document.addEventListener('mouseup', handleMouseUp); | |
| return () => { | |
| document.removeEventListener('mousemove', handleMouseMove); | |
| document.removeEventListener('mouseup', handleMouseUp); | |
| }; | |
| } | |
| }, [isDragging]); | |
| return { | |
| leftPanelWidth, | |
| isDragging, | |
| containerRef, | |
| handleMouseDown | |
| }; | |
| }; |