Configurable Widget Fields
The config array in the mobro-widget-config.json defines the fields users can configure
for a widget. The dashboard builder generates a form in its sidebar from these fields, and the widget reads the values
using the corresponding field hooks.
Field Types
| Type | Input in the dashboard builder | Hook to read the value |
|---|---|---|
string | Text input | useStringField |
number | Number input | useNumberField |
slider | Slider with a number input, within a range | useSliderField |
checkbox | Switch | useCheckboxField |
select | Select of predefined options | useSelectField |
radio | Radio buttons of predefined options | useSelectField |
button-group | Row of toggle buttons, optionally with icons | useButtonGroupField |
multi-select | Select of predefined options, several can be picked | useMultiSelectField |
file | File upload | useFileField, useFilesField |
font | Font select | useFontField |
metric | Metric select | useMetricField |
color | Color picker | useColorField |
repeater | List of items, each with its own set of fields | useRepeaterField |
action | Action select | useActionField |
separator | Labeled separator (deprecated, not a field) | - |
The options of select, multi-select and button-group fields can show icons from Strato and the react-icons sets
Material Design (md/), Tabler (tb/), Lucide (lu/) and Font Awesome 6 (fa6/), see Icons.
Common Properties
All fields share the following properties:
| Property | Type | Restrictions | Description |
|---|---|---|---|
| type | string | Required One of the field types above | The type of the field. |
| name | string | Required Pattern: ^[\w-]+$Unique within the widget | The identifier of the field, used to read its value. |
| label | string | - | The label shown in the dashboard builder. |
| description | string | - | A hint about the field, shown as tooltip in the dashboard builder. |
| defaultValue | - | Depends on the field type | The value of the field when a widget is added to a dashboard. |
| visibleIf | Condition | - | Only shows the field while the condition on the values of other fields passes, see Conditional Visibility. |
| hideIf | Condition | - | Hides the field while the condition on the values of other fields passes. |
Additional properties depending on the field type are described on the page of each field type.
The JSON schema also allows a value property on every field. It's used by MoBro internally; don't set it in the
mobro-widget-config.json.
Example
A mobro-widget-config.json with two configurable fields:
{
"name": "my_widget",
"displayName": "My Widget",
"filename": "MyWidget.tsx",
"config": [
{
"name": "title",
"label": "Title",
"type": "string"
},
{
"name": "show_title",
"label": "Show title",
"description": "Whether the title is shown above the value",
"type": "checkbox",
"defaultValue": true
}
]
}
To structure many fields in the dashboard builder, e.g. using tabs or by putting fields side by side, see Configurable Widget Layout. To show fields only when they're relevant, see Conditional Visibility.
Besides fields, the config array can contain markdown texts to explain
the fields, and separators.