Sidebar component displays a hierarchical file tree for navigating the opened folder. It supports expanding directories, displaying folder icons, and selecting files for editing.
Usage
Features
File Tree Display
The Sidebar renders a recursive tree structure of files and folders:Folder Navigation
Folders can be expanded to reveal their contents. The component lazy-loads directory contents when expanded:File Selection
Clicking on a file triggers thehandleFileSelect callback from the editor context, which opens the file in the editor.
Visual Indicators
- Folder icons:
FolderOpenwhen expanded,FolderClosedwhen collapsed - Chevron icons:
ChevronUpwhen expanded,ChevronDownwhen collapsed - Color differentiation: Directories have full opacity, files have 50% opacity
- Indentation: Each nesting level adds 15px of padding
TreeItem Component
The internalTreeItem component handles individual file/folder rendering:
Props
File or directory information
Nesting depth for indentation calculation. Top-level items have
level={0}State
Whether the folder is currently expanded (shows children)
Array of child items loaded when folder is expanded
Context Integration
The Sidebar uses theuseEditor hook to access:
Root-level files and folders in the opened directory. Hidden files (starting with
.) are filtered outTheme configuration for styling the sidebar
Function called when a file is clicked. Opens the file in the editor
IPC Integration
The Sidebar communicates with the Electron main process through theelectronAPI:
readDirectory
read-directory
Parameters:
dirPath(string): Absolute path to the directory
FileItem objects
Styling
The sidebar uses theme-aware styling:Layout
- Width: Minimum 260px with horizontal scroll
- Height:
calc(100% - 38px)to accommodate InfoBar - Padding: Item indentation based on nesting level:
10 + level * 15px
Hidden Files
Files and folders starting with. are automatically filtered:
Example: Custom Integration
Reference
Source:src/components/Sidebar.tsx
Dependencies:
lucide-react- Icon components (ChevronDown, ChevronUp, FolderClosed, FolderOpen)electron/preload- FileItem type definition
InfoBar- Displayed at the bottom of the sidebar