Skip to content

Commit ecedfce

Browse files
feat(ui): support a min expanded size for collapsible panels
1 parent 702cb2c commit ecedfce

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

invokeai/frontend/web/src/features/gallery/components/BoardsListPanelContent.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { GalleryHeader } from 'features/gallery/components/GalleryHeader';
99
import { selectBoardSearchText } from 'features/gallery/store/gallerySelectors';
1010
import { boardSearchTextChanged } from 'features/gallery/store/gallerySlice';
1111
import { useAutoLayoutContext } from 'features/ui/layouts/auto-layout-context';
12-
import { BOARD_PANEL_DEFAULT_HEIGHT_PX, BOARD_PANEL_MIN_HEIGHT_PX, BOARDS_PANEL_ID } from 'features/ui/layouts/shared';
12+
import {
13+
BOARD_PANEL_DEFAULT_HEIGHT_PX,
14+
BOARD_PANEL_MIN_EXPANDED_HEIGHT_PX,
15+
BOARD_PANEL_MIN_HEIGHT_PX,
16+
BOARDS_PANEL_ID,
17+
} from 'features/ui/layouts/shared';
1318
import { useCollapsibleGridviewPanel } from 'features/ui/layouts/use-collapsible-gridview-panel';
1419
import type { CSSProperties } from 'react';
1520
import { memo, useCallback } from 'react';
@@ -27,7 +32,8 @@ export const BoardsPanel = memo(() => {
2732
BOARDS_PANEL_ID,
2833
'vertical',
2934
BOARD_PANEL_DEFAULT_HEIGHT_PX,
30-
BOARD_PANEL_MIN_HEIGHT_PX
35+
BOARD_PANEL_MIN_HEIGHT_PX,
36+
BOARD_PANEL_MIN_EXPANDED_HEIGHT_PX
3137
);
3238
const isCollapsed = useStore(collapsibleApi.$isCollapsed);
3339
const { t } = useTranslation();

invokeai/frontend/web/src/features/gallery/components/Gallery.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useAutoLayoutContext } from 'features/ui/layouts/auto-layout-context';
1010
import {
1111
GALLERY_PANEL_DEFAULT_HEIGHT_PX,
1212
GALLERY_PANEL_ID,
13+
GALLERY_PANEL_MIN_EXPANDED_HEIGHT_PX,
1314
GALLERY_PANEL_MIN_HEIGHT_PX,
1415
} from 'features/ui/layouts/shared';
1516
import { useCollapsibleGridviewPanel } from 'features/ui/layouts/use-collapsible-gridview-panel';
@@ -38,7 +39,8 @@ export const GalleryPanel = memo(() => {
3839
GALLERY_PANEL_ID,
3940
'vertical',
4041
GALLERY_PANEL_DEFAULT_HEIGHT_PX,
41-
GALLERY_PANEL_MIN_HEIGHT_PX
42+
GALLERY_PANEL_MIN_HEIGHT_PX,
43+
GALLERY_PANEL_MIN_EXPANDED_HEIGHT_PX
4244
);
4345
const isCollapsed = useStore(collapsibleApi.$isCollapsed);
4446

invokeai/frontend/web/src/features/ui/layouts/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ export const LEFT_PANEL_MIN_SIZE_PX = 420;
2424
export const RIGHT_PANEL_MIN_SIZE_PX = 420;
2525

2626
export const BOARD_PANEL_MIN_HEIGHT_PX = 36;
27+
export const BOARD_PANEL_MIN_EXPANDED_HEIGHT_PX = 128;
2728
export const BOARD_PANEL_DEFAULT_HEIGHT_PX = 232;
2829

2930
export const GALLERY_PANEL_MIN_HEIGHT_PX = 36;
31+
export const GALLERY_PANEL_MIN_EXPANDED_HEIGHT_PX = 128;
3032
export const GALLERY_PANEL_DEFAULT_HEIGHT_PX = 232;
3133

3234
export const LAYERS_PANEL_MIN_HEIGHT_PX = 36;

invokeai/frontend/web/src/features/ui/layouts/use-collapsible-gridview-panel.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const useCollapsibleGridviewPanel = (
2121
panelId: string,
2222
orientation: 'horizontal' | 'vertical',
2323
defaultSize: number,
24-
collapsedSize?: number
24+
collapsedSize?: number,
25+
minExpandedSize?: number
2526
) => {
2627
const $isCollapsed = useState(() => atom(false))[0];
2728
const lastExpandedSizeRef = useRef<number>(0);
@@ -46,12 +47,18 @@ export const useCollapsibleGridviewPanel = (
4647
if (!panel || !(panel instanceof GridviewPanel)) {
4748
return;
4849
}
50+
51+
let newSize = lastExpandedSizeRef.current || defaultSize;
52+
if (minExpandedSize && newSize < minExpandedSize) {
53+
newSize = minExpandedSize;
54+
}
55+
4956
if (orientation === 'vertical') {
50-
panel.api.setSize({ height: lastExpandedSizeRef.current || defaultSize });
57+
panel.api.setSize({ height: newSize });
5158
} else {
52-
panel.api.setSize({ width: lastExpandedSizeRef.current || defaultSize });
59+
panel.api.setSize({ width: newSize });
5360
}
54-
}, [defaultSize, orientation, panelId, tab]);
61+
}, [defaultSize, minExpandedSize, orientation, panelId, tab]);
5562

5663
const toggle = useCallback(() => {
5764
const panel = navigationApi.getPanel(tab, panelId);

0 commit comments

Comments
 (0)