-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加侧边栏拖拽调整宽度
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
|
||
interface ResizeHandleProps { | ||
onResize: (width: number) => void; | ||
} | ||
|
||
export const ResizeHandle: React.FC<ResizeHandleProps> = ({ onResize }) => { | ||
const handleDrag = useCallback((e: MouseEvent) => { | ||
const width = e.clientX; | ||
if (width >= 420 && width <= 600) { | ||
onResize(width); | ||
} | ||
}, [onResize]); | ||
|
||
const handleDragEnd = useCallback(() => { | ||
document.removeEventListener('mousemove', handleDrag); | ||
document.removeEventListener('mouseup', handleDragEnd); | ||
document.body.style.cursor = 'default'; | ||
}, [handleDrag]); | ||
|
||
const startResize = useCallback(() => { | ||
document.addEventListener('mousemove', handleDrag); | ||
document.addEventListener('mouseup', handleDragEnd); | ||
document.body.style.cursor = 'ew-resize'; | ||
}, [handleDrag, handleDragEnd]); | ||
|
||
return ( | ||
<div | ||
className="absolute right-0 top-0 w-1 h-full cursor-ew-resize hover:bg-blue-500/50 transition-colors" | ||
onMouseDown={startResize} | ||
/> | ||
); | ||
}; |