mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(trace viewer): split view resizer should work (#8021)
This commit is contained in:
parent
a8d404cd29
commit
7da669bcc4
@ -24,7 +24,7 @@ export interface SplitViewProps {
|
||||
orientation?: 'vertical' | 'horizontal',
|
||||
}
|
||||
|
||||
const kMinSidebarSize = 50;
|
||||
const kMinSize = 50;
|
||||
|
||||
export const SplitView: React.FC<SplitViewProps> = ({
|
||||
sidebarSize,
|
||||
@ -33,7 +33,7 @@ export const SplitView: React.FC<SplitViewProps> = ({
|
||||
orientation = 'vertical',
|
||||
children
|
||||
}) => {
|
||||
const [size, setSize] = React.useState<number>(Math.max(kMinSidebarSize, sidebarSize));
|
||||
const [size, setSize] = React.useState<number>(Math.max(kMinSize, sidebarSize));
|
||||
const [resizing, setResizing] = React.useState<{ offset: number, size: number } | null>(null);
|
||||
|
||||
const childrenArray = React.Children.toArray(children);
|
||||
@ -63,11 +63,13 @@ export const SplitView: React.FC<SplitViewProps> = ({
|
||||
if (!event.buttons) {
|
||||
setResizing(null);
|
||||
} else if (resizing) {
|
||||
const offset = orientation === 'vertical' ? event.clientY : event.clientX;
|
||||
const delta = offset - resizing.offset;
|
||||
const newSize = sidebarIsFirst ? resizing.size + delta : resizing.size - delta;
|
||||
|
||||
const splitView = (event.target as HTMLElement).parentElement!;
|
||||
const rect = splitView.getBoundingClientRect();
|
||||
const clientOffset = orientation === 'vertical' ? event.clientY - rect.y : event.clientX - rect.x;
|
||||
const resizingPosition = sidebarIsFirst ? clientOffset : resizing.size - clientOffset + resizing.offset;
|
||||
const size = Math.min(Math.max(kMinSidebarSize, resizingPosition), (orientation === 'vertical' ? rect.height : rect.width) - kMinSidebarSize);
|
||||
const size = Math.min(Math.max(kMinSize, newSize), (orientation === 'vertical' ? rect.height : rect.width) - kMinSize);
|
||||
setSize(size);
|
||||
}
|
||||
}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user