Skip to content

Creating an action widget

An action widget fires events. It has no data binding — instead, it triggers named events via the on / onClick property that your application handles. The example we’ll walk through is productShare — a widget that renders social-network buttons and fires a shareEvent when clicked.

import { gui } from '@golemui/gui-shared';
gui.actions.custom('productShare', { onClick: 'shareEvent' });

When the widget calls onClick(), the form engine looks up onClick, finds 'shareEvent', and emits it through the formEvent callback. Your application code catches it there.

  • useActionWidget (React) and ActionWidgetAdapter (Angular / Lit) provide a click() / onClick method that triggers the event pipeline.
  • The event name ('shareEvent') is defined in the widget definition, not in the component — keeping your widget reusable.
  • The formEvent callback receives a FormEvent object with the current form data, so you always have access to the full form state when handling the event.
ProductShare.tsx
import * as Core from '@golemui/core';
import { useActionWidget } from '@golemui/react';
const NETWORKS = ['Twitter', 'Facebook', 'LinkedIn'];
export function ProductShare(widgetInstance: Core.WithWidget) {
const widget = widgetInstance.widget as Core.ActionWidget;
const { uid, templateData, onClick } = useActionWidget(widget);
return (
<div className="product-share" style={{ flex: templateData.size }}>
<div className="product-share__widget" id={uid}>
<span className="product-share__label">Share this product:</span>
<div className="product-share__buttons">
{NETWORKS.map((network) => (
<button
key={network}
className="product-share__button"
onClick={onClick}
>
{network}
</button>
))}
</div>
</div>
</div>
);
}

useActionWidget returns:

  • uid — unique identifier
  • templateData — your custom props plus engine-managed properties (label, disabled, etc.)
  • onClick() — emits the click event through the form engine pipeline

Click any of the share buttons to fire the shareEvent: