Skip to content
Discussion options

You must be logged in to vote

I managed to resolve the issue with this code:

import { Block, Field } from 'payload/types';

type HTMLElementBlockType = (options?: {
	depth?: number;
}) => Block;

const block: HTMLElementBlockType = ({ depth = 0 } = {}) => {
	const layoutField: Field = {
		name: 'layout',
		type: 'blocks',
		blocks: [],
	};

	let o = {
		slug: 'html-element',
		labels: {
			singular: 'HTML Element Block',
			plural: 'HTML Element Blocks',
		},
		interfaceName: 'HTMLElementBlock',
		fields: [layoutField],
	};

	if (depth < 5) {
		layoutField.blocks.push(block({ depth: depth + 1 }));
	}

	return o;
};

export default block;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by GeorgeHulpoi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant