overleaf/services/web/frontend/js/features/ide-react/hooks/use-collapsible-panel.ts
Alf Eaton e7dfd14986 Upgrade react-resizable-panels (#16321)
GitOrigin-RevId: 524257c441fc98ffc0e3da6f1e703ebdfbfbffb7
2023-12-21 09:03:02 +00:00

20 lines
538 B
TypeScript

import { RefObject, useEffect } from 'react'
import { ImperativePanelHandle } from 'react-resizable-panels'
export default function useCollapsiblePanel(
panelIsOpen: boolean,
panelRef: RefObject<ImperativePanelHandle>
) {
// collapse the panel when it is toggled closed (including on initial layout)
useEffect(() => {
const panelHandle = panelRef.current
if (panelHandle) {
if (panelIsOpen) {
panelHandle.expand()
} else {
panelHandle.collapse()
}
}
}, [panelIsOpen, panelRef])
}