feat(ui): support a min expanded size for collapsible panels

This commit is contained in:
psychedelicious
2025-07-07 18:55:32 +10:00
parent 702cb2cb1e
commit ecedfce758
4 changed files with 26 additions and 9 deletions

View File

@@ -24,9 +24,11 @@ export const LEFT_PANEL_MIN_SIZE_PX = 420;
export const RIGHT_PANEL_MIN_SIZE_PX = 420;
export const BOARD_PANEL_MIN_HEIGHT_PX = 36;
export const BOARD_PANEL_MIN_EXPANDED_HEIGHT_PX = 128;
export const BOARD_PANEL_DEFAULT_HEIGHT_PX = 232;
export const GALLERY_PANEL_MIN_HEIGHT_PX = 36;
export const GALLERY_PANEL_MIN_EXPANDED_HEIGHT_PX = 128;
export const GALLERY_PANEL_DEFAULT_HEIGHT_PX = 232;
export const LAYERS_PANEL_MIN_HEIGHT_PX = 36;

View File

@@ -21,7 +21,8 @@ export const useCollapsibleGridviewPanel = (
panelId: string,
orientation: 'horizontal' | 'vertical',
defaultSize: number,
collapsedSize?: number
collapsedSize?: number,
minExpandedSize?: number
) => {
const $isCollapsed = useState(() => atom(false))[0];
const lastExpandedSizeRef = useRef<number>(0);
@@ -46,12 +47,18 @@ export const useCollapsibleGridviewPanel = (
if (!panel || !(panel instanceof GridviewPanel)) {
return;
}
if (orientation === 'vertical') {
panel.api.setSize({ height: lastExpandedSizeRef.current || defaultSize });
} else {
panel.api.setSize({ width: lastExpandedSizeRef.current || defaultSize });
let newSize = lastExpandedSizeRef.current || defaultSize;
if (minExpandedSize && newSize < minExpandedSize) {
newSize = minExpandedSize;
}
}, [defaultSize, orientation, panelId, tab]);
if (orientation === 'vertical') {
panel.api.setSize({ height: newSize });
} else {
panel.api.setSize({ width: newSize });
}
}, [defaultSize, minExpandedSize, orientation, panelId, tab]);
const toggle = useCallback(() => {
const panel = navigationApi.getPanel(tab, panelId);