Skip to Content

UI library

@microboxlabs/miot-dashboard-ui draws and edits dashboards in the browser. Version 0.1.0 needs contract 0.6.0 or later. React 18 or 19 and ECharts 6 are optional peers.

There is no root import. Import the entry you need.

Entries

EntryForNeeds React
/coreGrid sizing, widget positions, createWidgetRegistryNo
/clientcreateDashboardClient, createDashboardRoutes: talk to the serverNo
/documentcreateDashboardDocument: load, edit and save one dashboardNo
/templatescreateTemplateEngine: isolated Handlebars templatesNo
/reactComponents, hooks, widget registries and editorsYes, as a peer
/chartsChart option builders for line, bar, scatter, pie and gaugeNo
/react-chartscreateChartRegistry for ReactYes, plus ECharts
/embedmountDashboard for non-React pages that bundle their own codeUses React internally
/web-componentdefineDashboardElement: the <miot-dashboard> elementUses React internally
/browserSelf-contained build: mountDashboard, defineDashboardElement, every registry except chartsNo, it is bundled
/browser-chartsThe same, plus createChartRegistryNo, it is bundled
/styles.cssThe stylesheet. Load it once.No

Client

const client = createDashboardClient({ routes: createDashboardRoutes({ baseUrl, tenantId, scopeId }), getToken: async (signal) => token, });
MethodReturns
list(signal?)[{ slug, name }]
scopeCapabilities(signal?){ canCreate }
load(slug, signal?){ config, etag }; config is null when absent
save(slug, config, etag, signal?){ revision, updatedAt, etag }
query(slug, queryId, filters?, signal?)Result rows
queryCatalog(slug, signal?)Connections and operations for editing
capabilities(slug, signal?)The five capability flags
permissions(slug, signal?){ assignments }
setPermissions(slug, assignments, signal?)Nothing
remove(slug, signal?)Nothing

Failures throw DashboardApiError with status. The client never stores tokens, never caches, never follows redirects, and never retries a save.

For a same-origin proxy, pass routes: { dashboards, scopeCapabilities } with paths, and credentials: "same-origin".

React hooks

HookDoes
useDashboardDocumentLoad, track revision, edit, save, discard and reload
useDashboardAutosaveSave once edits pause (1.5 s by default)
useDashboardStateEdit widgets, layout, filters, queries and settings, with undo and redo (50 steps)
useSavedQueryResultsRun saved queries, refresh them, cancel obsolete runs
useDashboardFilterStateHold filter values the host controls
useFilterOptionsTurn a query result into select options
useQueryCatalogLoad the operations an editor may choose
useDashboardPermissionsLoad and replace dashboard permissions
usePlannerDataRead one named result inside a custom widget

React components

ComponentDoes
DashboardCanvasGrid plus recursive widget rendering. Read-only unless you pass editMode and callbacks.
DashboardGridThe grid alone
SavedQueryProviderRuns saved queries and gives results to widgets
DashboardFiltersProviderGives filter values and actions to widgets
DashboardGeneralSettingsEdit title, refresh and order
DashboardFilterEditorEdit filters
SavedQueryManager, SavedQueryEditorEdit saved queries from the catalog
QueryBindingSelectorBind a widget to a result
PermissionAssignmentEditorEdit dashboard permissions
DashboardTransferImport and export JSON
SettingsPanelAccessible tabbed settings with a save action

Widget components (TextCard, CircularStat, DataTable, and others) are exported too, for pages that draw widgets without the registry.

Native mounting

const handle = mountDashboard(element, options); handle.update(newOptions); // replaces every option handle.destroy(); // before removing the element
OptionMeaning
instanceKeyRequired. Change it when the person or dashboard changes. Not a secret.
registryObject with get(componentId)
widgetsThe document’s widgets
unknownWidgetLabelShown for unknown widget types
savedQueries{ client, slug, queries, filters, refreshIntervalMs, paused, errorMessage }
filterController{ definitions, values, onChange }, when viewers change filters
editMode, onLayoutCommit, onActionFor editing pages

Errors throw DashboardMountError with a stable code: mounting twice, mounting over existing content, a missing instanceKey, or updating after destroy().

Styling

The stylesheet is scoped; it does not restyle your page. Widgets follow light or dark mode from a data-miot-theme="dark" ancestor, and card colors come from --miot-card-* CSS variables you can override.

Content Security Policy

Templates compile in the browser and need 'unsafe-eval' in script-src. Template output is always text, never HTML.

The complete API, with every option, is in the package README .

Last updated on