Overview
Modern dashboards often feature customizable layouts, allowing users to arrange information widgets according to their preferences. This problem focuses on building the core interaction for such a feature: enabling users to reorder widgets within a grid using drag-and-drop. This functionality is critical for user personalization and an intuitive user experience.
What you need to do / Task
Your task is to implement a React component that displays a set of predefined widgets in a grid layout. The primary requirement is to enable users to reorder these widgets by dragging and dropping them into new positions within the grid.
- Render Widgets: Display the initial
WIDGET_DATA in a grid layout.
- Implement Drag-and-Drop: Allow users to click, drag, and drop any widget to a new position within the grid.
- Visual Feedback: Provide clear visual cues during the drag operation, indicating the item being dragged and potential drop targets.
- Reorder Data: Upon a successful drop, update the internal state to reflect the new order of widgets.
- Maintain Grid Layout: Ensure the grid layout adapts correctly as items are reordered.
UI/UX expectations
- Grid Layout: Widgets should be arranged in a responsive grid, ideally using CSS Grid.
- Draggable Indicators: Each widget should visually indicate that it is draggable (e.g.,
cursor: grab).
- Drag Feedback: When a widget is being dragged, it should have a distinct visual appearance (e.g., reduced opacity, a shadow, or a 'ghost' image). A placeholder or visual shift should indicate where the dragged item will be dropped.
- Smooth Transitions (Optional but appreciated): If time permits, subtle animations for item reordering can enhance the user experience.
Acceptance criteria
- The initial set of widgets is rendered correctly in a grid structure.
- Users can initiate a drag operation on any widget.
- While dragging, the UI provides visual feedback for the item being moved.
- When a dragged widget is hovered over another widget's potential drop zone, the UI indicates a possible reordering (e.g., a visual shift in the grid).
- Upon dropping a widget, the grid visually reorders itself to reflect the new position of the dropped item.
- The underlying
widgets state array is updated to match the new visual order.
- There are no broken UI states (e.g., flickering, incorrect positioning) during or after the drag-and-drop operation.