File Explorer

MediumRecursionTreesStateReact35 mins

by Pratik Rai

Read the full write-up

Build a file explorer that starts empty and lets someone build a tree by hand.

One button to begin with. From there, every folder can be expanded, collapsed, and added to — and folders you create can themselves be added to, arbitrarily deep.

Requirements

  1. The initial state is a single Create src button. Clicking it creates a root folder named src.

  2. Folders expand and collapse. Files do not.

  3. Every folder has a + Add control that opens a small form asking for a type (file or folder) and a name.

  4. The name field starts at a sensible default: NewFile.txt for a file, NewFolder for a folder.

  5. Confirming adds the item inside that folder. Folders created this way have their own + Add, so nesting can go arbitrarily deep.

  6. Clicking a file selects it — visual feedback is enough.

Notes

  • The styling is already written; .name-selected handles the selection highlight.

  • makeNode is given to you, so ids are handled.

Hints

Loading editor…