SVAR React File Manager: A File Explorer for React Apps

Description:

SVAR React File Manager is a React file explorer component for browsing, organizing, and previewing files.

It provides List, tile, and split views that allow your users to navigate folders, while data-operation APIs connect the UI to your app’s backend.

Preview

SVAR React File Manager

Features

  • File creation, deletion, renaming, copying, cutting, and pasting.
  • Upload and download actions.
  • Folder tree, breadcrumbs, search, and sortable lists.
  • File previews with size, type, and date information.
  • Dynamic directory loading and storage usage information.
  • Light and dark themes, localization, and TypeScript declarations.

How To Use It

Install the package in a React app:

npm install @svar-ui/react-filemanager

Import Filemanager and the stylesheet, then apply the Willow light theme. Each record uses a path as its id, a file or folder type, a numeric size, and a JavaScript Date:

import { Filemanager, Willow } from "@svar-ui/react-filemanager";
import "@svar-ui/react-filemanager/all.css";
const files = [
  {
    id: "/Documents",
    type: "folder",
    size: 4096,
    date: new Date(2026, 10, 1),
  },
  {
    id: "/Documents/Project-notes.txt",
    type: "file",
    size: 2048,
    date: new Date(2026, 10, 4),
  },
  {
    id: "/Readme.txt",
    type: "file",
    size: 512,
    date: new Date(2026, 10, 2),
  },
];
export default function FileBrowser() {
  return (
    <Willow>
      <Filemanager data={files} />
    </Willow>
  );
}

Connect File Operations to a Backend

Pass file records through data. Connect upload, download, and modification actions to your storage service for persistence.

For a custom service, subscribe to data-operation events and send changes to the server. The onRenameFile handler receives the item’s id and new name, for example.

The optional RestDataProvider helper connects a REST backend to the file manager’s event bus. Install the package before importing it:

npm install @svar-ui/filemanager-data-provider

Point the provider at a backend that implements SVAR’s REST endpoints. This example loads the initial listing and storage information, then connects later operations through init:

import { useEffect, useMemo, useState } from "react";
import { RestDataProvider } from "@svar-ui/filemanager-data-provider";
import { Filemanager, Willow } from "@svar-ui/react-filemanager";
import "@svar-ui/react-filemanager/all.css";
export function ConnectedFileBrowser() {
  const provider = useMemo(() => new RestDataProvider("/api/files"), []);
  const [listing, setListing] = useState(null);
  const [error, setError] = useState("");
  useEffect(() => {
    Promise.all([provider.loadFiles(), provider.loadInfo()])
      .then(([files, info]) => setListing({ files, drive: info.stats }))
      .catch(() => setError("Unable to load files."));
  }, [provider]);
  if (error) return <p>{error}</p>;
  if (!listing) return <p>Loading files...</p>;
  return (
    <Willow>
      <Filemanager
        data={listing.files}
        drive={listing.drive}
        init={(api) => api.setNext(provider)}
      />
    </Willow>
  );
}

Server Operations

The provider sends requests for create, rename, delete, copy, move, and upload actions. Use dynamic folder loading to fetch directory contents as users open them.

Customization Hooks

PropPurpose
initReceives the file manager API
readonlyEnables read-only operation
menuOptions(mode, item)Returns menu items or false to disable the menu
extraInfo(file)Returns extra information, a promise for it, or null
icons"simple" or (file, size) => string | false; size is "big" or "small"
previews(file, width, height)Returns a preview URL or null

Style the File Browser

Replace Willow with WillowDark for the dark theme. Wrap Willow in <div className="file-browser">, then override its theme variables to change the background, primary color, or toolbar height:

.file-browser .wx-willow-theme {
  --wx-color-primary: #2563eb;
  --wx-fm-background: #f3f6fc;
  --wx-fm-toolbar-height: 60px;
}

File Interaction

You can perform file operations through the context menu, toolbar, and keyboard shortcuts.

Add Comment