# Customizing Strapi Admin Panel: Tailoring the UI/UX for Your Content Team
With the help of the open-source headless CMS Strapi, developers may create backends for content management that are incredibly adaptable. Developers can alter the admin panel in Strapi 5 to enhance the user experience (UX) and better fit it for content teams. Admin panel customization facilitates more intuitive navigation and helps content managers reduce inefficiencies in their workflows.
This guide covers two main aspects of Strapi 5’s admin panel customization:
1. Adding additional fields and developing custom components to expand the Admin Panel.
2. Switching out the WYSIWYG Editor for a solution with more features.
For developers who want to get the most out of Strapi 5, we will go through examples of both and provide thorough explanations of the code.
1. Extending the Admin Panel by creating custom components and adding new fields.
2. Replacing the WYSIWYG Editor with a more feature-rich solution.
We will walk through examples of both, with detailed explanations of the code to make this a comprehensive guide for developers looking to get the most out of Strapi 5.
## Why Customize the Strapi Admin Panel?
Although Strapi's admin panel is meant to be adaptable, it might not meet all of a content team's needs right out of the box. There are a few reasons why you would wish to alter it:
* Increased Efficiency: By including unique fields and features that are in line with the particular requirements of your team, you may bring extra efficiency to workflows.
* Tailored User Experience: Workflows and expectations vary throughout content teams. The admin panel can be made more user-friendly and straightforward for the specific team members dealing with it by customizing the UI/UX.
* Advanced Functionality: There may be situations in which the functions that come as standard are insufficient. For instance, you might require more sophisticated text editors or special content fields that aren't included in the installation by default.
Content teams can operate more efficiently by giving themselves complete control over the interface and its behavior by customizing the admin panel.
## Extending the Admin Panel in Strapi 5
Strapi 5's admin panel is a React-based single-page application (SPA) that developers can customize with React components. Now that Strapi 5 supports TypeScript as the default language, developers can create more sophisticated and type-safe customizations.
In Strapi 5, there are two main methods to expand the admin panel:
1. Developing reusable plugins as a plugin developer that alter the admin panel for various Strapi projects.
2. As a developer of Strapi applications: Tailoring a particular Strapi admin panel instance for a given project.
Let's examine these ideas using real-world instances.
### Example 1: Adding Custom Fields to the Admin Panel
Adding custom fields to the admin panel is one of the most popular extensions you might want to make. This lets you capture particular kinds of content that are pertinent to your application but aren't addressed by Strapi's default fields.
* ## Step 1: Create a Custom Field Component
To add a custom field to the Strapi admin panel, you first need to create a new component that defines the behavior of the field. This component will be located inside the `/src/admin/extensions` folder, which is where all your admin customizations are stored.
Here’s a simple example of a custom text input field:
```tsx
// File: /src/admin/extensions/components/CustomTextField.tsx
import React from 'react';
import { TextInput } from '@strapi/design-system/TextInput';
const CustomTextField = ({ name, value, onChange }) => {
return (
<TextInput
name={name}
label="Custom Text Field"
placeholder="Enter custom text"
value={value}
onChange={onChange}
/>
);
};
export default CustomTextField;
```
### Explanation
* To maintain consistency with the rest of the admin panel, we import the `TextInput` component from Strapi's design system.
* Three properties are passed to the `CustomTextField` component: `name,`` `value, and `onChange.` The behavior of standard form fields is mirrored in this setup.
* Real-time updates as users type are ensured by the `onChange` event, which is wired to update the value in the parent component.
* ## Step 2: In `app.tsx`, register the custom field
You must instruct the Strapi admin panel to use your custom field component after you have generated it. To accomplish this, register the new field and make changes to the `app.tsx` file located in the `/src/admin} directory.
```tsx
// File: /src/admin/app.tsx
import CustomTextField from './extensions/components/CustomTextField';
export default {
bootstrap(app) {
app.addFields({ type: 'customtext', Component: CustomTextField });
},
};
```
### Explanation:
* The lifetime of the admin panel in Strapi includes the `bootstrap` function. When the admin panel launches, it is called.
* To register our custom field, we utilize the `app.addFields()` method inside the `bootstrap` function. The React {Component} that renders the field {(CustomTextField)} is specified, along with a type of `(customtext)}.
* This guarantees that Strapi will render our custom input field each time a field of type {customtext} is used in a content type.
* ## Step 3: Utilize a Content Type's Custom Field
We only need to add the custom field to the content type's schema in order to use it. Create a new field with the `customtext` type by opening the appropriate content type schema (found in the `/api} folder).
```json
{
"collectionName": "articles",
"info": {
"name": "Article"
},
"attributes": {
"title": {
"type": "string"
},
"content": {
"type": "customtext"
}
}
}
```
### Explanation
* Content editors working with this content type will now see the custom text input field we constructed earlier. * In this instance, we define a new attribute called `content} and assign it the `customtext} type, which matches the type we registered in `app.tsx`.
* This straightforward example demonstrates how simple it is to add new functionality to the admin panel without changing the core Strapi files, guaranteeing that your customizations are modular and maintainable.
## Replacing the WYSIWYG Editor in Strapi 5
While Strapi's default WYSIWYG editor works well for simple content editing, it occasionally lacks the sophisticated capabilities that content teams need, including improved formatting options, media integration, or support for Markdown. Thankfully, Strapi enables developers to use an external editor such as TinyMCE or CKEditor in place of the built-in editor.
This section will guide you through the process of using the admin panel extensions system to swap out Strapi's built-in WYSIWYG editor with CKEditor.
* ## Step 1: Install CKEditor
Strapi's marketplace offers a number of third-party WYSIWYG editor choices. One of the most popular rich text editors is CKEditor, which has robust content management tools.
In the root directory of your project, use the following command to install CKEditor:
```bash
yarn add @strapi/plugin-ckeditor
```
The CKEditor plugin, which offers the required integration between Strapi and CKEditor, is installed by using this command.
* ## Step 2: Use CKEditor to extend the Admin Panel
After installing, you must replace the built-in WYSIWYG editor in the Strapi admin panel with CKEditor. To accomplish this, make a custom component and register it in the app.tsx file, just like you would with custom fields.
* Make the WYSIWYG component custom;
First, in the `/src/admin/extensions` folder, make a new component for CKEditor:
```tsx
// File: /src/admin/extensions/components/CustomWYSIWYG.tsx
import React from 'react';
import CKEditor from 'ckeditor4-react';
const CustomWYSIWYG = ({ value, onChange }) => {
return (
<CKEditor
initData={value}
onChange={(event) => onChange({ target: { value: event.editor.getData() } })}
/>
);
};
export default CustomWYSIWYG;
```
### Explanation
* We import the `CKEditor` component from the `ckeditor4-react` package.
* The material that will be altered is stored in the `value` prop; changes are made in real time via the `onChange` function, which updates the content.
* The current content of the CKEditor instance is retrieved using the `getData()` method.
* ### Register CKEditor in app.tsx in step three.
The next step after making the custom CKEditor component is to update the app.tsx file and register it in the admin panel:
```tsx
// File: /src/admin/app.tsx
import CustomWYSIWYG from './extensions/components/CustomWYSIWYG';
export default {
bootstrap(app) {
app.addFields({ type: 'wysiwyg', Component: CustomWYSIWYG });
},
};
```
### Explanation
* In the admin panel, we register CKEditor as a new field type (wysiwyg), much like we did with custom fields previously.
* When a field of type `wysiwyg` is found, Strapi will use CKEditor rather than the built-in WYSIWYG editor as a result.
* ## Step 4: Use Content Types in CKEditor
By changing the content type schema, you can apply CKEditor to any form of content now that it is registered as a custom WYSIWYG editor:
```json
{
"collectionName": "articles",
"info": {
"name": "Article"
},
"attributes": {
"title": {
"type": "string"
},
"content": {
"type": "wysiwyg"
}
}
}
```
* Explanation:
* Strapi now uses CKEditor for the `content` field because it is of type {wysiwyg`.
* To provide a more sophisticated text editing experience, content editors working on articles will now communicate with CKEditor rather than the built-in editor.
## Customizing the Admin Panel with Plugins
Not only can Strapi replace the WYSIWYG editor and add custom fields, but it also enables more extensive changes via plugins. Plugins are reusable modules that can expand on current capabilities or add new ones to the admin panel.
Adding functionality to the admin panel with plugins is an excellent method to keep your project modular and maintainable without having to make direct changes to the core source.
* ## Create a Custom Plugin as the First Step
Using Strapi's integrated plugin builder, you can make a new plugin:
* ## Step 1: Generate a Custom Plugin
To create a new plugin in Strapi, you can use the built-in plugin generator:
```bash
yarn strapi generate plugin myplugin
```
Within the `/plugins` directory, a new plugin will be scaffolded by using this command. This is how the folder structure will appear:
```arduino
plugins/
myplugin/
admin/
config/
controllers/
...
```
You will define the logic for your plugin's admin panel in the `admin` subdirectory.
* ## Add Admin Panel Features in Step Two
You can specify the elements and routes that will be included to the admin panel inside the `admin/src` directory of your plugin.
This is an illustration of a basic plugin that expands the admin panel's configuration page:
```tsx
// File: plugins/myplugin/admin/src/index.tsx
export default {
register(app) {
app.createSettingSection({
id: 'myplugin',
name: 'My Plugin',
description: 'A description of my plugin',
links: [
{
title: 'Configuration',
to: '/settings/myplugin/configuration',
Component: ConfigurationComponent,
},
],
});
},
};
```
### Explanation:
* The new features for the plugin are defined in the `register` function, which is called when the admin panel launches.
* We construct a new section in the admin interface's settings panel using the `createSettingSection` method. A link to the plugin's setup page is included in this section.
* The React component in charge of rendering the plugin's configuration page will be called `ConfigurationComponent}.
* ## Construct the Configuration Page in Step Three
*
Next, construct the component of the configuration page that users will see after clicking the settings panel link:
```tsx
// File: plugins/myplugin/admin/src/pages/Configuration.tsx
import React from 'react';
const ConfigurationComponent = () => {
return <div>Configuration settings for My Plugin</div>;
};
export default ConfigurationComponent;
```
### Explanation:
* This is a simple React component that renders a message to the user. In a real-world plugin, this component would contain forms, inputs, or other UI components that allow the user to customize the plugin’s settings.
## Conclusion
With the ability to extend the admin panel using React components and TypeScript, developers can create highly customized content management systems that meet the specific needs of their projects and users.
By following the examples and steps outlined in this guide, you can confidently extend and customize Strapi's admin panel to improve both functionality and usability for your content team. Whether you're adding custom fields, replacing the default WYSIWYG editor, or building full-fledged plugins, Strapi 5's TypeScript-based architecture makes these customizations robust and simple to implement.