CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lumino--widgets

Comprehensive UI widget toolkit for building desktop-like web applications with layouts, panels, tabs, menus, and other interactive components

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

components.mddocs/

UI Components

Interactive UI components for user input and navigation, including tab bars, menu bars, command palettes, and scrollbars. These components provide the building blocks for creating rich user interfaces with professional desktop application features.

Capabilities

TabBar

A widget that displays titles as a single row or column of tabs with full interaction support.

/**
 * A widget that displays titles as a single row or column of tabs.
 * Provides tab selection, reordering, closing, and other interactive features.
 */
class TabBar<T> extends Widget {
  /**
   * Construct a new tab bar.
   * @param options - The options for initializing the tab bar
   */
  constructor(options?: TabBar.IOptions<T>);

  /** The renderer for the tab bar (read-only) */
  readonly renderer: TabBar.IRenderer<T>;

  /** The document context for the tab bar (read-only) */
  readonly document: Document | ShadowRoot;

  /** Whether the tabs are movable by the user */
  tabsMovable: boolean;

  /** Whether the title text can be edited by the user */
  titlesEditable: boolean;

  /** Whether a tab can be deselected by clicking it */
  allowDeselect: boolean;

  /** The insertion behavior when adding new tabs */
  insertBehavior: TabBar.InsertBehavior;

  /** The removal behavior when removing tabs */
  removeBehavior: TabBar.RemoveBehavior;

  /** The currently selected title, or null if no title is selected */
  currentTitle: Title<T> | null;

  /** The index of the currently selected tab, or -1 if no tab is selected */
  currentIndex: number;

  /** The name of the tab bar */
  name: string;

  /** The orientation of the tab bar */
  orientation: TabBar.Orientation;

  /** Whether the add button is enabled */
  addButtonEnabled: boolean;

  /** The titles managed by the tab bar (read-only) */
  readonly titles: ReadonlyArray<Title<T>>;

  /** The content node for the tab bar (read-only) */
  readonly contentNode: HTMLUListElement;

  /** The add button node for the tab bar (read-only) */
  readonly addButtonNode: HTMLDivElement;

  /** A signal emitted when the current tab changes */
  readonly currentChanged: ISignal<this, TabBar.ICurrentChangedArgs<T>>;

  /** A signal emitted when a tab is moved */
  readonly tabMoved: ISignal<this, TabBar.ITabMovedArgs<T>>;

  /** A signal emitted when a tab should be activated */
  readonly tabActivateRequested: ISignal<this, TabBar.ITabActivateRequestedArgs<T>>;

  /** A signal emitted when the add button is clicked */
  readonly addRequested: ISignal<this, void>;

  /** A signal emitted when a tab close is requested */
  readonly tabCloseRequested: ISignal<this, TabBar.ITabCloseRequestedArgs<T>>;

  /** A signal emitted when a tab detach is requested */
  readonly tabDetachRequested: ISignal<this, TabBar.ITabDetachRequestedArgs<T>>;

  /** Dispose of the tab bar and its resources */
  dispose(): void;

  /**
   * Add a tab to the end of the tab bar.
   * @param value - The title or options for creating the tab
   * @returns The title object for the added tab
   */
  addTab(value: Title<T> | Title.IOptions<T>): Title<T>;

  /**
   * Insert a tab at the specified index.
   * @param index - The index at which to insert the tab
   * @param value - The title or options for creating the tab
   * @returns The title object for the inserted tab
   */
  insertTab(index: number, value: Title<T> | Title.IOptions<T>): Title<T>;

  /**
   * Remove a tab from the tab bar.
   * @param title - The title to remove
   */
  removeTab(title: Title<T>): void;

  /**
   * Remove the tab at the specified index.
   * @param index - The index of the tab to remove
   */
  removeTabAt(index: number): void;

  /** Remove all tabs from the tab bar */
  clearTabs(): void;

  /** Release the mouse grab for the tab bar */
  releaseMouse(): void;

  /** Handle DOM events for the tab bar */
  handleEvent(event: Event): void;
}

namespace TabBar {
  /**
   * Options for initializing a tab bar.
   */
  interface IOptions<T> {
    /** The document context for the tab bar */
    document?: Document | ShadowRoot;
    
    /** Whether tabs are movable (default: false) */
    tabsMovable?: boolean;
    
    /** Whether titles are editable (default: false) */
    titlesEditable?: boolean;
    
    /** Whether tabs can be deselected (default: false) */
    allowDeselect?: boolean;
    
    /** The insertion behavior (default: 'select-tab-if-needed') */
    insertBehavior?: InsertBehavior;
    
    /** The removal behavior (default: 'select-tab-after') */
    removeBehavior?: RemoveBehavior;
    
    /** The name for the tab bar (default: '') */
    name?: string;
    
    /** The orientation (default: 'horizontal') */
    orientation?: Orientation;
    
    /** Whether add button is enabled (default: false) */
    addButtonEnabled?: boolean;
    
    /** The renderer for creating tab elements */
    renderer?: IRenderer<T>;
  }

  /**
   * The available orientations for a tab bar.
   */
  type Orientation = 'horizontal' | 'vertical';

  /**
   * The available insertion behaviors for a tab bar.
   */
  type InsertBehavior = 'select-tab' | 'select-tab-if-needed' | 'none';

  /**
   * The available removal behaviors for a tab bar.
   */
  type RemoveBehavior = 'select-tab-after' | 'select-tab-before' | 'select-previous-tab' | 'none';

  /**
   * An object which renders the visual parts of a tab bar.
   */
  interface IRenderer<T> {
    /** The CSS selector for close icons in tab elements */
    readonly closeIconSelector: string;

    /**
     * Render the virtual element for a tab.
     * @param data - The render data for the tab
     * @returns The virtual element for the tab
     */
    renderTab(data: IRenderData<T>): VirtualElement;
  }

  /**
   * The render data for a tab bar tab.
   */
  interface IRenderData<T> {
    /** The title for the tab */
    title: Title<T>;
    
    /** Whether the tab is current */
    current: boolean;
    
    /** The z-index for the tab */
    zIndex: number;
  }

  /**
   * Default tab bar renderer implementation.
   */
  class Renderer implements IRenderer<any> {
    /** The CSS selector for close icons */
    readonly closeIconSelector: string;

    /**
     * Render the virtual element for a tab.
     * @param data - The render data for the tab
     * @returns The virtual element for the tab
     */
    renderTab(data: IRenderData<any>): VirtualElement;
  }

  /** Signal argument interfaces */
  interface ICurrentChangedArgs<T> {
    previousIndex: number;
    previousTitle: Title<T> | null;
    currentIndex: number;
    currentTitle: Title<T> | null;
  }

  interface ITabMovedArgs<T> {
    fromIndex: number;
    toIndex: number;
    title: Title<T>;
  }

  interface ITabActivateRequestedArgs<T> {
    index: number;
    title: Title<T>;
  }

  interface ITabCloseRequestedArgs<T> {
    index: number;
    title: Title<T>;
  }

  interface ITabDetachRequestedArgs<T> {
    index: number;
    title: Title<T>;
    clientX: number;
    clientY: number;
    offset: { x: number; y: number };
  }
}

Usage Examples:

import { Widget, TabBar, Title } from "@lumino/widgets";

// Create tab bar
const tabBar = new TabBar<Widget>({
  orientation: 'horizontal',
  tabsMovable: true,
  insertBehavior: 'select-tab'
});

// Add tabs
const widget1 = new Widget();
const title1 = tabBar.addTab({
  owner: widget1,
  label: 'Document 1',
  iconClass: 'fa fa-file',
  closable: true
});

const widget2 = new Widget();
const title2 = tabBar.addTab({
  owner: widget2,
  label: 'Document 2',
  closable: true
});

// Handle tab selection
tabBar.currentChanged.connect((sender, args) => {
  console.log(`Selected tab: ${args.currentTitle?.label}`);
});

// Handle tab close requests
tabBar.tabCloseRequested.connect((sender, args) => {
  tabBar.removeTab(args.title);
});

// Handle tab moves
tabBar.tabMoved.connect((sender, args) => {
  console.log(`Moved tab from ${args.fromIndex} to ${args.toIndex}`);
});

MenuBar

A widget that displays application menus in a horizontal bar.

/**
 * A widget that displays a menu bar for application menus.
 * Manages a collection of menus with keyboard and mouse navigation.
 */
class MenuBar extends Widget {
  /**
   * Construct a new menu bar.
   * @param options - The options for initializing the menu bar
   */
  constructor(options?: MenuBar.IOptions);

  /** The renderer for the menu bar (read-only) */
  readonly renderer: MenuBar.IRenderer;

  /** The currently active menu, or null if no menu is active */
  readonly activeMenu: Menu | null;

  /** The index of the active menu, or -1 if no menu is active */
  activeIndex: number;

  /** The menus in the menu bar (read-only) */
  readonly menus: ReadonlyArray<Menu>;

  /** The child menu for the menu bar (read-only) */
  readonly childMenu: Menu | null;

  /** The content node for the menu bar (read-only) */
  readonly contentNode: HTMLUListElement;

  /** The overflow index for the menu bar (read-only) */
  readonly overflowIndex: number;

  /** The overflow menu for the menu bar (read-only) */
  readonly overflowMenu: Menu | null;

  /** Dispose of the menu bar and its resources */
  dispose(): void;

  /**
   * Add a menu to the end of the menu bar.
   * @param menu - The menu to add
   * @param update - Whether to update the menu bar immediately
   */
  addMenu(menu: Menu, update?: boolean): void;

  /**
   * Insert a menu at the specified index.
   * @param index - The index at which to insert the menu
   * @param menu - The menu to insert
   * @param update - Whether to update the menu bar immediately
   */
  insertMenu(index: number, menu: Menu, update?: boolean): void;

  /**
   * Remove a menu from the menu bar.
   * @param menu - The menu to remove
   * @param update - Whether to update the menu bar immediately
   */
  removeMenu(menu: Menu, update?: boolean): void;

  /**
   * Remove the menu at the specified index.
   * @param index - The index of the menu to remove
   * @param update - Whether to update the menu bar immediately
   */
  removeMenuAt(index: number, update?: boolean): void;

  /**
   * Remove all menus from the menu bar.
   * @param update - Whether to update the menu bar immediately
   */
  clearMenus(update?: boolean): void;

  /** Open the active menu */
  openActiveMenu(): void;

  /** Handle DOM events for the menu bar */
  handleEvent(event: Event): void;

  /** Activate the next menu in the menu bar */
  activateNextMenu(): void;

  /** Activate the previous menu in the menu bar */
  activatePreviousMenu(): void;
}

namespace MenuBar {
  /**
   * Options for initializing a menu bar.
   */
  interface IOptions extends Widget.IOptions {
    /** The renderer for creating menu bar elements */
    renderer?: IRenderer;
    
    /** Options for forcing item positions */
    forceItemsPosition?: Partial<IForceItemsPositionOptions>;
  }

  /**
   * An object which renders the visual parts of a menu bar.
   */
  interface IRenderer {
    /**
     * Create an item node for a menu bar item.
     * @param data - The render data for the item
     * @returns The item node for the menu
     */
    createItemNode(data: IRenderData): HTMLLIElement;

    /**
     * Update an existing item node to reflect current state.
     * @param node - The item node to update
     * @param data - The render data for the item
     */
    updateItemNode(node: HTMLLIElement, data: IRenderData): void;

    /**
     * Create an icon node for a menu bar item.
     * @param data - The render data for the item
     * @returns The icon node for the menu
     */
    createIconNode(data: IRenderData): HTMLSpanElement;

    /**
     * Update an existing icon node to reflect current state.
     * @param node - The icon node to update
     * @param data - The render data for the item
     */
    updateIconNode(node: HTMLSpanElement, data: IRenderData): void;

    /**
     * Create a label node for a menu bar item.
     * @param data - The render data for the item
     * @returns The label node for the menu
     */
    createLabelNode(data: IRenderData): HTMLSpanElement;

    /**
     * Update an existing label node to reflect current state.
     * @param node - The label node to update
     * @param data - The render data for the item
     */
    updateLabelNode(node: HTMLSpanElement, data: IRenderData): void;
  }

  /**
   * The render data for a menu bar item.
   */
  interface IRenderData {
    /** The title for the menu */
    title: Title<Menu>;
    
    /** Whether the menu is active */
    active: boolean;
  }

  /**
   * Options for forcing menu item positions.
   */
  interface IForceItemsPositionOptions {
    /** Force items to the start position */
    forceX: boolean;
    
    /** Force items to the top position */
    forceY: boolean;
  }

  /**
   * Default menu bar renderer implementation.
   */
  class Renderer implements IRenderer {
    createItemNode(data: IRenderData): HTMLLIElement;
    updateItemNode(node: HTMLLIElement, data: IRenderData): void;
    createIconNode(data: IRenderData): HTMLSpanElement;
    updateIconNode(node: HTMLSpanElement, data: IRenderData): void;
    createLabelNode(data: IRenderData): HTMLSpanElement;
    updateLabelNode(node: HTMLSpanElement, data: IRenderData): void;
  }
}

Usage Examples:

import { MenuBar, Menu } from "@lumino/widgets";
import { CommandRegistry } from "@lumino/commands";

// Create command registry
const commands = new CommandRegistry();

// Create menus
const fileMenu = new Menu({ commands });
fileMenu.title.label = 'File';
fileMenu.title.mnemonic = 0; // 'F' is underlined

const editMenu = new Menu({ commands });
editMenu.title.label = 'Edit';
editMenu.title.mnemonic = 0; // 'E' is underlined

// Create menu bar
const menuBar = new MenuBar();
menuBar.addMenu(fileMenu);
menuBar.addMenu(editMenu);

// Add menu items
fileMenu.addItem({ command: 'file:new' });
fileMenu.addItem({ command: 'file:open' });
fileMenu.addItem({ type: 'separator' });
fileMenu.addItem({ command: 'file:save' });

editMenu.addItem({ command: 'edit:cut' });
editMenu.addItem({ command: 'edit:copy' });
editMenu.addItem({ command: 'edit:paste' });

CommandPalette

A widget that displays a searchable palette of commands for quick access.

/**
 * A widget that displays a palette of commands for quick access.
 * Provides fuzzy search and keyboard navigation of available commands.
 */
class CommandPalette extends Widget {
  /**
   * Construct a new command palette.
   * @param options - The options for initializing the command palette
   */
  constructor(options: CommandPalette.IOptions);

  /** The command registry for the palette (read-only) */
  readonly commands: CommandRegistry;

  /** The renderer for the palette (read-only) */
  readonly renderer: CommandPalette.IRenderer;

  /** The search input node for the palette (read-only) */
  readonly searchNode: HTMLInputElement;

  /** The input node for the palette (read-only) */
  readonly inputNode: HTMLInputElement;

  /** The content node for the palette (read-only) */
  readonly contentNode: HTMLUListElement;

  /**
   * Add an item to the command palette.
   * @param options - The options for creating the item
   * @returns The command palette item that was added
   */
  addItem(options: CommandPalette.IItemOptions): CommandPalette.IItem;

  /**
   * Add multiple items to the command palette.
   * @param options - An array of options for creating items
   * @returns An array of command palette items that were added
   */
  addItems(options: CommandPalette.IItemOptions[]): CommandPalette.IItem[];

  /**
   * Remove an item from the command palette.
   * @param item - The item to remove
   */
  removeItem(item: CommandPalette.IItem): void;

  /**
   * Remove the item at the specified index.
   * @param index - The index of the item to remove
   */
  removeItemAt(index: number): void;

  /** Remove all items from the command palette */
  clearItems(): void;

  /** Refresh the command palette display */
  refresh(): void;

  /** Handle DOM events for the command palette */
  handleEvent(event: Event): void;
}

namespace CommandPalette {
  /**
   * Options for initializing a command palette.
   */
  interface IOptions extends Widget.IOptions {
    /** The command registry to use for the palette */
    commands: CommandRegistry;
    
    /** The renderer for creating palette elements */
    renderer?: IRenderer;
  }

  /**
   * An object which represents an item in a command palette.
   */
  interface IItem {
    /** The command identifier for the item */
    command: string;
    
    /** The arguments for the command */
    args: any;
    
    /** The category for the item */
    category: string;
    
    /** The rank for the item (lower ranks appear first) */
    rank: number;
  }

  /**
   * Options for creating a command palette item.
   */
  interface IItemOptions {
    /** The command identifier for the item */
    command: string;
    
    /** The arguments for the command (optional) */
    args?: any;
    
    /** The category for the item (default: '') */
    category?: string;
    
    /** The rank for the item (default: Infinity) */
    rank?: number;
  }

  /**
   * An object which renders the visual parts of a command palette.
   */
  interface IRenderer {
    /**
     * Create an item node for a command palette item.
     * @param data - The render data for the item
     * @returns The item node for the command
     */
    createItemNode(data: IRenderData): HTMLLIElement;

    /**
     * Update an existing item node to reflect current state.
     * @param node - The item node to update
     * @param data - The render data for the item
     */
    updateItemNode(node: HTMLLIElement, data: IRenderData): void;

    /**
     * Create a category node for a command palette category.
     * @param data - The render data for the category
     * @returns The category node
     */
    createCategoryNode(data: IRenderData): HTMLLIElement;

    /**
     * Update an existing category node to reflect current state.
     * @param node - The category node to update
     * @param data - The render data for the category
     */
    updateCategoryNode(node: HTMLLIElement, data: IRenderData): void;
  }

  /**
   * The render data for a command palette item.
   */
  interface IRenderData {
    /** The item being rendered */
    item: IItem;
    
    /** Whether the item is active */
    active: boolean;
    
