Skip to content

File Explorer

The FileExplorer component is used to display file and folder hierarchies in a collapsible/expandable structure. It supports features like active states, links, nested levels, and tooltips.

Variations

Basic file explorer

Create a simple file explorer with folders and files. The explorer automatically handles expand/collapse interactions.

Nested folders

You can nest folders within folders to create deep hierarchies.

Active file

Highlight the currently active file or folder using the isActive prop.

Make files and folders navigable by providing the link prop.

Tooltips

Add tooltips to files for additional information.

Active folder

You can also highlight folders using the isActive prop.

Full project structure

This comprehensive example demonstrates all features of the FileExplorer component including:

  • Multiple nested folder levels
  • Active file highlighting
  • Links for navigation
  • Tooltips for additional context
  • Mixed file and folder structures
  • Click handlers for file selection

Custom content

The FileExplorer.CustomItem component allows you to add custom, non-interactive content to your file explorer. Use it when you need to display informational content, placeholders, or any custom elements that don’t require file/folder interactive behavior.

Installation

import { FileExplorer } from '@harnessio/ui/components'
//...
const [expandedFolders, setExpandedFolders] = useState(['src']);
return (
<FileExplorer.Root value={expandedFolders} onValueChange={setExpandedFolders}>
<FileExplorer.FolderItem
value="src"
level={0}
content={
<FileExplorer.Root value={expandedFolders} onValueChange={setExpandedFolders}>
<FileExplorer.FileItem level={1}>index.ts</FileExplorer.FileItem>
<FileExplorer.FileItem level={1}>App.tsx</FileExplorer.FileItem>
{/* Use CustomItem for custom non-interactive content */}
<FileExplorer.CustomItem className="text-cn-3 pl-cn-lg">
2 files total
</FileExplorer.CustomItem>
</FileExplorer.Root>
}
>
src
</FileExplorer.FolderItem>
</FileExplorer.Root>
)