## Introducing Prettier for docs
Prettier [was originally disabled for our docs as it didn't support MDX
2.0](1fa636417f),
outputting invalid MDX syntax.
This has since been fixed - prettier now supports MDX 2.0.
## Reducing print width
This also reduces the print width for the docs folder from 100 to 70.
Our docs code field are very narrow - this should help make code more
readable.
**Before**

**After**

**Before**

**After**

65 lines
3.1 KiB
Plaintext
65 lines
3.1 KiB
Plaintext
---
|
|
title: UI Field
|
|
label: UI
|
|
order: 200
|
|
desc: UI fields are purely presentational and allow developers to customize the Admin Panel to a very fine degree, including adding actions and other functions.
|
|
keywords: custom field, react component, fields, config, configuration, documentation, Content Management System, cms, headless, javascript, node, react, nextjs
|
|
---
|
|
|
|
The UI (user interface) Field gives you a ton of power to add your own React components directly into the [Admin Panel](../admin/overview), nested directly within your other fields. It has absolutely no effect on the data of your documents. It is presentational-only. Think of it as a way for you to "plug in" your own React components directly within your other fields, so you can provide your editors with new controls exactly where you want them to go.
|
|
|
|
With the UI Field, you can:
|
|
|
|
- Add a custom message or block of text within the body of an Edit View to describe the purpose of surrounding fields
|
|
- Add a "Refund" button to an Order's Edit View sidebar, which might make a fetch call to a custom `refund` endpoint
|
|
- Add a "view page" button into a Pages List View to give editors a shortcut to view a page on the frontend of the site
|
|
- Build a "clear cache" button or similar mechanism to manually clear caches of specific documents
|
|
|
|
To add a UI Field, set the `type` to `ui` in your [Field Config](./overview):
|
|
|
|
```ts
|
|
import type { Field } from 'payload'
|
|
|
|
export const MyUIField: Field = {
|
|
// ...
|
|
type: 'ui', // highlight-line
|
|
}
|
|
```
|
|
|
|
## Config Options
|
|
|
|
| Option | Description |
|
|
| ------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
| **`name`** \* | A unique identifier for this field. |
|
|
| **`label`** | Human-readable label for this UI field. |
|
|
| **`admin.components.Field`** \* | React component to be rendered for this field within the Edit View. [More](./overview#field) |
|
|
| **`admin.components.Cell`** | React component to be rendered as a Cell within collection List views. [More](./overview#cell) |
|
|
| **`admin.disableListColumn`** | Set `disableListColumn` to `true` to prevent the UI field from appearing in the list view column selector. |
|
|
| **`custom`** | Extension point for adding custom data (e.g. for plugins) |
|
|
|
|
_\* An asterisk denotes that a property is required._
|
|
|
|
## Example
|
|
|
|
`collections/ExampleCollection.ts`
|
|
|
|
```ts
|
|
import type { CollectionConfig } from 'payload'
|
|
|
|
export const ExampleCollection: CollectionConfig = {
|
|
slug: 'example-collection',
|
|
fields: [
|
|
{
|
|
name: 'myCustomUIField', // required
|
|
type: 'ui', // required
|
|
admin: {
|
|
components: {
|
|
Field: '/path/to/MyCustomUIField',
|
|
Cell: '/path/to/MyCustomUICell',
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}
|
|
```
|