Table of Contents

smudgy:widgets

Generated from smudgy v0.4.0 (smudgy-widgets.d.ts @ fef07a6b0601). Index: scriptref.

Script-driven UI: build widget trees from the components below (directly or with JSX in a .tsx module) and put them on screen with createWidget. Import from smudgy:widgets.

Mounting widgets

createWidget

export function createWidget(
    name: string,
    element: SmudgyElement,
    options?: CreateWidgetOptions,
): void;

Put a widget on screen (or replace the one already mounted under name). Re-mounting an existing name keeps its enabled state, and moves the widget when options.pane changes.

removeWidget

export function removeWidget(name: string): void;

Remove a previously-mounted named widget.

CreateWidgetOptions

export interface CreateWidgetOptions {
    pane?: Pane | string;
}

Options for createWidget.

Components

Column

export function Column(props?: ColumnProps, children?: WidgetChildren): SmudgyElement;

A vertical layout. Children are laid out top-to-bottom.

ColumnProps

export interface ColumnProps {
    width?: Bindable<WidgetLength>;
    height?: Bindable<WidgetLength>;
    spacing?: Bindable<number>;
    padding?: Bindable<number>;
    children?: WidgetChildren;
}

Props common to the linear layout containers.

Row

export function Row(props?: RowProps, children?: WidgetChildren): SmudgyElement;

A horizontal layout. Children are laid out left-to-right.

RowProps

export type RowProps = ColumnProps;

Stack

export function Stack(props?: StackProps, children?: WidgetChildren): SmudgyElement;

A layering layout. Children are stacked front-to-back.

StackProps

export interface StackProps {
    width?: Bindable<WidgetLength>;
    height?: Bindable<WidgetLength>;
    children?: WidgetChildren;
}

Props for the layering container (children stack front-to-back).

Container

export function Container(props?: ContainerProps, children?: WidgetChildren): SmudgyElement;

A single-child wrapper with alignment/background. Only the first child is used.

ContainerProps

export interface ContainerProps {
    width?: Bindable<WidgetLength>;
    height?: Bindable<WidgetLength>;
    align_x?: HorizontalAlign;
    align_y?: VerticalAlign;
    background?: Bindable<string>;
    children?: WidgetChildren;
}

Props for the single-child wrapper. Only the first child is used.

Text

export function Text(props?: TextProps, children?: WidgetChildren): SmudgyElement;

A run of (optionally colored) text.

TextProps

export interface TextProps {
    color?: Bindable<string>;
    size?: Bindable<number>;
    children?: WidgetChildren;
}

Props for a run of text. The children are concatenated as the text content.

ProgressBar

export function ProgressBar(props?: ProgressBarProps, children?: WidgetChildren): SmudgyElement;

A progress/health bar.

ProgressBarProps

export interface ProgressBarProps {
    min?: Bindable<number>;
    max?: Bindable<number>;
    value?: Bindable<number>;
    background?: Bindable<string>;
    color?: Bindable<string>;
    width?: Bindable<WidgetLength>;
    height?: Bindable<WidgetLength>;
    vertical?: boolean;
}

Props for a progress/health bar (a leaf – children are ignored).

Button

export function Button(props?: ButtonProps, children?: WidgetChildren): SmudgyElement;

A clickable button.

ButtonProps

export interface ButtonProps {
    width?: Bindable<WidgetLength>;
    height?: Bindable<WidgetLength>;
    variant?: ButtonVariant;
    onPress?: () => void;
    children?: WidgetChildren;
}

Props for a clickable button. A single non-text child is used as the label element; otherwise the text children are rendered as the label.

ButtonVariant

export type ButtonVariant = "primary" | "secondary" | "subtle" | "link";

A button emphasis variant, mapping to the theme's named button styles.

Scrollable

export function Scrollable(props?: ScrollableProps, children?: WidgetChildren): SmudgyElement;

A scrollable single-child viewport. Only the first child is used.

ScrollableProps

export interface ScrollableProps {
    width?: Bindable<WidgetLength>;
    height?: Bindable<WidgetLength>;
    direction?: ScrollDirection;
    anchor?: "start" | "end";
    children?: WidgetChildren;
}

Props for a scrollable single-child viewport. Only the first child is used.

ScrollDirection

export type ScrollDirection = "vertical" | "horizontal" | "both";

A scroll axis. Vertical by default.

Markdown

export function Markdown(props?: MarkdownProps, children?: WidgetChildren): SmudgyElement;

A rendered Markdown document. Children are concatenated as the Markdown source.

MarkdownProps

export interface MarkdownProps {
    size?: Bindable<number>;
    onLink?: (url: string) => void;
    children?: WidgetChildren;
}

Props for a rendered Markdown document. The children are concatenated as the source.

Styling follows the terminal color scheme. Links render as clickable command chips, and code renders monospace on a panel; a fenced block whose opening fence names a language (like js) is syntax-highlighted.

Links can stand in for MUD commands, two ways:

Real URLs (<http://...>) stay ordinary links, and inline code / fenced code blocks are left literal.

export function Modal(props?: ModalProps, children?: WidgetChildren): SmudgyElement;

A modal: a dimmed, input-blocking backdrop under a centered single child.

ModalProps

export interface ModalProps {
    onDismiss?: () => void;
    background?: Bindable<string>;
    children?: WidgetChildren;
}

Props for a modal: a dimmed, input-blocking backdrop under a centered content box. The single child is the content box (style it with a Container).

TextEditor

export function TextEditor(props?: TextEditorProps, children?: WidgetChildren): SmudgyElement;

A multi-line text editor. Read its text via the onChange callback.

TextEditorProps

export interface TextEditorProps {
    id?: string;
    value?: string;
    onChange?: (text: string) => void;
    placeholder?: string;
    height?: WidgetLength;
    padding?: number;
    size?: number;
    children?: WidgetChildren;
}

Props for a multi-line text editor (a leaf – children are ignored).

MapView

export function MapView(props?: MapViewProps, children?: WidgetChildren): SmudgyElement;

The map view for the current session.

MapViewProps

export interface MapViewProps {
    children?: WidgetChildren;
}

Props for the map view (a leaf – props and children are ignored).

Working with Markdown

export function extractMarkdownLinks(source: string): MarkdownLink[];

The links source contains when read as a Markdown document, in order: exactly the links a Markdown widget shows for it, including bare <command> links, with backslash escapes honored and inline code / fenced code left literal. Use it to act on the same links a widget displays, like running the first link in a room's notes.

export interface MarkdownLink {
    label: string;
    url: string;
}

One link in a Markdown document, as extractMarkdownLinks reports it.

Shared types

Element

export type Element = SmudgyElement;

Length

export type Length = WidgetLength;

Children

export type Children = WidgetChildren;

Bindable

export type Bindable<T> = T | Binding<T>;

A prop that takes a value or a live state binding (handle.bind(...) from smudgy:core). Bound props track the published value on their own – the widget repaints on each update, with no handler and no re-mount.

HorizontalAlign

export type HorizontalAlign = "left" | "start" | "center" | "right" | "end";

Horizontal alignment within a container.

VerticalAlign

export type VerticalAlign = "top" | "start" | "center" | "bottom" | "end";

Vertical alignment within a container.

Ambient globals

SmudgyElement

interface SmudgyElement {
    readonly __smudgyWidgetElement: true;
}

One piece of on-screen UI, returned by every component below. Build it, nest it as a child of another component, or mount it with createWidget; it is not inspectable from JS.

WidgetLength

type WidgetLength = number | "fill" | "shrink";

A size: a number of pixels, "fill" (take all available space), or "shrink" (hug the contents).

WidgetChild

type WidgetChild =
| SmudgyElement
| string
| number
| boolean
| null
| undefined
| import("smudgy:core").Binding<any>;

Anything a component accepts as a child: another element, text (a string or number), a state binding (rendered as live text – see bind() in smudgy:core), or null/undefined/false (dropped, so cond && <Text/> works), plus arrays of the above (flattened).

WidgetChildren

type WidgetChildren = WidgetChild | WidgetChild[];

smudgy:widgets/jsx-runtime

jsx

export function jsx(type: unknown, props: Record<string, unknown>, key?: unknown): SmudgyElement;

The automatic-JSX factory for elements.

jsxs

export function jsxs(type: unknown, props: Record<string, unknown>, key?: unknown): SmudgyElement;

The automatic-JSX factory for elements with multiple children.

Fragment

export function Fragment(props: { children?: WidgetChildren }): SmudgyElement;

Groups children with no wrapper element (<>...</>).

JSX

export namespace JSX {
    type Element = SmudgyElement;
    // No host string tags -- every JSX tag must be a widget component function.
    interface IntrinsicElements {}
    interface ElementChildrenAttribute {
        children: {};
    }
}

The JSX namespace TypeScript resolves for jsxImportSource: "smudgy:widgets".

Default export

WidgetsApi

This describes a type returned from a function on this page. Typically you'll never construct it directly.

interface WidgetsApi {
    Column: typeof Column;
    Row: typeof Row;
    Stack: typeof Stack;
    Container: typeof Container;
    Text: typeof Text;
    ProgressBar: typeof ProgressBar;
    Scrollable: typeof Scrollable;
    Markdown: typeof Markdown;
    Modal: typeof Modal;
    TextEditor: typeof TextEditor;
    Button: typeof Button;
    MapView: typeof MapView;
    createWidget: typeof createWidget;
    removeWidget: typeof removeWidget;
    extractMarkdownLinks: typeof extractMarkdownLinks;
}

The default export bundles every member above.

Default export

The module's default export (api).

const api: WidgetsApi;

Script API reference · smudgy:core — Sessions & output · smudgy:core — Lines & buffer · smudgy:core — Shared state & events · GMCP · smudgy:core — Automations · smudgy:core — Saved automations · smudgy:core — Panes · Mapper · smudgy:params