STAC Browser has a pluggable widget system that lets you inject custom Vue components into specific locations on the page. Widgets can display pretty much any content you need - using either the pre-defined widgets or your own Vue components.
Widgets are configured in widgets.config.js at the project root.
The file exports an object where each key is a hook ID (the location on the page, see below)
and each value is an array of widget definitions to render at that location.
Multiple widgets can be added to the same hook — they render in array order.
After editing the file, restart or rebuild STAC Browser for changes to take effect.
For pre-defined widgets (located in src/widgets), specify the id
(filename without the .vue extension) and any props:
{
id: 'AlertBox',
props: {
title: 'Warning',
text: 'This catalog is currently under maintenance.'
}
}To use a component from outside src/widgets/, import it with Vue's defineAsyncComponent
and assign it to the component property:
{
id: 'MyCustomWidget',
component: defineAsyncComponent(() => import('../MyCustomWidget.vue')),
props: {
myOption: true
}
}Make sure the beginning of the config file includes:
import { defineAsyncComponent } from 'vue';By default, a widget renders whenever its hook renders. To limit a widget to
specific situations, add a condition function to the widget definition.
The widget is only shown when the function returns true. It receives an
object with the currently shown STAC entity (data) and the Vuex store
state and getters.
For example, to show a widget only on the landing page:
{
id: 'AlertBox',
condition: ({ data, getters }) => Boolean(data && getters.root && data.is(getters.root)),
props: {
text: 'Welcome!'
}
}Or only for collections:
condition: ({ data }) => Boolean(data?.isCollection)The hooks in components/AssetAlternative.vue (asset-start, asset-actions-end and asset-end)
are rendered for each mounted asset panel. Alternate panels use lazy tabs, so their hooks
only render when the corresponding tab is selected.
Widgets in these hooks receive the asset as asset prop (in addition to the configured props,
a configured asset prop is ignored) and the condition function also receives it as asset.
For example, to show a widget only for CSV files:
'asset-actions-end': [
{
id: 'CsvPreview',
component: defineAsyncComponent(() => import('../CsvPreview.vue')),
condition: ({ asset }) => asset.type === 'text/csv'
}
]The component declares the prop to receive the asset:
props: {
asset: {
type: Object,
required: true
}
}All pre-defined widgets are stored in src/widgets.
Renders a dismissible alert banner.
| Props | Type | Default | Description |
|---|---|---|---|
title |
String | '' |
Bold heading shown before the text. |
text |
String | '' |
The alert message body, CommonMark (Markdown) is supported. |
variant |
String | 'warning' |
Color variant: 'warning', 'danger', 'success', 'info', etc. |
dismissible |
Boolean | false |
Whether the user can close the alert. |
allowHTML |
Boolean | false |
Allows HTML tags in the text. |
Renders a simple text with a heading.
| Props | Type | Default | Description |
|---|---|---|---|
title |
String | '' |
Rendered as an <h3> heading. |
text |
String | '' |
Rendered as the body, CommonMark (Markdown) is supported. |
allowHTML |
Boolean | false |
Allows HTML tags in the text. |
Renders a banner indicating that the shown catalog, collection or item is not
part of the configured catalog (i.e. external content, see the allowExternalAccess option).
This helps users understand that they left the configured catalog and are now looking at
data provided by an external data source.
The widget only renders on external content, so no condition is required.
It has no effect if no catalogUrl is configured, as in that case there is no catalog
to distinguish external content from.
A typical placement is the view-catalog-meta-start and view-item-secondary-start hooks,
which show the banner above the description.
| Props | Type | Default | Description |
|---|---|---|---|
variant |
String | 'info' |
Color variant: 'info', 'warning', 'danger', etc. |
Renders a list of "featured" STAC catalogs or collections.
A typical placement is the view-catalog-catalogs-start hook, which shows the featured entities right above the regular collection list.
The widget only renders on the landing page (the root catalog).
| Props | Type | Default | Description |
|---|---|---|---|
entities |
Array | required | The entities to feature, shown in the given order. See below for the supported types of entries. |
title |
String | null |
Rendered as the heading of the list. Can be given as plain text or as the key of a phrase from the locales (e.g. defined in the custom.json files, see the localization docs). If not given, defaults to a localized version of "Featured". |
view |
String | 'cards' |
How the entities are shown: 'cards' or 'list'. Set to null to follow the view mode that the user has chosen for the other lists. |
Each entry in entities can be one of the following:
- A collection ID (a string without a slash, e.g.
'sentinel-2-l2a'): Only works for STAC APIs. - A URL (a string with a slash, absolute or relative to the catalog,
e.g.
'https://example.com/api/collections/xyz'or'./data/catalog.json'): Works for both STAC APIs and static catalogs. Entities that fail to load are not shown. - A (partially) complete STAC entity as object
(e.g.
{ id: 'xyz', title: 'My Collection', description: '…', links: […] }): Works for both STAC APIs and static catalogs. The object must contain aselflink or (for APIs) anid, otherwise the entity is not shown. STAC Browser loads the full version of the entity when needed.
Hooks are named insertion points in the STAC Browser UI where widgets get rendered.
Each hook has an ID like view-catalog-meta-start that you use as the key in
widgets.config.js.
footer-startroot-before-contentroot-endroot-start
asset-actions-endasset-endasset-start
view-search-filters-collections-endview-search-filters-collections-startview-search-filters-endview-search-filters-items-endview-search-filters-items-startview-search-filters-startview-search-results-endview-search-results-start
view-catalog-catalogs-endview-catalog-catalogs-startview-catalog-intro-endview-catalog-items-endview-catalog-items-startview-catalog-meta-endview-catalog-meta-start
view-item-primary-endview-item-primary-startview-item-secondary-endview-item-secondary-start
view-select-data-source-start
Note: This list is auto-generated. Run npm run docs:hooks to update it after adding new hooks.
A widget is a standard Vue single-file component (.vue file). To create one:
-
Create the component file in
src/widgets/or at another location of your choice. The filename (without extension) must match the component'snameproperty exactly (case-sensitive).For example,
src/widgets/BannerImage.vue:<template> <div class="banner-image"> <img :src="url" :alt="alt" /> </div> </template> <script> export default { name: "BannerImage", inheritAttrs: false, props: { url: { type: String, required: true }, alt: { type: String, default: '' } } }; </script> <style lang="scss" scoped> @import "../theme/variables.scss"; .banner-image { margin-bottom: $block-gap; img { max-width: 100%; } } </style>
-
Register it in
widgets.config.jsunder the desired hook:export default { 'view-catalog-meta-start': [ { id: 'BannerImage', props: { url: '/banner.jpg', alt: 'Catalog banner' } }, ], };
-
Rebuild STAC Browser. The widget will be dynamically imported when the hook renders.
Tips:
- Use
@import "../theme/variables.scss"to access shared SCSS variables like$block-gap. - Widgets receive the
propsdefined inwidgets.config.jsand, in some hooks, additional data from the hook (e.g. the asset in the asset hooks). Other page data such as the STAC object or items is not passed automatically, you can import it from the Vuex store. - Set
inheritAttrs: falsein all widgets. Some hooks pass data to the widgets (e.g. the asset), and Vue would add the data that a widget doesn't declare as props as attributes to its root element. - You can place the same widget at multiple hooks with different props.
To add a new widget insertion point to a view:
-
Add a
<WidgetHook>tag in the Vue template of the relevant view or component:<WidgetHook id="view-catalog-custom-start" />WidgetHookis registered as a global component, so no import is needed.If the widgets need data that is not available in the store (e.g. the asset in a list of assets), pass it through the
contextprop. The widgets receive each entry as a prop (taking precedence over the configuredprops) and theconditionfunctions receive the entries as additional properties:<WidgetHook id="asset-end" :context="{ asset }" />
-
Update the docs by running:
npm run docs:hooks
This scans all
.vuefiles for<WidgetHook>tags and updates the hook list in this document automatically.