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