Custom UI Components

Sometimes you want to display more information to your users, than Ucommerce does by default. You may want to display some contextual information from an external source or have a button that calls a custom API. For this purpose, Ucommerce has support for inserting custom web components into specific sections of the UI.

Custom UI Mode

We have made it easy for you as a developer to identify the sections where you can insert your custom components. For this purpose, you can enable Custom UI Mode from Settings, which will display a box with information on how to insert a component in all the places where available. In some places, like the products editor, we also pass in a props object containing relevant context data.

Getting Started

To begin using the Custom UI feature, ensure that using admin account. Navigate to the Settings, and under Developer you'll find the Custom UI mode toggle. Enable this toggle to activate the Custom UI mode.

Activating Custom UI Mode

Once the Custom UI mode is activated, a notification will be displayed in the main navigation area, indicating that you are currently in Custom UI mode. This notification serves as a visual cue to remind you that you're seeing extra sections as potential placeholders for your custom component .

Integrating Custom Components

In Custom UI mode, each page will display placeholders where you can render your custom web components. These placeholders are marked with unique keys, indicating the specific location where your custom component will be displayed.

Viewing Available Properties

Each placeholder includes an anchor labeled 'Show Available Properties.' Clicking on this anchor will reveal an object containing the properties (props) that are passed to your custom component.

Creating Custom Web Components

  1. Develop your web component using standard JavaScript.

  2. Ensure that your component adheres to the Web Components standard.

Example of web component

Inserting Components

For setting up your components we recommend creating an extension method on the IUcommerceBuilder encapsulating your configuration and calling it in your program.cs.

Call your extension method in program.cs when setting up Ucommerce

Hosting Components in Ucommerce

In order for the backoffice UI to download your custom web component, you will have to host it on a server.

Ucommerce can host your components with the CustomComponentServer.

By default, we look for a directory called /CustomComponents in your web project, so you need to ensure that it exists and is published on your website.

Create the /CustomComponents directory in your project.

Add the following to your Ucommerce project .csproj file to publish the contents of the folder to your Ucommerce website.

Once the directory exists and is published you can enable the CustomComponentServer by calling the UseComponentServer method on the IUcommerceApplicationBuilder application builder.

Last updated

Was this helpful?