Overview
Bigbasket organizes its vast product catalog into a deep hierarchy of categories and subcategories. To enhance user experience and facilitate efficient navigation, we need an intuitive way for users to explore this structure. This problem challenges you to build an interactive Tree View component that allows users to browse Bigbasket's categories by expanding and collapsing nodes, providing a clear visual representation of the hierarchy.
What you need to do / Task
Your primary task is to develop a React component that renders a hierarchical list of categories as an interactive Tree View.
- Render Hierarchy: Display the provided mock category data, respecting its nested structure.
- Expand/Collapse Functionality: Implement the ability to expand and collapse parent categories. Clicking on a parent category's toggle or label should reveal/hide its direct children.
- Visual Indentation: Ensure that child categories are visually indented relative to their parent categories, clearly indicating their depth in the hierarchy.
- Sub-item Count: Next to each category name, display the total count of direct sub-items (either subcategories or individual products if the category is a leaf node). The mock data will provide
productCount for leaf nodes and children array for parent nodes.
- Leaf Node Interaction: For categories that are leaf nodes (i.e., have no
children), clicking their label should trigger a console.log displaying the category's name and ID.
UI/UX expectations
- Toggle Indicator: Use a clear visual indicator (e.g., an arrow icon
▶ for collapsed, ▼ for expanded) next to expandable nodes. Leaf nodes should not have this indicator.
- Indentation: Each level of depth should have a consistent, discernible indentation (e.g., using
padding-left or margin-left).
- Clickable Areas: The category name and its associated toggle (if any) should be clickable.
- Basic Styling: Ensure readability with basic styling for text and spacing. No need for elaborate designs.
Acceptance criteria
- The entire category tree, based on the mock data, renders correctly on initial load.
- Clicking a parent category's toggle or label correctly expands its children if collapsed, and collapses them if expanded.
- The expand/collapse indicator icon visually updates its state (e.g., rotates or changes shape) upon interaction.
- Leaf nodes (categories without children) are rendered without an expand/collapse toggle.
- Each category is indented according to its depth in the hierarchy.
- The count of direct sub-items (children categories or products) is accurately displayed next to each category name.
- Clicking on a leaf node's name logs its
name and id to the console.