feat(ui): improved panel interactions

This commit is contained in:
psychedelicious 2024-01-03 21:16:47 +11:00 committed by Kent Keirsey
parent 4ce9f9dc36
commit 8a6f03cd46
3 changed files with 36 additions and 10 deletions

View File

@ -192,6 +192,7 @@ const InvokeTabs = () => {
expand: expandOptionsPanel, expand: expandOptionsPanel,
collapse: collapseOptionsPanel, collapse: collapseOptionsPanel,
toggle: toggleOptionsPanel, toggle: toggleOptionsPanel,
onDoubleClickHandle: onDoubleClickOptionsPanelHandle,
} = usePanel(optionsPanelUsePanelOptions); } = usePanel(optionsPanelUsePanelOptions);
const { const {
@ -204,10 +205,19 @@ const InvokeTabs = () => {
expand: expandGalleryPanel, expand: expandGalleryPanel,
collapse: collapseGalleryPanel, collapse: collapseGalleryPanel,
toggle: toggleGalleryPanel, toggle: toggleGalleryPanel,
onDoubleClickHandle: onDoubleClickGalleryPanelHandle,
} = usePanel(galleryPanelUsePanelOptions); } = usePanel(galleryPanelUsePanelOptions);
useHotkeys('g', toggleGalleryPanel, []); useHotkeys('g', toggleGalleryPanel, [toggleGalleryPanel]);
useHotkeys(['t', 'o'], toggleOptionsPanel, []); useHotkeys(['t', 'o'], toggleOptionsPanel, [toggleOptionsPanel]);
useHotkeys(
'shift+r',
() => {
resetOptionsPanel();
resetGalleryPanel();
},
[resetOptionsPanel, resetGalleryPanel]
);
useHotkeys( useHotkeys(
'f', 'f',
() => { () => {
@ -219,7 +229,14 @@ const InvokeTabs = () => {
collapseGalleryPanel(); collapseGalleryPanel();
} }
}, },
[isOptionsPanelCollapsed, isGalleryPanelCollapsed] [
isOptionsPanelCollapsed,
isGalleryPanelCollapsed,
expandOptionsPanel,
expandGalleryPanel,
collapseOptionsPanel,
collapseGalleryPanel,
]
); );
return ( return (
@ -265,7 +282,7 @@ const InvokeTabs = () => {
</Panel> </Panel>
<ResizeHandle <ResizeHandle
id="options-main-handle" id="options-main-handle"
onDoubleClick={resetOptionsPanel} onDoubleClick={onDoubleClickOptionsPanelHandle}
orientation="vertical" orientation="vertical"
/> />
</> </>
@ -279,8 +296,8 @@ const InvokeTabs = () => {
<> <>
<ResizeHandle <ResizeHandle
id="main-gallery-handle" id="main-gallery-handle"
onDoubleClick={resetGalleryPanel}
orientation="vertical" orientation="vertical"
onDoubleClick={onDoubleClickGalleryPanelHandle}
/> />
<Panel <Panel
id="gallery-panel" id="gallery-panel"

View File

@ -64,18 +64,18 @@ export const resizeHandleTheme = defineStyleConfig({
}, },
'.resize-handle-drag-handle': { '.resize-handle-drag-handle': {
pos: 'absolute', pos: 'absolute',
borderRadius: '2px', borderRadius: '1px',
transitionProperty: 'inherit', transitionProperty: 'inherit',
transitionDuration: 'inherit', transitionDuration: 'inherit',
'&[data-orientation="horizontal"]': { '&[data-orientation="horizontal"]': {
w: '20px', w: '30px',
h: '6px', h: '6px',
insetInlineStart: '50%', insetInlineStart: '50%',
transform: 'translate(-50%, 0)', transform: 'translate(-50%, 0)',
}, },
'&[data-orientation="vertical"]': { '&[data-orientation="vertical"]': {
w: '6px', w: '6px',
h: '20px', h: '30px',
insetBlockStart: '50%', insetBlockStart: '50%',
transform: 'translate(0, -50%)', transform: 'translate(0, -50%)',
}, },

View File

@ -68,10 +68,14 @@ export type UsePanelReturn = {
*/ */
onExpand: PanelOnExpand; onExpand: PanelOnExpand;
/** /**
* Reset the panel to the minSize. If the panel is already at the minSize, collapse it. * Reset the panel to the minSize.
* This can be provided to the `onDoubleClick` prop of the panel's nearest resize handle.
*/ */
reset: () => void; reset: () => void;
/**
* Reset the panel to the minSize. If the panel is already at the minSize, collapse it.
* This should be passed to the `onDoubleClick` prop of the panel's nearest resize handle.
*/
onDoubleClickHandle: () => void;
/** /**
* Toggle the panel between collapsed and expanded. * Toggle the panel between collapsed and expanded.
*/ */
@ -183,6 +187,10 @@ export const usePanel = (arg: UsePanelOptions): UsePanelReturn => {
); );
const reset = useCallback(() => { const reset = useCallback(() => {
panelHandleRef.current?.resize(_minSize);
}, [_minSize]);
const onDoubleClickHandle = useCallback(() => {
// If the panel is really super close to the min size, collapse it // If the panel is really super close to the min size, collapse it
if (Math.abs((panelHandleRef.current?.getSize() ?? 0) - _minSize) < 0.01) { if (Math.abs((panelHandleRef.current?.getSize() ?? 0) - _minSize) < 0.01) {
collapse(); collapse();
@ -204,6 +212,7 @@ export const usePanel = (arg: UsePanelOptions): UsePanelReturn => {
expand, expand,
collapse, collapse,
resize, resize,
onDoubleClickHandle,
}; };
}; };