Frontend School

Build a Resizable Multi-Panel Layout Component

Machine Coding
medium

Build a Resizable Multi-Panel Layout Component

Medium
React
JavaScript
CSS
UI
Machine Coding
Resizable Panels

Overview

In modern e-commerce platforms like Meesho, complex dashboards and developer consoles are crucial for monitoring various business metrics, managing orders, or debugging applications. These interfaces often require flexible layouts to display multiple types of content side-by-side or top-bottom, allowing users to customize their workspace. This problem focuses on building a core UI primitive: a resizable panel component.

What you need to do / Task

Your task is to create a ResizablePanels React component that can display two child components (panels) separated by a draggable divider. Users should be able to resize these panels by dragging the divider.

  1. Component Structure: Create a functional React component named ResizablePanels.
  2. Panel Rendering: The ResizablePanels component should accept two ReactNode children as props, representing the content for the left/top and right/bottom panels.
  3. Divider Implementation: Render a visual divider (separator) between the two panels. This divider should be draggable.
  4. Resizing Logic: Implement the necessary event handlers to enable resizing. When the user clicks and drags the divider, the adjacent panels should resize dynamically in real-time.
  5. Minimum Size Constraint: Ensure that each panel has a configurable minimum width/height (e.g., 100px) and cannot be resized below this minimum.

UI/UX expectations

  • Layout: Initially, the ResizablePanels should display two panels horizontally (side-by-side), with the divider in the middle.
  • Divider Appearance: The divider should be visually distinct (e.g., a thin grey bar) and change the cursor to ew-resize when hovered over.
  • Resizing Experience: Resizing should feel smooth and responsive. There should be no noticeable lag or flickering as the user drags the divider.
  • Panel Content: The child components inside the panels should adapt to the new dimensions without overflowing or causing layout issues (assume children handle their own responsiveness).

Acceptance criteria

  • The ResizablePanels component renders two distinct child panels and a visible divider between them.
  • Hovering over the divider changes the cursor to ew-resize.
  • Clicking and dragging the divider allows for real-time horizontal resizing of the adjacent panels.
  • Panels cannot be resized below a defined minimum width (e.g., 100px).
  • The layout remains stable and visually correct during and after resizing.
  • The component is reusable and well-structured.

Constraints

Constraints & assumptions

  • You must use React functional components and hooks.
  • No external libraries specifically for resizing (e.g., react-resizable-panels, react-split) are allowed. Implement the core resizing logic yourself using native browser events.
  • Assume the ResizablePanels component will be rendered within a parent container that provides sufficient space (e.g., width: 100%; height: 400px;).
  • Focus on horizontal resizing for two panels only.
  • The minimum panel width can be a hardcoded constant (e.g., 100px).

Out of scope

  • Vertical resizing.
  • More than two panels or nested resizable panels.
  • Persistence of panel sizes across sessions (e.g., using localStorage).
  • Accessibility features beyond basic cursor changes.
  • Complex animations during resizing.

What interviewers evaluate

  • Core Logic Implementation: Correctness and efficiency of the resizing mechanism using mouse events.
  • React State Management: Appropriate use of useState, useRef, and useEffect for managing component state and side effects.
  • Component Design: Clean, modular, and reusable component structure following React best practices.
  • UI Responsiveness & Performance: The smoothness and lack of visual glitches during the resizing interaction.

Loading editor...