Skip to content

Creating a display widget

A display widget renders read-only content. It has no data binding, no validation, and no events — just props. The example we’ll walk through is productDescription — a product image alongside a markdown description.

import { gui } from '@golemui/gui-shared';
gui.displays.custom('productDescription', {
img: 'assets/product-image.png',
description: `### My Cool Product
My product is the best`,
});
  • useDisplayWidget (React) and DisplayWidgetAdapter (Angular / Lit) give you the merged templateData (your custom props plus engine-managed values).
  • No onValueChanged, no events — you just render.
  • For inline ad-hoc markup that doesn’t justify a full custom widget, use the Renderer widget instead.

This is a great place to show how you can use GolemUI’s library of custom elements inside your own widgets. The gui-markdown-text web component ships with @golemui/gui-components and renders markdown as HTML — no extra dependencies needed.

ProductDescription.tsx
import * as Core from '@golemui/core';
import { useDisplayWdiget } from '@golemui/react';
import '@golemui/gui-components';
interface ProductDescriptionProps {
img: string;
description: string;
}
export function ProductDescription(widgetInstance: Core.WithWidget) {
const widget = widgetInstance.widget as Core.DisplayWidget;
const { uid, templateData } =
useDisplayWdiget<ProductDescriptionProps>(widget);
return (
<div className="product-description" style={{ flex: templateData.size }}>
<div className="product-description__widget" id={uid}>
<img
className="product-description__image"
src={templateData.img}
alt="Product"
/>
<gui-markdown-text md={templateData.description} />
</div>
</div>
);
}

useDisplayWdiget returns just uid and templateData — the simplest hook of the four. Your custom props (img, description) are available directly on templateData.

Notice the <gui-markdown-text> custom element: import @golemui/gui-components once and you can use any of GolemUI’s web components in your JSX.

Here’s the product description displaying an image alongside rendered markdown: