Master the @wordpress/components library to build consistent, accessible, and native-feeling WordPress admin interfaces for your plugin's React dashboard.
Previously in this course, we covered scaffolding the React admin dashboard to establish a mounting point for our application. While a blank <div> is a functional start, it lacks the professional polish users expect from a modern plugin. In this lesson, we will replace raw HTML elements with the @wordpress/components library to ensure our plugin feels like a native part of the WordPress ecosystem.
When building admin UIs, the temptation to write custom CSS for buttons, inputs, and layout containers is high. However, doing so creates a "disconnected" experience. The @wordpress/components package provides a suite of pre-built, accessible, and theme-aware React components.
By using these, you get:
Button and Panel are built with keyboard navigation and screen-reader support in mind.To get started, ensure you have the package installed in your project:
npm install @wordpress/components --save
We will focus on three fundamental building blocks: the Card for grouping information, the Panel for organizing settings, and the Button for user actions.
Let’s refine our dashboard container. We’ll replace our basic markup with a Card containing a header and a Button.
JSXimport { Button, Card, CardBody, CardHeader, Panel, PanelBody } from CE9178">'@wordpress/components'; import { useState } from CE9178">'@wordpress/element'; const DashboardWidget = () => { const [isPanelOpen, setIsPanelOpen] = useState(true); return ( <div className="kb-dashboard-container"> <Card> <CardHeader>Knowledge Base Overview</CardHeader> <CardBody> <p>Manage your plugin settings and content here.</p> <Button variant="primary" onClick={() => alert(CE9178">'Action triggered!')} > Sync Data </Button> </CardBody> </Card> <Panel header="Advanced Configuration"> <PanelBody title="Settings" initialOpen={isPanelOpen}> <p>Toggle your plugin features here.</p> </PanelBody> </Panel> </div> ); }; export default DashboardWidget;
While components handle the heavy lifting, you still need to scope your styles. Use the wp-components library in conjunction with your own stylesheet. Because the components are wrapped in standard HTML tags, you can target them using standard CSS classes or BEM notation.
In your index.scss file, ensure you import the WordPress component styles to maintain consistency:
SCSS// Import the base WordPress component styles @import '@wordpress/components/build-style/style.css'; .kb-dashboard-container { max-width: 800px; margin-top: 20px; .components-card { margin-bottom: 20px; } }
AdminApp component you created in our previous lesson.<Card> component.<Button> inside the <CardHeader> to act as a "Refresh" button.style.scss file to ensure the UI isn't cramped against the admin sidebar.@wordpress/components/build-style/style.css in your SCSS or CSS entry point.Card. Use them to group logical sections of data. Overuse leads to a cluttered, "boxy" UI.variant props: The Button component accepts a variant prop (e.g., primary, secondary, tertiary). Using primary for every single action confuses the user. Reserve primary for the main action of a form or section.We’ve moved from raw HTML to professional-grade UI components. By using Card, Panel, and Button from @wordpress/components, your plugin's admin dashboard now aligns with the WordPress design system, providing a superior user experience. These components handle the complexities of accessibility and cross-browser styling, allowing you to focus on the logic of your Knowledge Base plugin.
Up next: We will move beyond static UI and build a React form for submissions, managing state to handle user input effectively.
Master selectors in @wordpress/data to efficiently retrieve state. Learn to implement memoization for high-performance React admin interfaces in WordPress.
Read moreLearn to register a custom data store in WordPress using @wordpress/data. Master createReduxStore and store registration to centralize your plugin's state.
Working with @wordpress/components
Defining Actions and Reducers
Implementing Resolvers for Data Fetching
Optimizing Performance with Selectors
Handling Complex State Dependencies
Implementing Nonce Verification
Advanced Sanitization Techniques
Input Validation and Error Handling
Protecting Admin Screens
Production Build Pipeline
Debugging React in the WordPress Admin
Building Search and Filter Functionality
Internationalization in React
Managing File Uploads via REST API
Optimizing API Response Times
Working with Date and Time in React
Implementing Drag-and-Drop Sorting
Creating Custom Hooks for API Logic
Integrating with Gutenberg Blocks
Handling Conflict Resolution
Building a Modal Confirmation System
Implementing Activity Logging
Using Webpack Aliases
Unit Testing API Endpoints
Unit Testing React Components
Handling Large Datasets with GraphQL
Implementing Real-time Updates with Web