Custom components
Last updated
© 2024 UI Bakery
Last updated
You can create a custom component to add functionality that is not present in the UI Bakery components list.
As a developer, you can create a custom component to use in UI Bakery. This component can have its own logic and interface that is defined by you. Additionally, the custom component 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 import custom libraries, such as jQuery or React.
Please note that the custom component is rendered inside of an iframe, thus we recommend using it only for the fix-sized elements and avoid overlays and popups inside of it.
Additionally, you can use the to render any HTML and JavaScript without any restrictions. This component is not rendered inside of an iframe.
A Custom component is an HTML page embedded within an iframe that can contain any HTML, CSS, and JavaScript. You can provide its code in the Code setting. The Custom component can communicate with other UI Bakery components, actions, and app state. It can receive data and fire events.
A typical custom component would have the following structure:
3rd party scripts
custom styles
root element (usually a <div> tag)
custom JavaScript script tag
By default, the custom component is rendered inside an iframe, so there are no specific limitations to the code and styles specified by the developer.
To pass the data into your custom component use the "Data" setting. This can be done by passing a JavaScript object that contains the necessary data, such as:
Additionally, you can pass the data using JS API in your actions:
To access this data within the custom component, use the following code:
You can also subscribe to updates of the data using the following code:
If your custom component produces events or needs to trigger an action, use the following code:
To set the value of the component, use the following code inside the custom component:
Once executed, the new value is available as {{ui.customComponent.value}}
;
To trigger an action, use the following code inside the custom component:
Then, 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 {{ui.customComponent.value}}
as well as {{params}}
variable in the assigned action.
Copy and paste the whole example into the custom component Code field:
Copy and paste the whole example into the custom component Code field:
In this example, we will create a custom calendar to display the appointments.
Find a Custom component and place it onto the working area.
In the component's Data field, assign the newly created action:{ events: {{ actions.loadAppointments.data }} }.
4. In the Code field, type in the below code:
Your calendar is ready now!
Now, let's create a project milestones Gantt chart. We will use the data about each project milestone from the data source and show its timeline and details on a Gantt chart.
For this example, we are using Google Sheets as a data source. In the table, there are the following columns:
Id
Task
Team
Responsible
Start date
ETA
Percent done.
3. Find a Custom Component and drag it onto the working area.
4. In the Data field of the component, assign the newly created action: {{actions.mapData.data}}.
Check the component now - you will see a Gantt chart populated. When you hover over a milestone, you will see additional details about it.
Copy and paste the following code into the custom component Code setting:
Start with loading the data: - Load Table with appointments data.
offer a vast variety of charts, so you can connect the charts library to UI Bakery and code your own chart.
and add a Table to display it.
2. - Code step. This action is to map the data to later use it in the chat configuration:
5. In the component's Code field, you'll need to specify the code for the Gantt. We'll take the sample from the and then make adjustments according to your data:
Here's an example of how to connect and use the library to build custom components in UI Bakery: