import type { Field, GroupField } from 'payload' /** * The two field groups every section block shares — same panel, same data * shape in every project, so the shared
/ components * work on every block. Everything is overridable: names, options, extra fields. * * fields: [buildSectionHeaderField(), …the block's own fields…, buildSectionSettingsField()] * fields: [buildSectionSettingsField({ backgrounds: [{ label: 'Brand', value: 'brand' }] })] */ export type SectionHeaderFieldOptions = { /** Extra fields inside the group (e.g. a heading level select). */ fields?: Field[] /** Generated TS type name. Default 'SectionHeaderData'. */ interfaceName?: string /** Default 'header'. */ name?: string } /** eyebrow + heading + intro, localized — rendered by the project's . */ export function buildSectionHeaderField({ name = 'header', fields = [], interfaceName = 'SectionHeaderData' }: SectionHeaderFieldOptions = {}): GroupField { return { name, type: 'group', fields: [ { name: 'eyebrow', type: 'text', admin: { description: 'Small line above the heading. Optional.' }, localized: true }, { name: 'heading', type: 'text', localized: true }, { name: 'intro', type: 'textarea', admin: { rows: 3 }, localized: true }, ...fields, ], interfaceName, } } export type SectionSettingsFieldOptions = { /** Section #id for anchor links and a section nav. Default true. */ anchor?: boolean /** * Background choices — values map to the project's own classes in
. * Default Default / Muted / Inverted (dark). `false` → no background select. */ backgrounds?: { label: string; value: string }[] | false /** Extra settings (e.g. spacing, width). */ fields?: Field[] /** Generated TS type name. Default 'SectionSettings'. */ interfaceName?: string /** Default 'settings'. */ name?: string } const DEFAULT_BACKGROUNDS = [ { label: 'Default', value: 'default' }, { label: 'Muted', value: 'muted' }, { label: 'Inverted (dark)', value: 'inverted' }, ] /** Sidebar group: anchor + background (+ your own) — instead of bgColor / sectionId per block. */ export function buildSectionSettingsField({ name = 'settings', anchor = true, backgrounds = DEFAULT_BACKGROUNDS, fields = [], interfaceName = 'SectionSettings', }: SectionSettingsFieldOptions = {}): GroupField { return { name, type: 'group', admin: { position: 'sidebar' }, fields: [ ...(anchor ? [{ name: 'anchor', type: 'text', admin: { description: 'Section id for #links and section nav, e.g. "pricing".' } } as Field] : []), ...(backgrounds && backgrounds.length ? [{ name: 'background', type: 'select', defaultValue: backgrounds[0].value, options: backgrounds } as Field] : []), ...fields, ], interfaceName, label: 'Section settings', } }