@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
219 lines (218 loc) • 9.19 kB
JavaScript
export const MenuItem = (pages, customBlocks = [], depth = 0, maxDepth = 10)=>{
const menuItem = {
type: 'withBlock',
slug: `Level ${depth}`,
fields: [
// type
{
name: 'type',
type: 'select',
defaultValue: 'category',
/*
admin: {
layout: 'horizontal',
},
*/ options: [
{
label: 'Page',
value: 'page'
},
{
label: 'Category',
value: 'category'
},
{
label: 'Link',
value: 'link'
},
{
label: 'Group',
value: 'group'
}
]
},
// tabs
{
type: 'tabs',
tabs: [
// tab data
{
label: 'Data',
fields: [
// category fields
{
type: 'row',
fields: [
// category
{
type: 'withCategory',
required: true,
admin: {
width: '50%',
condition: (_, siblingData)=>siblingData?.type === 'category'
}
},
// maxDepth
{
name: 'maxDepth',
type: 'number',
admin: {
width: '50%',
condition: (_, siblingData)=>siblingData?.type === 'category'
}
},
// strategy
{
name: 'strategy',
type: 'select',
defaultValue: 'default',
admin: {
condition: (_, siblingData)=>siblingData?.type === 'category'
},
options: [
{
label: 'Default',
value: 'default'
},
{
label: 'Exclude hidden categories',
value: 'exclude-hidden'
}
]
}
],
admin: {
condition: (_, siblingData)=>siblingData?.type === 'category'
}
},
// page fields
{
type: 'row',
fields: [
// page
{
name: 'page',
type: 'relationship',
relationTo: pages,
hasMany: false,
required: true,
maxDepth: 2,
admin: {
width: '50%',
condition: (_, siblingData)=>siblingData?.type === 'page'
}
}
],
admin: {
condition: (_, siblingData)=>siblingData?.type === 'page'
}
},
// title field
{
type: 'withTitle',
required: true,
admin: {
condition: (_, siblingData)=>siblingData?.type === 'group' || siblingData?.type === 'link'
}
},
// link fields
{
type: 'row',
fields: [
// href
{
name: 'href',
type: 'text',
required: true,
localized: true,
admin: {
width: '50%',
condition: (_, siblingData)=>siblingData?.type === 'link'
}
},
// target
{
name: 'target',
type: 'text',
required: true,
defaultValue: '_blank',
admin: {
width: '50%',
condition: (_, siblingData)=>siblingData?.type === 'link'
}
}
],
admin: {
condition: (_, siblingData)=>siblingData?.type === 'link'
}
}
]
},
// markets
{
label: 'Markets',
// description: 'Configure the list of available markets for this item. Leave empty for all markets.',
fields: [
// markets
{
type: 'withMarkets'
}
]
},
// details
{
label: 'Details',
fields: [
// title
{
type: 'withText',
name: 'customTitle',
localized: true,
admin: {
condition: (_, siblingData)=>siblingData?.type === 'category' || siblingData?.type === 'page'
}
},
// abstract
{
type: 'withAbstract'
},
// media
{
type: 'withMedia'
},
// custom class
{
type: 'withText',
name: 'customClass'
},
// extra
{
type: 'withText',
name: 'extra',
localized: true
}
]
}
]
}
]
};
if (depth < maxDepth) {
depth++;
menuItem.fields.push({
name: 'items',
label: 'Items',
type: 'blocks',
blocks: [
MenuItem(pages, customBlocks, depth, maxDepth),
...customBlocks
],
admin: {
condition: (_, siblingData)=>siblingData?.type !== 'category',
initCollapsed: true
}
});
}
return menuItem;
};
//# sourceMappingURL=MenuItem.js.map