Files
payload/test/types/config.ts
Paul acead1083b feat: add support for interfaceName on radio and select fields to create reusable top level types (#11277)
Adds support for `interfaceName` on radio and select fields. Adding this
property will extract your provided options into a top level type for
re-use.


![image](https://github.com/user-attachments/assets/be5c3e17-5127-4546-a778-d3aa801dec90)

Added types test to make sure assignment is consistent.
2025-02-19 13:51:03 +00:00

111 lines
2.2 KiB
TypeScript

import { lexicalEditor } from '@payloadcms/richtext-lexical'
import { fileURLToPath } from 'node:url'
import path from 'path'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export default buildConfigWithDefaults({
// ...extend config here
collections: [
{
slug: 'posts',
versions: true,
fields: [
{
type: 'text',
name: 'text',
},
{
type: 'text',
name: 'title',
},
{
name: 'selectField',
type: 'select',
required: true,
interfaceName: 'MySelectOptions',
options: [
{
label: 'Option 1',
value: 'option-1',
},
{
label: 'Option 2',
value: 'option-2',
},
],
},
{
name: 'radioField',
type: 'radio',
required: true,
interfaceName: 'MyRadioOptions',
options: [
{
label: 'Option 1',
value: 'option-1',
},
{
label: 'Option 2',
value: 'option-2',
},
],
},
],
},
{
slug: 'pages',
fields: [
{
type: 'text',
name: 'title',
},
{
type: 'relationship',
relationTo: 'pages-categories',
name: 'category',
},
],
},
{
slug: 'pages-categories',
fields: [
{
type: 'text',
name: 'title',
},
{
type: 'join',
name: 'relatedPages',
collection: 'pages',
on: 'category',
},
],
},
],
admin: {
importMap: {
baseDir: path.resolve(dirname),
},
},
editor: lexicalEditor({}),
globals: [
{
slug: 'menu',
versions: true,
fields: [
{
type: 'text',
name: 'text',
},
],
},
],
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
})