[WEB-4477] fix: sidebar resize behaviour #7386
This commit is contained in:
parent
5fbe411e04
commit
bb48250467
1 changed files with 16 additions and 7 deletions
|
|
@ -50,6 +50,8 @@ export function ResizableSidebar({
|
||||||
const [isHoveringTrigger, setIsHoveringTrigger] = useState(false);
|
const [isHoveringTrigger, setIsHoveringTrigger] = useState(false);
|
||||||
// refs
|
// refs
|
||||||
const peekTimeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
const peekTimeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
||||||
|
const initialWidthRef = useRef<number>(0);
|
||||||
|
const initialMouseXRef = useRef<number>(0);
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
const setShowPeek = useCallback(
|
const setShowPeek = useCallback(
|
||||||
|
|
@ -62,15 +64,22 @@ export function ResizableSidebar({
|
||||||
const handleResize = useCallback(
|
const handleResize = useCallback(
|
||||||
(e: MouseEvent) => {
|
(e: MouseEvent) => {
|
||||||
if (!isResizing) return;
|
if (!isResizing) return;
|
||||||
const newWidth = Math.min(Math.max(e.clientX, minWidth), maxWidth);
|
|
||||||
|
const deltaX = e.clientX - initialMouseXRef.current;
|
||||||
|
const newWidth = Math.min(Math.max(initialWidthRef.current + deltaX, minWidth), maxWidth);
|
||||||
setWidth(newWidth);
|
setWidth(newWidth);
|
||||||
},
|
},
|
||||||
[isResizing, minWidth, maxWidth, setWidth]
|
[isResizing, minWidth, maxWidth, setWidth]
|
||||||
);
|
);
|
||||||
|
|
||||||
const startResizing = useCallback(() => {
|
const startResizing = useCallback(
|
||||||
|
(e: React.MouseEvent) => {
|
||||||
setIsResizing(true);
|
setIsResizing(true);
|
||||||
}, []);
|
initialWidthRef.current = width;
|
||||||
|
initialMouseXRef.current = e.clientX;
|
||||||
|
},
|
||||||
|
[width]
|
||||||
|
);
|
||||||
|
|
||||||
const stopResizing = useCallback(() => {
|
const stopResizing = useCallback(() => {
|
||||||
setIsResizing(false);
|
setIsResizing(false);
|
||||||
|
|
@ -199,7 +208,7 @@ export function ResizableSidebar({
|
||||||
>
|
>
|
||||||
<aside
|
<aside
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/sidebar h-full w-full bg-custom-background-100 overflow-hidden relative flex flex-col pt-3",
|
"group/sidebar h-full w-full bg-custom-sidebar-background-100 overflow-hidden relative flex flex-col pt-3",
|
||||||
isAnyExtendedSidebarExpanded && "rounded-none"
|
isAnyExtendedSidebarExpanded && "rounded-none"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -215,7 +224,7 @@ export function ResizableSidebar({
|
||||||
)}
|
)}
|
||||||
// onDoubleClick toggle sidebar
|
// onDoubleClick toggle sidebar
|
||||||
onDoubleClick={() => toggleCollapsed()}
|
onDoubleClick={() => toggleCollapsed()}
|
||||||
onMouseDown={startResizing}
|
onMouseDown={(e) => startResizing(e)}
|
||||||
role="separator"
|
role="separator"
|
||||||
aria-label="Resize sidebar"
|
aria-label="Resize sidebar"
|
||||||
/>
|
/>
|
||||||
|
|
@ -273,7 +282,7 @@ export function ResizableSidebar({
|
||||||
)}
|
)}
|
||||||
// onDoubleClick toggle sidebar
|
// onDoubleClick toggle sidebar
|
||||||
onDoubleClick={() => toggleCollapsed()}
|
onDoubleClick={() => toggleCollapsed()}
|
||||||
onMouseDown={startResizing}
|
onMouseDown={(e) => startResizing(e)}
|
||||||
role="separator"
|
role="separator"
|
||||||
aria-label="Resize sidebar"
|
aria-label="Resize sidebar"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue