# react-file-navigator

> A React component to render a file explorer with features similar to VSCode.

Latest version **1.0.2-dev.1** (published 2024-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-file-navigator
pnpm add react-file-navigator
yarn add react-file-navigator
bun add react-file-navigator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2-dev.1 |
| Published | 2024-07-02 |
| First published | 2024-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 73 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Avinash Singh |
| Maintainers | singhscript |
| Keywords | react, file, navigator, explorer, tree, component, file explorer, VSCode, file management, folder structure, file tree, react component, web development, frontend, UI component, file system, tree view, directory, code editor, file navigation, open source, developer tools, JavaScript, ReactJS, UI library, interactive, user interface, customizable, responsive, lightweight |

## Links

- npm: https://www.npmjs.com/package/react-file-navigator
- Repository: https://github.com/singh-avinash-2000/react-file-navigator
- Homepage: https://github.com/singh-avinash-2000/react-file-navigator#readme
- Issues: https://github.com/singh-avinash-2000/react-file-navigator/issues
- npm.io page: https://npm.io/package/react-file-navigator

## Dependencies (1)

- [react-icons](https://npm.io/package/react-icons.md) ^5.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2-dev.1 (latest) — 2024-07-02
- 1.0.1 — 2024-02-22
- 1.0.1-dev.1 — 2024-02-22
- 1.0.0 — 2024-02-22

## README

# React File Navigator

## Introduction

React File Navigator allows you to integrate a file system navigator into your React applications. It provides a customizable and interactive hierarchical view of files and folders, complete with icons and configurable actions with drag and drop support.

For queries reachout : workwith.avinashsingh@gmail.com

## Features

- Render a hierarchical tree structure of files and folders.
- Customizable icons for file types and folder states.
- Configurable actions and callbacks for file and folder interaction.
- Easily integrate with modern React applications.
- Drag Drop to rearrange structure.

## Installation

To install the package, run the following command in your project directory:

```bash
npm install react-file-navigator
```

Or if you use Yarn:

```bash
yarn add react-file-navigator
```

![Demo Screenshot](images/explorer.png)

## Usage

### Import Components

Import the necessary components and hooks into your React component:

```jsx
import React, { useState } from 'react';
import { IoLogoReact, IoDocumentText } from 'react-icons/io5';
import { DownOutlined, RightOutlined } from '@ant-design/icons';
import { Explorer, IconMap, Tree, TreeNode } from 'react-file-navigator';
```

### Define the File System Structure

Define your initial file system structure using the Tree and TreeNode types:

```tsx
const initialTree: Tree = [
	{
		id: '1',
		type: 'Folder',
		name: 'Root',
		filePath: '/root',
		expanded: true,
		icon: 'folderExpanded',
		children: [
			{
				id: '2',
				type: 'File',
				filePath: '/root/main.tsx',
				extension: 'tsx',
				icon: 'tsx',
				name: 'main.tsx',
			},
		],
	},
];
```

### Set Up the Explorer Component

Use the Explorer component in your application with the defined tree structure:

```tsx
const App: React.FC = () => {
	const [tree, setTree] = useState < Tree > initialTree;

	const handleFileSelectionChange = (selectedNode: TreeNode | null) => {
		console.log('Selected file:', selectedNode);
	};

	const iconMap: IconMap = {
		default: <IoDocumentText />,
		folderCollapsed: <RightOutlined />,
		folderExpanded: <DownOutlined />,
		tsx: <IoLogoReact />,
	};

	return (
		<div style={{ height: '100vh' }}>
			<Explorer
				tree={tree}
				setTree={setTree}
				iconMap={iconMap}
				onFileSelectionChange={handleFileSelectionChange}
				config={{
					accentColor: 'lavender',
					fontColor: 'black',
					label: 'File System',
				}}
			/>
		</div>
	);
};

export default App;
```

## Type Definitions

### Tree

Array of TreeNode objects representing the file system.

### TreeNode

Union type of FileNode and FolderNode, representing individual nodes in the file system.

### FileNode

Represents a file in the tree:

```typescript
interface FileNode {
	id: string;
	type: 'File';
	filePath: string;
	extension: string;
	icon: string;
	name: string;
}
```

### FolderNode

Represents a folder in the tree:

```typescript
interface FolderNode {
	id: string;
	type: 'Folder';
	filePath: string;
	expanded: boolean;
	icon: 'folderCollapsed' | 'folderExpanded';
	name: string;
	children: TreeNode[];
}
```

### IconMap

Object defining the icons used for different file types and folder states:

```typescript
type IconMap = {
	default: React.ReactNode;
	folderCollapsed: React.ReactNode;
	folderExpanded: React.ReactNode;
	[extension: string]: React.ReactNode;
};
```

### ExplorerConfig

Configuration options for customizing the file navigator:

```typescript
interface ExplorerConfig {
	label?: string;
	rename?: 'DoubleClick' | 'Enter' | 'Both';
	delete?: 'Delete' | 'CMD + Backspace' | 'Both';
	fontColor?: string;
	accentColor?: string;
	headerFontSize?: string;
	headerIconSize?: string;
	fontSize?: string;
	iconSize?: string;
	disableActions?: boolean;
}
```

---
_Source: https://npm.io/package/react-file-navigator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
