mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -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])
|
||
|
}
|