Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cubone/react-file-manager

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cubone/react-file-manager

React File Manager is an open-source, user-friendly component designed to easily manage files and folders within applications. With smooth drag-and-drop functionality, responsive design, and efficient navigation, it simplifies file handling in any React p

  • 1.11.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

React File Manager

NPM Downloads npm bundle size NPM Version

An open-source React.js package for easy integration of a file manager into applications. It provides a user-friendly interface for managing files and folders, including viewing, uploading, and deleting, with full UI and backend integration.

✨ Features

  • File & Folder Management: View, upload, download, delete, copy, move, create, and rename files or folders seamlessly.
  • Grid & List View: Switch between grid and list views to browse files in your preferred layout.
  • Navigation: Use the breadcrumb trail and sidebar navigation pane for quick directory traversal.
  • Toolbar & Context Menu: Access all common actions (upload, download, delete, copy, move, rename, etc.) via the toolbar or right-click for the same options in the context menu.
  • Multi-Selection: Select multiple files and folders at once to perform bulk actions like delete, copy, move, or download.
  • Keyboard Shortcuts: Quickly perform file operations like copy, paste, delete, and more using intuitive keyboard shortcuts.
  • Drag-and-Drop: Move selected files and folders by dragging them to the desired directory, making file organization effortless.

React File Manager

🚀 Installation

To install React File Manager, use the following command:

npm i @cubone/react-file-manager

💻 Usage

Here’s a basic example of how to use the File Manager Component in your React application:

import { useState } from "react";
import { FileManager } from "@cubone/react-file-manager";
import "@cubone/react-file-manager/dist/style.css";

function App() {
  const [files, setFiles] = useState([
    {
      name: "Documents",
      isDirectory: true, // Folder
      path: "/Documents", // Located in Root directory
      updatedAt: "2024-09-09T10:30:00Z", // Last updated time
    },
    {
      name: "Pictures",
      isDirectory: true,
      path: "/Pictures", // Located in Root directory as well
      updatedAt: "2024-09-09T11:00:00Z",
    },
    {
      name: "Pic.png",
      isDirectory: false, // File
      path: "/Pictures/Pic.png", // Located inside the "Pictures" folder
      updatedAt: "2024-09-08T16:45:00Z",
      size: 2048, // File size in bytes (example: 2 KB)
    },
  ]);

  return (
    <>
      <FileManager files={files} />
    </>
  );
}

export default App;

📂 File Structure

The files prop accepts an array of objects, where each object represents a file or folder. You can customize the structure to meet your application needs. Each file or folder object follows the structure detailed below:

type File = {
  name: string;
  isDirectory: boolean;
  path: string;
  updatedAt?: string; // Optional: Last update timestamp in ISO 8601 format
  size?: number; // Optional: File size in bytes (only applicable for files)
};

⚙️ Props

NameTypeDescription
acceptedFileTypesstring(Optional) A comma-separated list of allowed file extensions for uploading specific file types (e.g., .txt, .png, .pdf). If omitted, all file types are accepted.
enableFilePreviewbooleanA boolean flag indicating whether to use the default file previewer in the file manager default: true.
filePreviewPathstringThe base URL for file previews e.g.https://example.com, file path will be appended automatically to it i.e. https://example.com/yourFilePath.
fileUploadConfig{ url: string; headers?: { [key: string]: string } }Configuration object for file uploads. It includes the upload URL (url) and an optional headers object for setting custom HTTP headers in the upload request. The headers object can accept any standard or custom headers required by the server. Example: { url: "https://example.com/fileupload", headers: { Authorization: "Bearer" + TOKEN, "X-Custom-Header": "value" } }
filesArray<File>An array of file and folder objects representing the current directory structure. Each object includes name, isDirectory, and path properties.
heightstring | numberThe height of the component default: 600px. Can be a string (e.g., '100%', '10rem') or a number (in pixels).
isLoadingbooleanA boolean state indicating whether the application is currently performing an operation, such as creating, renaming, or deleting a file/folder. Displays a loading state if set true.
layout"list" | "grid"Specifies the default layout style for the file manager. Can be either "list" or "grid". Default value is "grid".
maxFileSizenumberFor limiting the maximum upload file size in bytes.
onCreateFolder(name: string, parentFolder: File) => voidA callback function triggered when a new folder is created. Use this function to update the files state to include the new folder under the specified parent folder using create folder API call to your server.
onDelete(files: Array<File>) => voidA callback function is triggered when one or more files or folders are deleted.
onDownload(files: Array<File>) => voidA callback function triggered when one or more files or folders are downloaded.
onError(error: { type: string, message: string }, file: File) => voidA callback function triggered whenever there is an error in the file manager. Where error is an object containing type ("upload", etc.) and a descriptive error message.
onFileOpen(file: File) => voidA callback function triggered when a file or folder is opened.
onFileUploaded(response: { [key: string]: any }) => voidA callback function triggered after a file is successfully uploaded. Provides JSON response holding uploaded file details, use it to extract the uploaded file details and add it to the files state e.g. setFiles((prev) => [...prev, JSON.parse(response)]);
onFileUploading(file: File, parentFolder: File) => { [key: string]: any }A callback function triggered during the file upload process. You can also return an object with key-value pairs that will be appended to the FormData along with the file being uploaded. The object can contain any number of valid properties.
onLayoutChange(layout: "list" | "grid") => voidA callback function triggered when the layout of the file manager is changed.
onPaste(files: Array<File>, destinationFolder: File, operationType: "copy" | "move") => voidA callback function triggered when when one or more files or folders are pasted into a new location. Depending on operationType, use this to either copy or move the sourceItem to the destinationFolder, updating the files state accordingly.
onRefresh() => voidA callback function triggered when the file manager is refreshed. Use this to refresh the files state to reflect any changes or updates.
onRename(file: File, newName: string) => voidA callback function triggered when a file or folder is renamed.
widthstring | numberThe width of the component default: 100%. Can be a string (e.g., '100%', '10rem') or a number (in pixels).

⌨️ Keyboard Shortcuts

ActionShortcut
New FolderAlt + Shift + N
Upload FilesCTRL + U
CutCTRL + X
CopyCTRL + C
PasteCTRL + V
RenameF2
DownloadCTRL + D
DeleteDEL
Select All FilesCTRL + A
Select Multiple FilesCTRL + Click
Select Range of FilesShift + Click
Switch to List LayoutCTRL + Shift + 1
Switch to Grid LayoutCTRL + Shift + 2
Jump to First File in the ListHome
Jump to Last File in the ListEnd
Refresh File ListF5
Clear SelectionEsc

🤝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/branch-name).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add some feature').
  5. Push to the branch (git push origin feature/branch-name).
  6. Open a Pull Request.

Get started by running following commands:

git clone https://github.com/Saifullah-dev/react-file-manager.git
cd react-file-manager

Frontend

cd frontend
npm i
npm run dev

The application should now be running on http://localhost:5173.

Backend

cd backend
npm i
npm run devStart

The server should now be running on http://localhost:3000, have fun!

©️ License

React File Manager is MIT Licensed.

Keywords

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc