Skip to content

Datasource

This component generates a datasource field to be used in the author dialog. The available values are fetched from the provided URL. The datasource field’s value is passed to the component as a prop.

Properties

PropertyTypeDescriptionDefault ValueRequired
labelstringThe label of the datasource componentYes
placeholderstringPlaceholder text for the datasource fieldNo
defaultValuestringDefault value for the datasource componentNo
urlstringURL to fetch the data sourceYes
multiplebooleanWhether multiple selections are allowedfalseNo
bodyobjectBody of the requestYes
methodstringHTTP method to use for the requestPOSTNo

Example

To use a datasource component in the author dialog, we can use the following code:

{
datasource: datasource({
label: 'Datasource',
placeholder: 'Select a data source',
defaultValue: 'default-source',
url: 'https://api.example.com/data',
multiple: false,
body: {},
method: 'POST',
})
}

Output Type

type DatasourceOutputType<Multiple extends boolean> = Multiple extends true ? string[] : string;

Example expected output from your service

[
{
"value": "value1",
"label": "Label 1"
},
{
"value": "value2",
"label": "Label 2"
}
]

Example in author dialog

Datasource Component Datasource Component