File Explorer
A flexible grid/list component that provides seamless switching between grid and list layouts with customizable card rendering.
Usage
File Explorer
Files
No File Selected
Select a file from the sidebar to view its contents
import { FileExplorer } from "@/components/file-explorer"
const previewFileSystem = {
id: 'root',
name: 'my-project',
type: 'folder' as const,
expanded: true,
icon: <FolderClosed className="h-4 w-4 text-blue-500" />,
expandedIcon: <FolderOpen className="h-4 w-4 text-blue-500" />,
children: [
{
id: 'src',
name: 'src',
type: 'folder' as const,
children: [
{
id: 'file1',
name: 'example.ts',
type: 'file' as const,
language: 'typescript',
content: 'console.log("Hello world!");',
icon: <FileCode className="h-4 w-4 text-green-500" />
},
{
id: 'images',
name: 'images',
type: 'folder' as const,
icon: <FolderClosed className="h-4 w-4 text-purple-500" />,
expandedIcon: <FolderOpen className="h-4 w-4 text-purple-500" />,
children: [{
id: 'logo.png',
name: 'logo.png',
type: 'file' as const,
isImage: true,
imageUrl: 'https://via.placeholder.com/300x200/3B82F6/FFFFFF?text=Logo',
content: 'Binary image data',
icon: <ImageIcon className="h-4 w-4 text-orange-500" />
}]
}
]
}
]
}
export default function MyComponent() {
return (
<FileExplorer
initialData={previewFileSystem}
showTitle={true}
height="400px"
className="w-full"
/>
)
}
Installation
Install the File Explorer component using your preferred package manager.
npx shadcn@latest add https://rigidui.com/r/file-explorer.json
Features
The File Explorer component is packed with powerful features designed to provide an exceptional user experience.
Tree Structure
Navigate through a hierarchical file system with expandable folders and files.
File Search
Quickly find files by name with an integrated search functionality.
Copy Content
Easily copy file contents to clipboard with a single click.
Syntax Highlighting
View file contents with language-specific syntax highlighting for better readability.
Image Preview
Preview images directly in the explorer with support for multiple formats.
Accessibility
Full keyboard navigation support and screen reader compatibility.
Performance Optimized
Memoized components and optimized rendering for large file structures.
Error Handling
Robust error boundaries and graceful fallbacks for better user experience.
Props
Prop | Type | Default |
---|---|---|
initialData? | FolderType | defaultFileSystemData |
className? | string | '' |
cardClassName? | string | '' |
title? | string | 'File Explorer' |
showTitle? | boolean | true |
height? | string | 'calc(100vh-200px)' |
fileContentHeight? | string | '100%' |
defaultFileIcon? | React.ReactNode | <FileText className="h-4 w-4 text-muted-foreground" /> |
defaultFolderIcon? | React.ReactNode | <Folder className="h-4 w-4 text-yellow-500" /> |
defaultFolderOpenIcon? | React.ReactNode | <FolderOpen className="h-4 w-4 text-yellow-500" /> |
onFileSelect? | (file: FileType) => void | undefined |
onFolderToggle? | (folderId: string, isExpanded: boolean) => void | undefined |
readOnly? | boolean | false |
allowedFileTypes? | string[] | undefined |
maxFileSize? | number | undefined |
loading? | boolean | false |
onRefresh? | () => void | undefined |