    /** The indices of matched characters in the label */
    indices: number[] | null;
  }

  /**
   * Default command palette renderer implementation.
   */
  class Renderer implements IRenderer {
    createItemNode(data: IRenderData): HTMLLIElement;
    updateItemNode(node: HTMLLIElement, data: IRenderData): void;
    createCategoryNode(data: IRenderData): HTMLLIElement;
    updateCategoryNode(node: HTMLLIElement, data: IRenderData): void;
  }
}

Usage Examples:

import { CommandPalette } from "@lumino/widgets";
import { CommandRegistry } from "@lumino/commands";

// Create command registry and add commands
const commands = new CommandRegistry();

commands.addCommand('file:new', {
  label: 'New File',
  iconClass: 'fa fa-file',
  execute: () => console.log('Creating new file')
});

commands.addCommand('edit:find', {
  label: 'Find in File',
  iconClass: 'fa fa-search',
  execute: () => console.log('Opening find dialog')
});

// Create command palette
const palette = new CommandPalette({ commands });

// Add items to palette
palette.addItem({
  command: 'file:new',
  category: 'File',
  rank: 100
});

palette.addItem({
  command: 'edit:find',
  category: 'Edit',
  rank: 200
});

// User can now search and execute commands
// Typing "new" will show the "New File" command
// Pressing Enter or clicking executes the command

ScrollBar

A custom scrollbar widget for enhanced scrolling experiences.

/**
 * A custom scrollbar widget.
 * Provides precise scroll control with customizable appearance and behavior.
 */
class ScrollBar extends Widget {
  /**
   * Construct a new scrollbar.
   * @param options - The options for initializing the scrollbar
   */
  constructor(options?: ScrollBar.IOptions);

  /** The orientation of the scrollbar */
  orientation: ScrollBar.Orientation;

  /** The current value of the scrollbar */
  value: number;

  /** The page size for the scrollbar */
  page: number;

  /** The maximum value for the scrollbar */
  maximum: number;

  /** The decrement button node (read-only) */
  readonly decrementNode: HTMLDivElement;

  /** The increment button node (read-only) */
  readonly incrementNode: HTMLDivElement;

  /** The track node (read-only) */
  readonly trackNode: HTMLDivElement;

  /** The thumb node (read-only) */
  readonly thumbNode: HTMLDivElement;

  /** A signal emitted when the thumb position changes */
  readonly thumbMoved: ISignal<this, number>;

  /** A signal emitted when a step is requested */
  readonly stepRequested: ISignal<this, 'decrement' | 'increment'>;

  /** A signal emitted when a page step is requested */
  readonly pageRequested: ISignal<this, 'decrement' | 'increment'>;

  /** Handle DOM events for the scrollbar */
  handleEvent(event: Event): void;
}

namespace ScrollBar {
  /**
   * Options for initializing a scrollbar.
   */
  interface IOptions extends Widget.IOptions {
    /** The orientation of the scrollbar (default: 'vertical') */
    orientation?: Orientation;
    
    /** The initial value (default: 0) */
    value?: number;
    
    /** The page size (default: 10) */
    page?: number;
    
    /** The maximum value (default: 100) */
    maximum?: number;
  }

  /**
   * The available orientations for a scrollbar.
   */
  type Orientation = 'horizontal' | 'vertical';
}

Usage Examples:

import { ScrollBar } from "@lumino/widgets";

// Create vertical scrollbar
const scrollBar = new ScrollBar({
  orientation: 'vertical',
  value: 0,
  page: 10,
  maximum: 100
});

// Handle scroll events
scrollBar.thumbMoved.connect((sender, value) => {
  console.log(`Scrolled to position: ${value}`);
  // Update content position based on scroll value
  updateContentPosition(value);
});

scrollBar.stepRequested.connect((sender, direction) => {
  const step = 1;
  const newValue = direction === 'increment' 
    ? Math.min(scrollBar.value + step, scrollBar.maximum)
    : Math.max(scrollBar.value - step, 0);
  scrollBar.value = newValue;
});

scrollBar.pageRequested.connect((sender, direction) => {
  const newValue = direction === 'increment'
    ? Math.min(scrollBar.value + scrollBar.page, scrollBar.maximum)
    : Math.max(scrollBar.value - scrollBar.page, 0);
  scrollBar.value = newValue;
});

function updateContentPosition(value: number) {
  // Update the position of scrollable content
  const percentage = value / scrollBar.maximum;
  // Apply scroll position to content
}

docs

components.md

index.md

layouts.md

panels.md

specialized.md

widget-foundation.md

tile.json