Files
Stirling-PDF/frontend/src/core/utils/sidebarUtils.ts
T
James BruntonandGitHub d2b38ef4b8 Restructure frontend code to allow for extensions (#4721)
# Description of Changes
Move frontend code into `core` folder and add infrastructure for
`proprietary` folder to include premium, non-OSS features
2025-10-28 10:29:36 +00:00

34 lines
1.2 KiB
TypeScript

import { SidebarRefs, SidebarState, SidebarInfo } from '@app/types/sidebar';
/**
* Gets the All tools sidebar information using React refs and state
* @param refs - Object containing refs to sidebar elements
* @param state - Current sidebar state
* @returns Object containing the sidebar rect and whether the tool panel is active
*/
export function getSidebarInfo(refs: SidebarRefs, state: SidebarState): SidebarInfo {
const { quickAccessRef, toolPanelRef } = refs;
const { sidebarsVisible, readerMode } = state;
// Determine if tool panel should be active based on state
const isToolPanelActive = sidebarsVisible && !readerMode;
let rect: DOMRect | null = null;
if (isToolPanelActive && toolPanelRef.current) {
// Tool panel is expanded: use its rect
rect = toolPanelRef.current.getBoundingClientRect();
} else if (quickAccessRef.current) {
// Fall back to quick access bar
// This probably isn't needed but if we ever have tooltips or modals that need to be positioned relative to the quick access bar, we can use this
rect = quickAccessRef.current.getBoundingClientRect();
}
return {
rect,
isToolPanelActive,
sidebarState: state
};
}