Skip to content

Writing a widget

A widget is a module whose default export is a React component; its props are the layout node’s props. It can live anywhere in the workspace; ctx.widgets.define("tests", "./widgets/tests/index.tsx") in .omfp/init.ts names it, and layouts use the name (["tests", { "command": "make test" }]). The window reloads it as soon as one of its files changes and shows any error in its place. To show it at once without declaring it: views.mount (omfp://docs/views), or in the chat: omfp_card (omfp://docs/cards).

import { Button, Card, Log, Progress } from "omfp/kit";
import { useJob } from "omfp/sdk";
export default function Tests({ command = "make test" }: { command?: string }) {
const job = useJob(command);
const done = job.stdout.filter((line) => line.startsWith("ok")).length;
const running = job.status === "running";
return (
<Card title={`Tests ${job.status} (run ${job.runs})`}>
<Progress label="Tests" value={done} max={20} />
<Log lines={job.lines.slice(-10)} />
<Button onPress={running ? job.kill : job.restart}>{running ? "Stop" : "Run again"}</Button>
</Card>
);
}

Only these resolve; everything else must be a relative file of the widget’s folder (./chart.tsx):

  • react, react/jsx-runtime, react-dom: the window’s own React 19.
  • omfp/sdk: hooks over the daemon (omfp://docs/sdk).
  • omfp/kit: the window’s components, styled by the theme (omfp://docs/kit).

JSX needs no import. The window strips TypeScript types without checking them: workspaces.check type-checks every widget and the files it imports against these modules’ declarations. CSS files cannot be imported.

  • Controls come from omfp/kit, never native <select>, <input type="checkbox|radio|range|date|color"> or <datalist>: their popups are drawn by the platform, out of the theme’s reach (omfp://docs/kit has the replacements). windows.check_widget warns about each one.
  • Phones too: every widget must work in the narrow (under 1100 px) and mobile (under 700 px) layouts. Read FRAME_LAYOUT with useWindowState and give way: stack instead of columns, no fixed widths or wide tables (wrap, or scroll inside the widget), touch-sized controls, nothing reachable only by hover.
  • Style with the kit and the theme: inline style and the theme’s custom properties (var(--omfp-primary), var(--omfp-surface-container), var(--omfp-on-surface), var(--omfp-outline), var(--omfp-s2), var(--omfp-fs-sm), var(--omfp-font-code), …). Kit components also follow the user’s skin (crush or boring); your own inline styles stay as written.
  • Effects clean up and run again: a widget in a hidden view keeps its state but its effects stop (omfp://docs/views).
  • Report results: useReportError() in the catch of every user action, useReportSuccess() for what an action did (Copied …); useNotify() only for what is worth the user’s attention later.
  • Mark targets for the window’s context menus: data-omfp-path (and data-omfp-line) on a file, data-omfp-thread on a thread, data-omfp-message on a message index (omfp://docs/keys).
  • useStored(key, initial): JSON state the daemon keeps per workspace, instance and key, shared live by every window and kept across restarts.
  • useState: this mount only.
  • Window keys (useWindowState): this window’s selection, layout and requests (omfp://docs/sdk).

Long-running commands: useJob (omfp://docs/jobs); a real terminal: useTerminal with TerminalEmulator. Data of the workspace’s MCP servers: useMcp / useMcpTool. Methods the init file defines: useMethod.

The SDK also exports the view models and strings the built-in widgets use; read a built-in’s source (omfp://widgets/builtin) to see them, or copy a default flavor widget’s folder (:widget copy omfp:<name>, omfp://docs/flavor).