Skip to main content

Props

  1. MakeswiftComponentSnapshot
    required
    The Makeswift snapshot to render.
  2. string
    required
    The label of the component used in the Visual Builder.
  3. string
    The description shown in the Panel of the Makeswift builder. This can be written in Markdown format. Added in v0.24.8.
  4. string
    required
    The type of the registered Makeswift component. This should match the type property that was used when calling registerComponent.

Example

The following examples expects that you have integrated Makeswift into your project according to the App Router Installation guide. If you have not, you may need to tweak the code snippets below to match your project setup and file structure.
The following example registers a <Header> component that is editable by the user and will be displayed on each page.
Properties of a header component in the Makeswift Visual Builder

Creating the component

First, you’ll need a React component. Here, we’re going to create one that takes three properties: className, logo, and links.
@/components/header/index.tsx

Registering with Makeswift

Next, this component needs to be registered with Makeswift. This example registers the same three properties: className, logo, and links. Notice these property names match the property names defined in the Header component.
In registerComponent the hidden property is set to true which hides it from being listed in the Component Tray. This is because we will be hard-coding where this component will be incorporated into the page and we don’t want the user to drag and drop multiple instances of it.
@/components/header/register.ts
You’ll then need to import this component into your makeswift/components.ts file with the rest of your components. If you don’t already have this file, refer to the App Router Installation guide to ensure it’s created and imported in the correct places.

Rendering the component

Then, you’ll need to retrieve the snapshot of the component from the Makeswift API by calling getComponentSnapshot with a unique ID and pass that snapshot to <MakeswiftComponent>. Here, we are adding the <Header> to the root layout.tsx file so that it shows up on each page.
@/app/layout.tsx
The header should now be visible on each page within the Visual Builder.
Header component showing on a page in the Makeswift Visual Builder

Adding a description

We can define a description string using markdown formatting, and then in this `layout.tsx’ we can add the description field.
@/app/layout.tsx
You should now be able to see an info icon next to the label when selecting the component in the Visual Builder. To view your description, simply hover over the label and the popover will open.
Site header description open