overleaf/services/web/frontend/js/features/ide-react/hooks/use-sidebar-pane.ts
Alf Eaton d5b3c10cb5 Upgrade react-resizable-panels (#15998)
GitOrigin-RevId: af799f1a5b4945ad2acbb460806d559fae7416b9
2023-12-06 09:04:40 +00:00

34 lines
873 B
TypeScript

import { useCallback, useState } from 'react'
import useFixedSizeColumn from '@/features/ide-react/hooks/use-fixed-size-column'
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
export const useSidebarPane = () => {
const [isOpen, setIsOpen] = useState(true)
const [resizing, setResizing] = useState(false)
const { fixedPanelRef, handleLayout } = useFixedSizeColumn(isOpen)
useCollapsiblePanel(isOpen, fixedPanelRef)
const togglePane = useCallback(() => {
setIsOpen(value => !value)
}, [])
const handlePaneExpand = useCallback(() => {
setIsOpen(true)
}, [])
const handlePaneCollapse = useCallback(() => {
setIsOpen(false)
}, [])
return {
isOpen,
setIsOpen,
fixedPanelRef,
handleLayout,
togglePane,
handlePaneExpand,
handlePaneCollapse,
resizing,
setResizing,
}
}