UNPKG

stream-chat-react

Version:

React components to create chat conversations or livestream style chat

54 lines (53 loc) 1.89 kB
/// <reference types="node" /> import { StateStore } from 'stream-chat'; export type GetDialogParams = { id: DialogId; }; export type GetOrCreateDialogParams = GetDialogParams; type DialogId = string; export type Dialog = { close: () => void; id: DialogId; isOpen: boolean | undefined; open: (zIndex?: number) => void; removalTimeout: NodeJS.Timeout | undefined; remove: () => void; toggle: (closeAll?: boolean) => void; }; export type DialogManagerOptions = { id?: string; }; type Dialogs = Record<DialogId, Dialog>; export type DialogManagerState = { dialogsById: Dialogs; }; /** * Keeps a map of Dialog objects. * Dialog can be controlled via `Dialog` object retrieved using `useDialog()` hook. * The hook returns an object with the following API: * * - `dialog.open()` - opens the dialog * - `dialog.close()` - closes the dialog * - `dialog.toggle()` - toggles the dialog open state. Accepts boolean argument closeAll. If enabled closes any other dialog that would be open. * - `dialog.remove()` - removes the dialog object reference from the state (primarily for cleanup purposes) */ export declare class DialogManager { id: string; state: StateStore<DialogManagerState>; constructor({ id }?: DialogManagerOptions); get openDialogCount(): number; get(id: DialogId): Dialog; getOrCreate({ id }: GetOrCreateDialogParams): Dialog; open(params: GetOrCreateDialogParams, closeRest?: boolean): void; close(id: DialogId): void; closeAll(): void; toggle(params: GetOrCreateDialogParams, closeAll?: boolean): void; remove(id: DialogId): void; /** * Marks the dialog state as unused. If the dialog id is referenced again quickly, * the state will not be removed. Otherwise, the state will be removed after * a short timeout. */ markForRemoval(id: DialogId): void; } export {};