Custom widgets can use the built-in Studio form builder to edit their data and format settings.
The example above adds a Special Config section to the setup tab, with an input to control the font size of the value in the custom widget.
The form is provided via the form property of the widget definition.
Form configuration using typed form builder. |
Form Setup Copy Link
The ID of each form item is a dot delimited path of the corresponding property within the widget config.
interface CustomWidgetStyle {
valueFontSize?: number;
}
interface CustomWidgetDef {
type: 'customWidget';
dataMapping: {
value: AgWidgetFieldReference[];
};
format?: AgWidgetDataFormat<CustomWidgetStyle>;
}
For the above definition, the corresponding input ID for the valueFontSize property would be format.style.valueFontSize.
Form Helpers Copy Link
The form callback provides some helper functions to create form elements for the default properties (e.g. data mapping, titles, etc.).
const widgetDefinition = {
// ...
form: (params) => {
return params.createDefaults({
dataMappingItems: [
{
key: 'value',
label: 'Value',
},
],
});
},
}
Create the default tab group with a setup and format tab. Setup tab contains: |
Creates a section containing the widget type selector. |
Create the data mapping item. Either a section if multiple data mapping fields, or a single fieldset or field item.
|
Creates a section containing the cross filter input.
supportsCrossHighlight true if this widget supports cross highlight and therefore should show the cross highlight options
|
Creates the title group. |
Creates the subtitle group. |
Creates the caption group. |
Creates the title section containing the title, subtitle and caption group. |
Form Grouping Items Copy Link
The following form items allow for grouping/structuring the form items (e.g. they have children).
| Item | Interface | Description |
|---|---|---|
| Tab Group | AgWidgetFormTabGroup / AgFormTabGroup | A group of tab items. E.g. the top-level Setup / Format tab group in the edit panel for the default widgets. |
| Tab | AgWidgetFormTab / AgFormTab | A child tab of a tab group item. E.g. the Setup tab in the edit panel for the default widgets. |
| Section | AgWidgetFormSection / AgFormSection | A top-level collection of items. E.g. the Titles section in the edit panel for the default widgets. |
| Group | AgWidgetFormGroup / AgFormGroup | A lower-level collection of items (with an optional toggle). E.g. the Title group in the edit panel for the default widgets. |
Form Input Items Copy Link
| Item | Interface | Description |
|---|---|---|
| Select | AgWidgetFormSelect / AgFormSelect | A select input item. |
| Checkbox | AgWidgetFormCheckbox / AgFormCheckbox | A checkbox input item. |
| Toggle | AgWidgetFormToggle / AgFormToggle | A toggle input item. |
| Text Input | AgWidgetFormTextField / AgFormTextField | A text input item. |
| Text Area | AgWidgetFormTextArea / AgFormTextArea | A text area input item. |
| Number Input | AgWidgetFormNumber / AgFormNumber | A number input item. |
| Optional Number Input | AgWidgetFormOptionalNumber / AgFormOptionalNumber | A number input item that allows optional values. |
| Color Input | AgWidgetFormColor / AgFormColor | A color picker input item. |
| Widget Type Selector | AgWidgetFormWidgetType (widget form only) | A select input that allows changing the widget type. |
| Field Selection Input | AgWidgetFormField (widget form only) | An input for selecting a field (supporting drag and drop). |
| Fieldset Selection Input | AgWidgetFormFieldSet (widget form only) | An input for selecting multiple fields (supporting drag and drop). |
| Grouped Typography Input | AgWidgetFormTypography (widget form only) | A group of elements for configuring typography. |