2023-10-02 05:35:02 -04:00
|
|
|
import { RefObject, useEffect } from 'react'
|
|
|
|
import { ImperativePanelHandle } from 'react-resizable-panels'
|
|
|
|
|
|
|
|
export default function useCollapsiblePanel(
|
|
|
|
panelIsOpen: boolean,
|
|
|
|
panelRef: RefObject<ImperativePanelHandle>
|
|
|
|
) {
|
2023-12-20 07:18:12 -05:00
|
|
|
// collapse the panel when it is toggled closed (including on initial layout)
|
2023-10-02 05:35:02 -04:00
|
|
|
useEffect(() => {
|
2023-12-20 06:48:24 -05:00
|
|
|
const panelHandle = panelRef.current
|
|
|
|
|
|
|
|
if (panelHandle) {
|
2023-12-20 07:18:12 -05:00
|
|
|
if (panelIsOpen) {
|
|
|
|
panelHandle.expand()
|
2023-12-05 04:34:21 -05:00
|
|
|
} else {
|
2023-12-20 07:18:12 -05:00
|
|
|
panelHandle.collapse()
|
2023-12-05 04:34:21 -05:00
|
|
|
}
|
2023-10-02 05:35:02 -04:00
|
|
|
}
|
|
|
|
}, [panelIsOpen, panelRef])
|
|
|
|
}
|