registerComponent() options
With the registerComponent() function, you can define and register custom components for the Visual Editor with tailored solutions by defining properties, behavior, and appearance of your components.
Prerequisites
To get the most out of this document, you should be familiar with Registering Custom Components.
Required: name property
name
Type: string
Assign a unique name to identify, reference, and register the component.
To override a built-in component with your custom component, you can use the same name as the built-in component. For example, to replace the built-in Text component, you can register your component with the name Text:
Optional properties
canHaveChildren
Type: boolean
Set to true if your component can accept children. Use in combination with withChildren(YourComponent); that is, only use canHaveChildren when a component will have children.
For more information, visit Using Child Blocks to Custom Components and a hero with children GitHub example.
Tip: Builder's Gen 2 SDKs don't requirewithChildren(). For more information on the SDKs, visit SDK Comparision.
childRequirements
Type: object
Specify restrictions on the direct children of a component. Use to define the rules that the children must match in order to be considered valid.
| Name | Type | Description |
|
| Optional. Specifies a component name. This property provides a direct way to enforce that the children must be of a specific component type. |
|
| Message to show when the child requirements are not met. Use to provide information or instructions to the user about the expected child components. For example, "Children of 'Columns' must be a 'Column'". |
|
| Optional. Use for more advanced requirements by specifying a MongoDB-style query using the sift.js library. Use to define complex conditions that the children objects must match. You can use various operators, such as Example of childRequirements: {
query: {
// The child of this element must be
// a 'Button' or 'Text' component
'component.name': { $in: ['Button', 'Text'] }
}
} |
defaultChildren
Type: BuilderElement[]
Use to specify the default child elements for a component. It is an array that contains BuilderElement objects, which represent the child elements within the component.
defaultStyles
Type: object
Specify default styles for an element or component when it is dropped into the Builder.io editor.
Accepts an object where each key represents a breakpoint or screen size, and the corresponding value is a set of CSS styles to be applied at that breakpoint.
defaults
Type: Partial<BuilderElement>
Provide default options for the block when it is created. When a new instance of the block is created, these default options will be merged with any user-defined options, providing initial values for the block's properties.
For instance, to define responsive styles, use defaults.responsiveStyles:
docsLink
Type: string
Provide a link to a documentation page for the component. It is a string that represents the URL of the documentation page. This is helpful for users who want to learn more about the component's features, usage, or customization options.
group
Type: string
Assign a custom component to a named group so it appears in its own accordion section in the Visual Editor's insert menu, making it easier for users to find related components.
Components without a group value are shown in the default ungrouped section of the insert menu.
hideFromInsertMenu
Type: boolean
Hide your component in editor, useful for gradually deprecating and Versioning Custom Components.
image
Type: string
Link to an image to be used as an icon for this component in Builder's Visual Editor.
inputs
Type: Input[]
Represents the input schema for the component which is an array of Input objects that define the options in the user interface (UI) to configure the component's properties or behavior.
Each input object specifies properties, for example:
models
Type: string[]
Use to restrict the usage of a component to specific models. By providing a list of model names, the component will only be available for those models. If models is not specified, the component is available for all models.
In the following example, MyComponent is available only for the Page and Hero models.
noWrap
Type: boolean
Prevents Builder from wrapping the component in a DOM element. When set to true, Builder renders the component directly without an additional wrapper element.
Make sure to use {...props.attributes} so the component receives the necessary attributes to function properly.
This snippet is an excerpt from the full FormInputComponent on Github.
override
Type: boolean
Override the behavior of a built-in component. Any special behavior or functionality provided by the default button component, such as virtual options or custom editors, are skipped.
requiredPermissions
Type: Permission[]
Specify the availability of the component dependent on permissions.
Possible Permission values are read, publish, editCode, editDesigns, admin, and create.
For more information, see Roles and Permissions by Space.
requiresParent
Type: object
Specify restrictions on the parent component that must be met in order for the current component to be valid. Use to define requirements for the parent component's properties or type.
The available requiresParent options are:
message: A string that represents the message to be displayed when the parent requirement is not met.component(optional): Specify that the parent component must be a particular component name.query(optional): Specify a MongoDB-style query using thesift.jslibrary. This query defines the conditions that at least one parent in the hierarchy should match. The following example uses thecomponent.namefield to check if the parent is either aProduct boxor aCollectioncomponent.
screenshot
Type: string
Provide a screenshot that is displayed when a user hovers over the component in the Visual Editor.
See also the Image API and Builder's CDN.
shouldReceiveBuilderProps
Type: object
For applications using the Gen 2 SDK, the shouldReceiveBuilderProps property is needed to use Builder props within your custom components. By default, the property uses the following values:
To gain access to Builder blocks within your custom component, for example, include the key-value pair for Builder blocks, setting the value to true instead of false.
Tip: shouldReceiveBuilderProps is only applicable for applications using Builder's Gen 2 SDKs. For more information on the SDKs, visit SDK Comparision.
tag
Type: string
Use to specify a custom tag name for your custom web components. In this example, you could use <my-custom-component>.
The tag property is specifically for custom web components and is not applicable to other types of components.
What's next
Working with custom components opens up endless opportunities. For more on custom components, read: