A generic, reusable PatternFly component library providing a customizable widget-based dashboard with drag-and-drop functionality. This library was created by lifting and adapting code from the RedHatInsights/widget-layout repository, removing console-specific dependencies to make it suitable for any PatternFly application.
- Drag-and-Drop Grid Layout: Powered by
react-grid-layoutwith responsive breakpoints - Widget Drawer: Easy widget selection and management
- Lock/Unlock Widgets: Prevent accidental changes to widget positions and sizes
- Resize Widgets: Adjust widget dimensions with corner handles
- Responsive Design: Automatic layout adjustments for xl, lg, md, and sm breakpoints
- Customizable: Fully configurable widgets with custom icons, titles, and content
- TypeScript Support: Full type definitions included
- No External Dependencies: Self-contained state management (no Jotai, Redux, or other state libraries required)
yarn add @patternfly/widgetized-dashboardOr with npm:
npm install @patternfly/widgetized-dashboardMake sure you have the required peer dependencies installed:
yarn add react react-dom react-router-dom @patternfly/react-core @patternfly/react-iconsimport React from 'react';
import { WidgetLayout, WidgetMapping, ExtendedTemplateConfig } from '@patternfly/widgetized-dashboard';
import { CubeIcon } from '@patternfly/react-icons';
// Define your widgets
const widgetMapping: WidgetMapping = {
'example-widget': {
defaults: { w: 2, h: 3, maxH: 6, minH: 2 },
config: {
title: 'Example Widget',
icon: <CubeIcon />
},
renderWidget: (id) => <div>Widget content goes here</div>
}
};
// Define initial layout (or load from API/localStorage)
const initialTemplate: ExtendedTemplateConfig = {
xl: [
{ i: 'example-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'example-widget', title: 'Example Widget' }
],
lg: [
{ i: 'example-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'example-widget', title: 'Example Widget' }
],
md: [
{ i: 'example-widget#1', x: 0, y: 0, w: 2, h: 3, widgetType: 'example-widget', title: 'Example Widget' }
],
sm: [
{ i: 'example-widget#1', x: 0, y: 0, w: 1, h: 3, widgetType: 'example-widget', title: 'Example Widget' }
]
};
function App() {
return (
<WidgetLayout
widgetMapping={widgetMapping}
initialTemplate={initialTemplate}
onTemplateChange={(template) => {
// Save template to API or localStorage
console.log('Template changed:', template);
}}
/>
);
}The main component that provides the complete dashboard experience with grid layout and widget drawer.
The core layout engine with drag-and-drop functionality (can be used standalone).
The widget selection drawer (can be used standalone with GridLayout).
Individual widget tile wrapper with actions menu (used internally by GridLayout).
This library is based on RedHatInsights/widget-layout but has been adapted to be a generic, reusable PatternFly component:
- ❌ Scalprum federated module loading
- ❌ Chrome Services API calls for template persistence
- ❌ Console-specific authentication (useCurrentUser)
- ❌ Console-specific analytics (useChrome)
- ❌ Jotai state management atoms
- ❌ Console-specific icons and branding
- ✅ Generic widget rendering via
renderWidgetprop - ✅ Prop-based template management (bring your own state management)
- ✅ Optional analytics callback
- ✅ Standalone component usage (no external state required)
- ✅ Full TypeScript support
- ✅ Simplified API without console dependencies
Modern browsers (Chrome, Firefox, Safari, Edge) with ES6 support.
MIT
Please reference PatternFly's AI-assisted development guidelines if you'd like to contribute code generated using AI.
This library is based on the RedHatInsights/widget-layout repository, adapted to be a generic PatternFly component.