import React, { useState } from 'react'; import GridLayout from 'react-grid-layout'; import 'react-grid-layout/css/styles.css'; import 'react-resizable/css/styles.css'; /** * Customizable Dashboard with Drag-and-Drop * * Features: * - Drag to reorder widgets * - Resize widgets * - Save/restore layout * - Add/remove widgets * - Responsive breakpoints */ const AVAILABLE_WIDGETS = [ { id: 'revenue', title: 'Revenue', type: 'kpi' }, { id: 'users', title: 'Active Users', type: 'kpi' }, { id: 'chart', title: 'Trend Chart', type: 'chart' }, { id: 'table', title: 'Recent Orders', type: 'table' }, ]; export function CustomizableDashboard() { const [layout, setLayout] = useState([ { i: 'revenue', x: 0, y: 0, w: 3, h: 1 }, { i: 'users', x: 3, y: 0, w: 3, h: 1 }, { i: 'chart', x: 0, y: 1, w: 6, h: 2 }, { i: 'table', x: 6, y: 1, w: 6, h: 2 }, ]); const [widgets, setWidgets] = useState(['revenue', 'users', 'chart', 'table']); const saveLayout = () => { localStorage.setItem('dashboardLayout', JSON.stringify(layout)); localStorage.setItem('dashboardWidgets', JSON.stringify(widgets)); alert('Layout saved!'); }; const resetLayout = () => { localStorage.removeItem('dashboardLayout'); localStorage.removeItem('dashboardWidgets'); window.location.reload(); }; const onLayoutChange = (newLayout) => { setLayout(newLayout); }; const renderWidget = (widgetId: string) => { const widget = AVAILABLE_WIDGETS.find((w) => w.id === widgetId); if (!widget) return null; return (
Tip: Drag widgets to reorder, resize by dragging corners. Changes are saved automatically.