Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 14 of the Intermediate WordPress Plugins: REST API & React Admin course
WordPressJune 25, 20263 min read

Working with @wordpress/components for WordPress Admin UIs

Master the @wordpress/components library to build consistent, accessible, and native-feeling WordPress admin interfaces for your plugin's React dashboard.

WordPressReact@wordpress/componentsUIGutenbergDevelopmentphpplugin-development

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.

Why use @wordpress/components?

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:

  • Consistency: Your plugin inherits WordPress's design language, ensuring it looks at home in the dashboard.
  • Accessibility: Components like Button and Panel are built with keyboard navigation and screen-reader support in mind.
  • Maintenance: When WordPress updates its admin styles, your plugin updates automatically.

Integrating Core Components

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.

Worked Example: Building a Dashboard Widget

Let’s refine our dashboard container. We’ll replace our basic markup with a Card containing a header and a Button.

JSX
import { 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;

Styling with CSS

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;
    }
}

Hands-on Exercise

  1. Refactor your container: Locate the main AdminApp component you created in our previous lesson.
  2. Add a Card: Wrap your primary content area in a <Card> component.
  3. Add an Action: Place a <Button> inside the <CardHeader> to act as a "Refresh" button.
  4. Style: Add a custom class to the parent container and add some padding in your style.scss file to ensure the UI isn't cramped against the admin sidebar.

Common Pitfalls

  • Missing Styles: If your components look unstyled (like plain HTML), ensure you have correctly imported the @wordpress/components/build-style/style.css in your SCSS or CSS entry point.
  • Over-nesting: Avoid wrapping every single element in a Card. Use them to group logical sections of data. Overuse leads to a cluttered, "boxy" UI.
  • Ignoring 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.

Recap

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.

Previous lessonScaffolding the React Admin DashboardNext lesson Creating a React Form for Submissions
Back to Blog

Similar Posts

WordPressJune 25, 20263 min read

Writing Selectors for Data Access: Memoization in WordPress

Master selectors in @wordpress/data to efficiently retrieve state. Learn to implement memoization for high-performance React admin interfaces in WordPress.

Read more
WordPressJune 25, 20263 min read

Registering a Custom Data Store in WordPress @wordpress/data

Learn to register a custom data store in WordPress using @wordpress/data. Master createReduxStore and store registration to centralize your plugin's state.

Part of the course

Intermediate WordPress Plugins: REST API & React Admin

intermediate · Lesson 14 of 45

  1. 1

    Setting up the WordPress Development Environment

    3 min
  2. 2

    Introduction to @wordpress/scripts

    3 min
  3. 3

    Configuring ESLint and Prettier

    3 min
Read more
WordPressJune 25, 20263 min read

Implementing CRUD in the Admin UI: WordPress REST API & React

Master CRUD operations in your WordPress admin dashboard. Learn to trigger API requests from React forms and lists to build truly interactive plugins.

Read more
4

Localizing Data for JavaScript

3 min
  • 5

    Anatomy of a REST API Endpoint

    3 min
  • 6

    Implementing REST API Permission Callbacks

    3 min
  • 7

    Handling GET Requests in REST API

    3 min
  • 8

    Validating and Sanitizing API Arguments

    4 min
  • 9

    Creating POST Endpoints for Data Submission

    3 min
  • 10

    Updating Existing API Resources

    3 min
  • 11

    Handling Asynchronous State in React

    3 min
  • 12

    Building the Knowledge Base Service Layer

    3 min
  • 13

    Scaffolding the React Admin Dashboard

    3 min
  • 14

    Working with @wordpress/components

    3 min
  • 15

    Creating a React Form for Submissions

    3 min
  • 16

    Implementing CRUD in the Admin UI

    3 min
  • 17

    Understanding WordPress Data Store Architecture

    4 min
  • 18

    Registering a Custom Data Store

    3 min
  • 19

    Writing Selectors for Data Access

    3 min
  • 20

    Defining Actions and Reducers

    Coming soon
  • 21

    Implementing Resolvers for Data Fetching

    Coming soon
  • 22

    Optimizing Performance with Selectors

    Coming soon
  • 23

    Handling Complex State Dependencies

    Coming soon
  • 24

    Implementing Nonce Verification

    Coming soon
  • 25

    Advanced Sanitization Techniques

    Coming soon
  • 26

    Input Validation and Error Handling

    Coming soon
  • 27

    Protecting Admin Screens

    Coming soon
  • 28

    Production Build Pipeline

    Coming soon
  • 29

    Debugging React in the WordPress Admin

    Coming soon
  • 30

    Building Search and Filter Functionality

    Coming soon
  • 31

    Internationalization in React

    Coming soon
  • 32

    Managing File Uploads via REST API

    Coming soon
  • 33

    Optimizing API Response Times

    Coming soon
  • 34

    Working with Date and Time in React

    Coming soon
  • 35

    Implementing Drag-and-Drop Sorting

    Coming soon
  • 36

    Creating Custom Hooks for API Logic

    Coming soon
  • 37

    Integrating with Gutenberg Blocks

    Coming soon
  • 38

    Handling Conflict Resolution

    Coming soon
  • 39

    Building a Modal Confirmation System

    Coming soon
  • 40

    Implementing Activity Logging

    Coming soon
  • 41

    Using Webpack Aliases

    Coming soon
  • 42

    Unit Testing API Endpoints

    Coming soon
  • 43

    Unit Testing React Components

    Coming soon
  • 44

    Handling Large Datasets with GraphQL

    Coming soon
  • 45

    Implementing Real-time Updates with Web

    Coming soon
  • View full course