Overview
In modern applications, navigating complex hierarchies of data is a common requirement. Imagine you're building a file explorer, a resource manager, or an organizational chart. A robust and performant Tree View component is crucial for users to efficiently browse, understand, and interact with structured information. This problem challenges you to build a dynamic Tree View that can handle large datasets gracefully.
What you need to do / Task
Your primary task is to implement a reusable React Tree View component in TypeScript that displays hierarchical data. The component should be capable of:
- Recursive Rendering: Display a tree structure based on provided hierarchical data.
- Expand/Collapse Functionality: Allow users to expand and collapse folder nodes to reveal or hide their children.
- Single Node Selection: Enable users to select a single node at a time. The selected node should be visually highlighted.
- Lazy Loading of Children ("Load More"): For folders that contain many children, initially display only a subset. A "Load More" button should appear, allowing the user to incrementally load additional chunks of children for that specific folder. This should simulate an asynchronous operation.
UI/UX expectations
- Hierarchy: Use indentation to clearly represent the parent-child relationships between nodes.
- Expand/Collapse Indicators: Display a clear visual indicator (e.g.,
> for collapsed, v for expanded) next to folder nodes.
- Selection Highlight: The currently selected node should have a distinct background color or border.
- Node Types: Differentiate visually between 'file' and 'folder' nodes (e.g., using icons or different text styles).
- "Load More" Button: The "Load More" button should be clearly visible when applicable, positioned appropriately within the folder node it pertains to. It should disable itself briefly during the simulated loading process.
Acceptance criteria
- The tree renders correctly with initial data and proper indentation.
- Clicking a folder's expand/collapse indicator toggles its children's visibility.
- Clicking any node selects it, and only one node is selected at a time.
- Selected node is visually highlighted.
- Folder nodes with more children than initially displayed show a "Load More" button.
- Clicking "Load More" appends the next chunk of children to that specific folder.
- The "Load More" button disappears when all children for that folder have been loaded.
- The component handles nested "Load More" scenarios (i.e., a loaded child folder might itself have a "Load More" button).
- The solution uses React and TypeScript effectively, demonstrating good component design and state management.