editor-sidebar.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Panel, PanelGroup } from 'react-resizable-panels'
  2. import { VerticalResizeHandle } from '@/features/ide-react/components/resize/vertical-resize-handle'
  3. import { FileTree } from '@/features/ide-react/components/file-tree'
  4. import classNames from 'classnames'
  5. import { useLayoutContext } from '@/shared/context/layout-context'
  6. import { OutlineContainer } from '@/features/outline/components/outline-container'
  7. import { useOutlinePane } from '@/features/ide-react/hooks/use-outline-pane'
  8. import React, { ElementType } from 'react'
  9. import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
  10. import { t } from 'i18next'
  11. const editorSidebarComponents = importOverleafModules(
  12. 'editorSidebarComponents'
  13. ) as { import: { default: ElementType }; path: string }[]
  14. export default function EditorSidebar() {
  15. const { view } = useLayoutContext()
  16. const { outlineEnabled, outlinePanelRef } = useOutlinePane()
  17. return (
  18. <nav
  19. className={classNames('ide-react-editor-sidebar', {
  20. hidden: view === 'history',
  21. })}
  22. aria-label={t('project_files_outline')}
  23. >
  24. {editorSidebarComponents.map(
  25. ({ import: { default: Component }, path }) => (
  26. <Component key={path} />
  27. )
  28. )}
  29. <PanelGroup autoSaveId="ide-editor-sidebar-layout" direction="vertical">
  30. <Panel
  31. defaultSize={50}
  32. minSize={25}
  33. className="ide-react-file-tree-panel"
  34. id="panel-file-tree"
  35. order={1}
  36. >
  37. <FileTree />
  38. </Panel>
  39. <VerticalResizeHandle disabled={!outlineEnabled} />
  40. <Panel
  41. defaultSize={50}
  42. maxSize={75}
  43. id="panel-outline"
  44. order={2}
  45. collapsible
  46. ref={outlinePanelRef}
  47. style={{ minHeight: 32 }} // keep the header visible
  48. >
  49. <OutlineContainer />
  50. </Panel>
  51. </PanelGroup>
  52. </nav>
  53. )
  54. }