@furystack/shades-common-components
Version:
Common UI components for FuryStack Shades
52 lines • 1.64 kB
TypeScript
import { EventHub, ObservableValue } from '@furystack/utils';
export type ContextMenuItem<T> = {
type: 'item' | 'separator';
data?: T;
label?: string;
description?: string;
icon?: JSX.Element;
disabled?: boolean;
};
export type ContextMenuPosition = {
x: number;
y: number;
};
/**
* Manages context menu state including open/close, items, focus, positioning, and keyboard navigation
*/
export declare class ContextMenuManager<T> extends EventHub<{
onSelectItem: T;
}> implements Disposable {
isOpened: ObservableValue<boolean>;
items: ObservableValue<ContextMenuItem<T>[]>;
focusedIndex: ObservableValue<number>;
position: ObservableValue<ContextMenuPosition>;
/**
* Returns the indices of items that are navigable (non-separator, non-disabled)
*/
getNavigableIndices(): number[];
/**
* Opens the context menu, optionally setting items and position
* @param options - Items and/or position to set
*/
open(options?: {
items?: Array<ContextMenuItem<T>>;
position?: ContextMenuPosition;
}): void;
/**
* Closes the context menu and resets focus
*/
close(): void;
/**
* Selects a menu item by index, emits the selection event, and closes the menu
* @param index - The index of the item to select (defaults to focused item)
*/
selectItem(index?: number): void;
/**
* Handles keyboard events for menu navigation
* @param ev - The keyboard event
*/
handleKeyDown(ev: KeyboardEvent): void;
[Symbol.dispose](): void;
}
//# sourceMappingURL=context-menu-manager.d.ts.map