An interactive demo showing how to model a file system–like folder & file tree in React using a simple tree data structure. Built with React + TypeScript + Vite. You can add folders/files, rename nodes inline, nest children, expand/collapse folders, and inspect the live JSON tree.
Key goals:
- Demonstrate a minimal tree model (folder/file nodes).
- Provide a UI that lets you create, rename, nest, and delete nodes.
- Show the underlying data in a Tree Inspector for learning/debugging.
Run the app locally and open http://localhost:5173 in your browser.
Live demo (deployed to GitHub Pages):
(Note: the site will be live after you run npm run deploy or when your CI workflow publishes the gh-pages branch.)
- Add folders/files at the root or inside any folder.
- Inline rename: click a node label to edit; press Enter or blur to save.
- Expand/Collapse folders via arrow or double-click.
- Delete any node (folder or file).
- Per-node controls (add folder/file, delete) and root controls for quick creation.
- Stats (folder/file counts) and an empty state when no nodes exist.
- Live JSON view of the tree (great for learning/debugging).
- React 19 (functional components + hooks)
- TypeScript
- Vite (dev server + build)
- Tailwind CSS
- ESLint for linting
- Node.js 18+ recommended
- A package manager (pnpm, npm or yarn). The project uses standard npm scripts.
Open a terminal in the project root and run:
npm installStart the dev server (Vite):
npm run devOpen http://localhost:5173
To produce a production build and preview it locally:
npm run build
npm run previewRun ESLint across the project:
npm run lintFeature-based (vertical slices) with a single navigation slice.
Important files and folders:
src/main.tsx- App bootstrap and React entrypointsrc/app/App.tsx- Top-level app layoutsrc/app/features/fs- Core feature: hooks, UI, and small utilitiesstate/useTree.ts- Hook managing the tree state & actions (add, remove, rename, toggle).state/seed.ts- Initial seed data for the demo.ui/FolderTree.tsx- Top-level panel, stats, and root controls.ui/TreeNode.tsx- Recursive node renderer (expand/collapse, rename, children).ui/NodeControls.tsx- Small control cluster (add folder/file, delete).ui/TreeInspector.tsx- JSON representation of the current tree.
Other repo files:
vite.config.ts- Vite configurationtsconfig*.json- TypeScript configurationeslint.config.js- ESLint configuration
-
The tree is an array of nodes; each node is either a folder (with
children[]andisOpen) or a file. -
The custom hook
useTree(seed)exposes:treeandstats(folders/files count),- actions:
addFile(parentId?),addFolder(parentId?),remove(id),rename(id, name),toggleOpen(id).
-
UI wiring:
- FolderTree renders global controls and the root list.
TreeNoderenders each node and recurses for folder children; it handles inline rename and expand/collapse.NodeControlsprovides per-node create/delete actionsTreeInspectorprintsJSON.stringify(tree, null, 2)
Contributions are welcome. If you'd like to contribute:
- Fork the repository.
- Create a branch for your feature/fix:
git checkout -b feat/change-name - Run the app and add tests/docs where helpful.
npm run lintand open a PR.
Please follow existing code style, TypeScript typing, and lint rules. Run npm run lint before opening a PR.
This project is provided under the MIT License. See the LICENSE file for details.
Copyright © 2025, Kaissar Mouelhi