File Explorer

A fully-featured, accessible file explorer component with syntax highlighting, image preview, search functionality, and keyboard navigation support. Perfect for showcasing code structures, documentation sites, or any hierarchical data visualization.

Installation

Install the File Explorer component using your preferred package manager.

npxshadcn@latest addhttps://rigidui.com/registry/file-explorer

Usage

The File Explorer component provides a comprehensive interface for browsing and viewing hierarchical file system structures with full accessibility support, performance optimizations, and extensive customization options.

Live Preview

File Explorer

Files

src

No File Selected

Select a file from the sidebar to view its contents

Discover Its 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.

API Reference

PropTypeDefaultDescription
initialDataFolderTypedefaultFileSystemDataThe initial file system data structure to display
classNamestring''Additional class names for the container
cardClassNamestring''Additional class names for the card components
titlestring'File Explorer'Title displayed above the file explorer
showTitlebooleantrueWhether to show the title or not
heightstring'calc(100vh-200px)'Height of the file explorer component
fileContentHeightstring'100%'Height of the file content display area
defaultFileIconReact.ReactNode<FileText className="h-4 w-4 text-muted-foreground" />Default icon to use for all files without a custom icon
defaultFolderIconReact.ReactNode<Folder className="h-4 w-4 text-yellow-500" />Default icon to use for closed folders without a custom icon
defaultFolderOpenIconReact.ReactNode<FolderOpen className="h-4 w-4 text-yellow-500" />Default icon to use for open folders without a custom icon
onFileSelect(file: FileType) => voidundefinedCallback function called when a file is selected
onFolderToggle(folderId: string, isExpanded: boolean) => voidundefinedCallback function called when a folder is expanded or collapsed
readOnlybooleanfalseWhether the file explorer is in read-only mode
allowedFileTypesstring[]undefinedArray of allowed file extensions for filtering
maxFileSizenumberundefinedMaximum file size in bytes for validation
loadingbooleanfalseWhether the component is in a loading state
onRefresh() => voidundefinedCallback function for the refresh button

Advanced Usage

Explore different configurations and use cases for the File Explorer component with various project structures and interactive features.

Basic Project Structure

A simple React project with source files, package.json, and README. Perfect for showcasing small projects or tutorials.

Live Preview

Basic Project

Files

README.md
src
index.js
App.js
package.json

No File Selected

Select a file from the sidebar to view its contents

Media Files with Image Preview

Showcase a media gallery project with image preview capabilities. Images are displayed inline when selected.

Live Preview

Media Gallery

Files

images
hero.jpg
thumbnail.png
videos
config.yaml

No File Selected

Select a file from the sidebar to view its contents

Full-Stack Project Structure

Complex project structure with frontend, backend, and configuration files. Demonstrates nested folders and different file types.

Live Preview

Full-Stack Application

Files

frontend
src
package.json
backend
docker-compose.yml

No File Selected

Select a file from the sidebar to view its contents

Interactive File Selection

Handle file selection events with callbacks to integrate with your application state and perform actions when files are selected.

Live Preview

File Explorer

Files

README.md
src
index.js
App.js
package.json

No File Selected

Select a file from the sidebar to view its contents

Interactive Features:

  • • Click files to select them (check console)
  • • Expand/collapse folders
  • • Use keyboard navigation (Tab, Enter, Space)

Loading States & Refresh

Demonstrate loading states and refresh functionality for dynamic file systems that load data asynchronously.

Live Preview

Dynamic File System

Files

README.md
src
index.js
App.js
package.json

No File Selected

Select a file from the sidebar to view its contents

Refreshed 0 times

Click the refresh button to simulate loading states