Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make DBRowSidePanel resizeable #508

Merged
merged 7 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/app/src/components/DBRowSidePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
createContext,
MouseEventHandler,
useCallback,
useContext,
useId,
Expand Down Expand Up @@ -80,6 +81,25 @@ export default function DBRowSidePanel({
parseAsStringEnum<Tab>(Object.values(Tab)).withDefault(Tab.Parsed),
);

const [panelWidth, setPanelWidth] = useState(
Math.round(window.innerWidth * 0.8),
);
const handleResize = useCallback((e: MouseEvent) => {
const offsetRight =
document.body.offsetWidth - (e.clientX - document.body.offsetLeft);
const maxWidth = document.body.offsetWidth - 25;
setPanelWidth(Math.min(offsetRight + 3, maxWidth)); // ensure we bury the cursor in the panel
}, []);
const startResize: MouseEventHandler<HTMLDivElement> = useCallback(e => {
e.preventDefault();
document.addEventListener('mousemove', handleResize);
document.addEventListener('mouseup', endResize);
}, []);
const endResize = useCallback(() => {
document.removeEventListener('mousemove', handleResize);
document.removeEventListener('mouseup', endResize);
}, []);

// const [queryTab, setQueryTab] = useQueryParam(
// 'tb',
// withDefault(StringParam, undefined),
Expand Down Expand Up @@ -162,12 +182,13 @@ export default function DBRowSidePanel({
}
}}
direction="right"
size={'80vw'}
size={panelWidth}
zIndex={drawerZIndex}
enableOverlay={subDrawerOpen}
>
<ZIndexContext.Provider value={drawerZIndex}>
<div className={styles.panel} ref={drawerRef}>
<Box className={styles.panelDragBar} onMouseDown={startResize} />
{isRowLoading && (
<div className={styles.loadingState}>Loading...</div>
)}
Expand Down
13 changes: 13 additions & 0 deletions packages/app/styles/LogSidePanel.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ $padding-x: 24px;
border-left: 1px solid $slate-900;
}

.panelDragBar {
kruegernet marked this conversation as resolved.
Show resolved Hide resolved
position: absolute;
width: 3px;
height: 100%;
cursor: col-resize;
background-color: transparent;

&:hover {
background-color: $slate-900;
transition: background-color 0.2s ease-in-out;
}
}

.panelHeader {
display: flex;
justify-content: space-between;
Expand Down