mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
e7dfd14986
GitOrigin-RevId: 524257c441fc98ffc0e3da6f1e703ebdfbfbffb7
20 lines
538 B
TypeScript
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])
|
|
}
|