Widget SDK
A widget is a React component in the widgets/ folder of the workspace (<name>.tsx, or a folder <name>/index.tsx). The server builds it when the file is saved, and the dashboard loads the new version without a reload. New widget… in the dashboard’s edit mode makes one from a template, and puts this type file (laborchestra-widget.d.ts) next to it for your editor.
import { Tile, useDevice } from '@laborchestra/widget';
export const meta = { title: 'Big pressure', size: 'S', profile: 'pressure_sensor' };
export default function BigPressure({ device }: { device: string }) { const d = useDevice(device); return <Tile label={device} testId="big"><span className="text-3xl font-bold">{d?.state.channels?.[0]?.pressure}</span></Tile>;}defaultis the component. It gets{ id, device, info, props }.metatells the Add widget panel what it is:sizeis'main'(fills a pane),'S'or'M'(a small tile);profileoffers it for devices of that profile only;propslists settings that its ⚙ dialog edits.- Tailwind classes work; the server builds the stylesheet from your widgets.
reactand@laborchestra/widgetcome from the page; other npm packages are bundled in (install them next to the widget). - A build error is shown in place of the widget, and an error while it runs stays inside it.
@laborchestra/widget
Section titled “@laborchestra/widget”import type { ReactNode } from 'react';
export type DeviceInfo = { status: string; error: string | null; schema: { id: string; class: string; units?: Record<string, string>; actions: { name: string; doc: string | null; params: { name: string; type: string; default: unknown; required: boolean }[] }[] } | null; state: Record<string, unknown> | null;};export type RecordingStatus = { active: boolean; name?: string; start_time?: string; elapsed_s?: number; events?: number };export type StreamFrame = { sequence: number; meta: Record<string, any>; data: Float32Array };
/** What a widget gets as props. */export type WidgetProps = { id: string; device: string; info: DeviceInfo; props: Record<string, unknown> };/** One setting of a widget instance, edited in its settings dialog and given to the widget in `props`. */export type PropSpec = { name: string; label?: string; type: 'text' | 'number' | 'integer' | 'boolean' | 'select'; default?: unknown; options?: string[]; min?: number; max?: number; help?: string;};/** What a widget module exports as `meta`, so that the picker knows it. */export type WidgetMeta = { title: string; description?: string; size: 'main' | 'S' | 'M'; profile?: string; needsDevice?: boolean; props?: PropSpec[] };export type Device = { id: string; status: string; error: string | null; state: Record<string, any>; units: Record<string, string>; action: (name: string, ...args: unknown[]) => Promise<unknown>;};
export function useDevice(id: string): Device | undefined;export function useDevices(): Record<string, DeviceInfo>;export function callAction(device: string, name: string, ...args: unknown[]): Promise<unknown>;export function useRecording(): RecordingStatus;export function useStream(device: string, stream: string, params?: Record<string, unknown>): StreamFrame | null;export function useAction(device: string): { run: (action: string, ...args: unknown[]) => Promise<void>; error: string | null };
export const Tile: (props: { label: string; testId: string; children: ReactNode; problem?: string | null }) => ReactNode;export const NumberField: (props: { value: number | null | undefined; format: (v: number) => string; parse: (text: string) => number; onCommit: (v: number) => void; testId: string; label: string;}) => ReactNode;export const formatSI: (value: number, unit: string) => string;export const formatNumber: (value: number) => string;export const parseFrequency: (text: string) => number;export const unitFor: (units: Record<string, string> | undefined, path: string) => string | undefined;Something wrong or missing on this page? Open a GitHub issue or use the form (no account needed).