I am looking for instructions on how to create a custom input type that I can use on components and or models so that I can define a common set of input fields once and re-use them.
For example, here is the definition of a component I have created that has a standard set of input fields to help creating links to content within the CMS. Rather than having to drag in this component as a child to other components I want to be able to define this as a custom input type (similiar to how the Cloudinary plugin defines the cloudinaryImageEditor type).
Builder.registerComponent(
dynamic(() => import("@/components/navigation/cmslink")),
{
name: "CMS Link",
inputs: [
{ name: "Label", type: "string", defaultValue: "Link Text" },
{
name: "type",
type: "string",
enum: ["page", "blog", "url", "text"],
defaultValue: "page",
},
{
name: "linkPage",
type: "reference",
model: "page",
friendlyName: "Destination",
showIf: `options.get('type') === 'page'`,
},
{
name: "linkBlog",
type: "reference",
model: "blog",
friendlyName: "Destination",
showIf: `options.get('type') === 'blog'`,
},
{
name: "linkUrl",
type: "string",
friendlyName: "Destination",
showIf: `options.get('type') === 'url'`,
},
{
name: "linkText",
type: "string",
friendlyName: "Destination",
showIf: `options.get('type') === 'text'`,
},
],
}
);
Has anyone done something like this before / could you provide examples of how to do this? My goal would be to be able to define this custom InputType named ‘cmsLink’ and then use it in registering a component like this:
Builder.registerComponent(
dynamic(() => import("@/components/helloworld")),
{
name: "Hello World",
inputs: [
{
name: "type",
type: "cmsLink",
},
{
name: "linkText",
type: "string",
},
],
}
);
Note, I am working in NextJS