Overview
Widgets enable you to:- Add custom content to existing pages
- Display additional information alongside core features
- Integrate third-party services into the admin
- Create reusable UI components across multiple pages
Creating a Widget
Basic Widget
Create a widget by defining a React component and specifying where it should appear: The widget will automatically appear on all order detail pages, after the main content.Widget Configuration
ThedefineWidgetConfig function accepts:
Multiple Zones
Inject a widget into multiple locations:Injection Zones
Injection zones are specific locations in the admin where widgets can be inserted. They follow the pattern:Available Zones
The full list of injection zones is defined inpackages/admin/admin-shared/src/extensions/widgets/constants.ts:210:
Order Zones
Product Zones
Customer Zones
Other Entity Zones
Data Access
Route Parameters
Access route parameters to fetch relevant data:Medusa SDK
Fetch data from Medusa using the Admin SDK:Styling Widgets
Using Design System
Leverage Medusa UI components for consistent styling:Responsive Layout
Advanced Patterns
Conditional Rendering
Show widgets based on conditions:Interactive Widgets
Create widgets with state and interactions:Chart Widget
Integrate charts and visualizations:Complete Example
Here’s a complete widget that displays product inventory across locations:Best Practices
Keep Widgets Focused
Keep Widgets Focused
Each widget should have a single, clear purpose. Create multiple small widgets rather than one large complex widget.
Handle Loading States
Handle Loading States
Always show loading indicators while fetching data to prevent layout shifts.
Use Container Components
Use Container Components
Wrap widgets in
<Container> from @medusajs/ui for consistent spacing and styling.Optimize Performance
Optimize Performance
Use React Query for efficient data fetching and caching. Avoid expensive computations in render.
Consider Widget Placement
Consider Widget Placement
Choose injection zones carefully. Use
.side zones for supplementary info and .before/.after for primary content.Next Steps
- Learn about custom routes
- Explore dashboard customization
- Review the JavaScript SDK for API integration