docs(richtext-slate): update outdated code example (#5572) (#5573)

This commit is contained in:
Alessio Gravili
2024-03-31 17:50:15 -04:00
committed by GitHub
parent 51fbd02b40
commit 71a5a02e8c

View File

@@ -167,7 +167,9 @@ Specifying custom `Type`s let you extend your custom elements by adding addition
`collections/ExampleCollection.ts` `collections/ExampleCollection.ts`
```ts ```ts
import { CollectionConfig } from 'payload/types' import type { CollectionConfig } from 'payload/types'
import { slateEditor } from '@payloadcms/richtext-slate'
export const ExampleCollection: CollectionConfig = { export const ExampleCollection: CollectionConfig = {
slug: 'example-collection', slug: 'example-collection',
@@ -181,57 +183,59 @@ export const ExampleCollection: CollectionConfig = {
}, },
], ],
required: true, required: true,
admin: { editor: slateEditor({
elements: [ admin: {
'h2', elements: [
'h3', 'h2',
'h4', 'h3',
'link', 'h4',
'blockquote', 'link',
{ 'blockquote',
name: 'cta',
Button: CustomCallToActionButton,
Element: CustomCallToActionElement,
plugins: [
// any plugins that are required by this element go here
],
},
],
leaves: [
'bold',
'italic',
{
name: 'highlight',
Button: CustomHighlightButton,
Leaf: CustomHighlightLeaf,
plugins: [
// any plugins that are required by this leaf go here
],
},
],
link: {
// Inject your own fields into the Link element
fields: [
{ {
name: 'rel', name: 'cta',
label: 'Rel Attribute', Button: CustomCallToActionButton,
type: 'select', Element: CustomCallToActionElement,
hasMany: true, plugins: [
options: ['noopener', 'noreferrer', 'nofollow'], // any plugins that are required by this element go here
},
],
},
upload: {
collections: {
media: {
fields: [
// any fields that you would like to save
// on an upload element in the `media` collection
], ],
}, },
],
leaves: [
'bold',
'italic',
{
name: 'highlight',
Button: CustomHighlightButton,
Leaf: CustomHighlightLeaf,
plugins: [
// any plugins that are required by this leaf go here
],
},
],
link: {
// Inject your own fields into the Link element
fields: [
{
name: 'rel',
label: 'Rel Attribute',
type: 'select',
hasMany: true,
options: ['noopener', 'noreferrer', 'nofollow'],
},
],
},
upload: {
collections: {
media: {
fields: [
// any fields that you would like to save
// on an upload element in the `media` collection
],
},
},
}, },
}, },
}, }),
}, },
], ],
} }