Custom component

UI Bakery offers a large number of built-in components that you can choose from. Check out our Reference section for the full list. But it's also possible to create custom components if you want to add functionality not present in our Components list. Here, we'll dive into how custom components work and provide you with some examples.

Custom components basics

Custom components can have their own logic and interface that are defined by you. Additionally, they can communicate with other features in UI Bakery by triggering events and receiving data to display. Custom components can be written in pure JavaScript or can be imported from custom libraries, such as jQuery or React.

Component anatomy

A custom component is basically an HTML page embedded within an iframe that can contain HTML, CSS, and JavaScript. You can specify its code in the component's Code property.

Here is an example of a custom component based on React:

Since the custom component is rendered inside an iframe there are no specific limitations to the code and styles specified by the developer.

Passing data to a component

To pass data into your custom component you can use the component's Data property. You simply need to specify the JavaScript object that contains the necessary data, for example:

Additionally, you can also pass data using JS API in your actions:

  • To access this data within the custom component, you can use:

  • You can also subscribe to updates of the data using:

Receiving data and triggering actions from a component

If your custom component produces events or needs to trigger an action, you can use the following code:

Use this code inside the component to set its value. Once executed, the new value will be available as {{ui.customComponent.value}}.

Use this code inside the component to trigger an action. You also need to subscribe your action to the On Event trigger of the custom component. Once the UB.triggerEvent('data') is executed, the assigned action will be triggered.

The data supplied to the triggerEvent() function is available as the {{ui.customComponent.value}} variable as well as the {{params}} variable in the assigned action.

jQuery example

Copy and paste the whole example into the custom component Code field:

React example

Copy and paste the whole example into the custom component Code field:

Custom components examples

Now that we're done with the basics, let's explore how you can actually create custom components. In this section, we'll review the following examples:

Custom Calendar

In this section, we will create a custom calendar to display appointments:

  1. Start by loading your data - create a JavaScript Code action step and add your data in the following format:

This format is required to make sure your events are correctly displayed in the calendar.

  1. Next, add a Custom Component to your working area.

  2. Assign your load data action to the custom component's Data field: { events: {{ actions.loadAppointments.data }} }.

4. In the component's Code field, specify the following code:

And voilΓ ! Your calendar is ready now.

MUI React library template example

You can connect and use the MUI library to build custom components in UI Bakery, for example, a custom Sign In form.

To do so, simply copy and paste the following code in the custom component Code field:

Last updated

Was this helpful?