mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-11 15:26:39 -05:00
20 lines
437 B
TypeScript
20 lines
437 B
TypeScript
|
import { RefObject, useEffect } from 'react'
|
||
|
import { ImperativePanelHandle } from 'react-resizable-panels'
|
||
|
|
||
|
export default function useCollapsiblePanel(
|
||
|
panelIsOpen: boolean,
|
||
|
panelRef: RefObject<ImperativePanelHandle>
|
||
|
) {
|
||
|
useEffect(() => {
|
||
|
const panel = panelRef.current
|
||
|
if (!panel) {
|
||
|
return
|
||
|
}
|
||
|
if (panelIsOpen) {
|
||
|
panel.expand()
|
||
|
} else {
|
||
|
panel.collapse()
|
||
|
}
|
||
|
}, [panelIsOpen, panelRef])
|
||
|
}
|