Skip to content

Item Renderers

Some widgets render a list of items β€” dropdown, list, radiogroup, and similar. By default, each item is rendered as a label/value pair. Item renderers let you supply a richer template (e.g. a country flag next to its label, a product card with a thumbnail and a price).

An item renderer is a small framework-specific function or component that receives the current item and returns the template for it. The renderer is registered under a name; widgets reference that name through their itemRenderer prop.

The shape of CountryItemRenderer itself is framework-specific β€” see Extending GolemUI / Item Renderers for the implementation contract. The wiring below shows how to register and use it once it exists.

In the Programmatic API, item renderers go inside formConfig.itemRenderers. The widget references the renderer by name through its itemRenderer prop.

import { gui } from '@golemui/gui-shared';
import { GuiForm } from '@golemui/gui-react';
import { CountryItemRenderer } from './CountryItemRenderer';
const config = {
formDef: [
gui.inputs.dropdown('country', {
items: [
{ id: 'US', flag: 'πŸ‡ΊπŸ‡Έ', label: 'United States' },
{ id: 'CA', flag: 'πŸ‡¨πŸ‡¦', label: 'Canada' },
],
labelField: 'label',
valueField: 'id',
itemRenderer: 'countryItemRenderer',
}),
],
formConfig: { itemRenderers: { countryItemRenderer: CountryItemRenderer } },
};
export function MyForm() {
return <GuiForm config={config} />;
}

In the JSON path, item renderers go into the itemRenderers property on the config object. The JSON references the renderer by name through the dropdown’s "itemRenderer" field.

{
"form": [
{
"kind": "input",
"type": "dropdown",
"path": "country",
"items": [
{ "id": "US", "flag": "πŸ‡ΊπŸ‡Έ", "label": "United States" },
{ "id": "CA", "flag": "πŸ‡¨πŸ‡¦", "label": "Canada" }
],
"labelField": "label",
"valueField": "id",
"itemRenderer": "countryItemRenderer"
}
]
}
import { GuiForm } from '@golemui/gui-react';
import formDef from './my-form.json';
import { CountryItemRenderer } from './CountryItemRenderer';
const config = {
formDef,
itemRenderers: { countryItemRenderer: CountryItemRenderer },
};
export function MyForm() {
return <GuiForm config={config} />;
}