Skip to main content

Derive a UI mod

Use this page as an authoring skill. First choose the public UI owner. Then derive the smallest contribution from the SDK installed with the host.

need -> public owner -> live contract -> total presentation -> one registration -> proof

Do not start with JSX. The wrong UI lane can compile and still put behavior in the wrong runtime.

Route the request​

NeedUse
Show a notification, confirmation, input, pick, or progressctx.ui from @modular/sdk
Add a docked React panelview(...) and @modular/sdk/ui
Show a hierarchy with native rows and selectiontreeView(...)
Add UI inside a document or canvaseditorExtension(...) or canvasElement(...)
Add content to existing workbench chrome@modular/sdk/mod-ui
Open a target, apply a layout, or own a status itemctx.workbench

These APIs solve different problems. They are not alternate ways to mount the same component.

ctx.ui is an interaction capability​

UiCapability groups notifications, dialogs, quick input, and progress. Each call takes a request and returns a result. Handle the result kind. The user can cancel or dismiss the request.

Do not assume every handler receives this capability. Commands, slash commands, effects, views, and renderer-native host contexts expose ui. Tools, checks, auth providers, and the base context do not.

@modular/sdk/ui is the host React surface​

Use its components, icons, styles, and hooks inside a component the host mounts. The host supplies React and the live SDK module. Do not bundle another copy or import the internal design system.

See the component guide and the generated @modular/sdk/ui reference.

@modular/sdk/mod-ui decorates published chrome​

Mod UI does not provide a free DOM mount point. It selects a semantic row and renders into one slot that the row family publishes.

semantic row -> selector -> slot -> ModUI class -> defineMod({ ui: [...] })

See the generated Mod UI reference for the live families, selectors, classes, and types.

Discover before you write​

Use the installed SDK as the source of truth.

modular mod docs <mod-id> --symbol ModUI
modular mod docs <mod-id> --symbol UiCapability
modular mod language <mod-id> completions <file> --line <n> --column <n>
modular mod language <mod-id> hover <file> --line <n> --column <n>

Use completion to prove:

  1. the row family exists;
  2. a filter narrows the row as expected;
  3. the target slot belongs to that family;
  4. the supporting row fields exist;
  5. the host action exists.

If the public tools do not expose a field, slot, or action, treat it as a capability gap. Do not inspect product internals and copy a private contract.

Derive a Mod UI contribution​

Follow this order:

  1. Start with selector(query => query.from(family)).
  2. Add variant or a supported where comparison only when required.
  3. Choose a slot from language completion.
  4. Export one named class that extends ModUI.
  5. Read the selected row from this.self.value.
  6. Read supporting families from this.rows(family).value.
  7. Convert the inputs into one closed presentation value.
  8. Render only from that value.
  9. Use this.host.actions for host changes. Never mutate a row.
  10. Register the contribution once in the top-level ui array.

The current public ModUI class is not generic. Authoring analysis derives the selected-row type from the local selector and contribution binding.

Complete neutral example​

This example adds an owner marker to every published view title. It also shows how to join a selected row to a supporting row family.

Create src/view-owner-marker.tsx:

import type { ReactNode } from 'react';
import { contribute, ModUI, selector } from '@modular/sdk/mod-ui';
import { style } from '@modular/sdk/ui';

const allViews = selector(query => query.from('views'));

const marker = style(
  {
    color: '$text.secondary',
    fontSize: 10,
  },
  'view-owner-marker'
);

type MarkerPresentation =
  | { readonly kind: 'known'; readonly label: string }
  | { readonly kind: 'unknown'; readonly label: string };

export class ViewOwnerMarker extends ModUI {
  private readonly definitions = this.rows('viewDefinitions');

  override render(): ReactNode {
    const view = this.self.value;
    const definition = this.definitions.value.find(
      candidate => candidate.id === view.descriptorId
    );
    const presentation: MarkerPresentation =
      definition === undefined
        ? { kind: 'unknown', label: 'Unknown view' }
        : { kind: 'known', label: definition.name };

    return (
      <span
        aria-label={presentation.label}
        className={marker}
        data-state={presentation.kind}
        title={presentation.label}
      >
        {presentation.kind}
      </span>
    );
  }
}

export const viewOwnerMarker = contribute({
  selector: allViews,
  slot: 'title.accessory',
  ui: ViewOwnerMarker,
});

Register it in src/mod.tsx:

import { defineMod } from '@modular/sdk';

import { viewOwnerMarker } from './view-owner-marker';

export default defineMod({
  metadata: {
    displayName: 'UI Mods',
    description: 'Adds small workbench UI contributions.',
  },
  ui: [viewOwnerMarker],
});

self is the selected views row. rows('viewDefinitions') is a supporting live row set. The join handles absence explicitly instead of spreading an optional value through the render tree.

The example uses title.accessory, a slot published by the views family. A different family can publish different slots. Always use completion at the actual contribution site.

Keep presentation total​

Derive one presentation value before JSX.

self row + supporting rows + local state -> closed presentation union -> JSX

Use a closed union or an exhaustive switch when the host publishes a state union. Give absence a named state. Do not stack unrelated JSX conditions until priority becomes accidental.

Keep semantic priority in the presentation function. Keep color, spacing, and motion in styles.

Use host actions for interaction​

Semantic rows are read-only facts. If the contribution has a button or menu, use the family actions exposed through this.host.actions. Use language completion on that value to find the allowed action and input.

Do not call private workbench services. Do not dispatch a DOM event to imitate a host action. Do not mutate self or a supporting row.

Style for the host​

  • Import public styles and components from @modular/sdk/ui.
  • Use host tokens instead of fixed theme colors.
  • Keep chrome additions small. The host still owns the surrounding layout.
  • Give icon-only controls an accessible name.
  • Do not use color or motion as the only status signal.
  • Disable non-essential animation under prefers-reduced-motion.
  • Dispose external resources through registerDisposable.

ModUI owns signal, computed, and effect. Use them for local reactive state. Use rows or liveQuery for host-owned state.

Make one clean owner​

When moving a contribution between mods:

  1. add the source and registration to the destination;
  2. delete the previous registration;
  3. delete the previous source;
  4. search for the old symbol and slot binding;
  5. check both the destination and the previous owner.

Do not keep a forwarding export or register both copies. Two registrations can mount two elements into the same slot.

Prove the result​

Use a preview check before changing disk source. Then check the installed mod.

modular mod check <mod-id>

The proof path is:

docs symbol -> language hover/completion -> preview check -> disk check
          -> committed generation -> runtime inspection

Require static, fold, build, and runtime to be clean. An unavailable layer is not a pass. A preview has no committed generation, so runtime can be unavailable during source-shape research. The installed disk check must finish the proof.