@blueprintjs/core
Version:
Core styles & components
70 lines (69 loc) • 3.02 kB
TypeScript
import * as React from "react";
import { AbstractPureComponent } from "../../common";
import type { DOMMountOptions } from "../../common/utils/mountOptions";
import type { OverlayToasterProps } from "./overlayToasterProps";
import type { Toaster, ToastOptions } from "./toaster";
import type { ToastProps } from "./toastProps";
export interface OverlayToasterState {
toasts: ToastOptions[];
toastRefs: Record<string, React.RefObject<HTMLElement>>;
}
export type OverlayToasterCreateOptions = DOMMountOptions<OverlayToasterProps>;
export declare const OVERLAY_TOASTER_DELAY_MS = 50;
/**
* OverlayToaster component.
*
* @see https://blueprintjs.com/docs/#core/components/toast
*/
export declare class OverlayToaster extends AbstractPureComponent<OverlayToasterProps, OverlayToasterState> implements Toaster {
static displayName: string;
static defaultProps: OverlayToasterProps;
/**
* Create a new `Toaster` instance that can be shared around your application.
* The `Toaster` will be rendered into a new element appended to the given container.
*/
static create(props?: OverlayToasterProps, container?: HTMLElement): Toaster;
/**
* Similar to {@link OverlayToaster.create}, but returns a Promise to a
* Toaster instance after it's rendered and mounted to the DOM.
*
* This API will replace the synchronous {@link OverlayToaster.create} in a
* future major version of Blueprint to reflect React 18+'s new asynchronous
* rendering API.
*/
static createAsync(props?: OverlayToasterProps, options?: OverlayToasterCreateOptions): Promise<Toaster>;
state: OverlayToasterState;
private queue;
private toastId;
private toastRefs;
/** Compute a new collection of toast refs (usually after updating toasts) */
private getToastRefs;
show(props: ToastProps, key?: string): string;
private maybeUpdateExistingToast;
private immediatelyShowToast;
private startQueueTimeout;
private handleQueueTimeout;
private updateToastsInState;
dismiss(key: string, timeoutExpired?: boolean): void;
clear(): void;
getToasts(): ToastOptions[];
render(): React.JSX.Element;
protected validateProps({ maxToasts }: OverlayToasterProps): void;
/**
* If provided `Toast` children, automaticaly upgrade them to `Toast2` elements so that `Overlay2` can inject
* refs into them for use by `CSSTransition`. This is a bit hacky but ensures backwards compatibility for
* `OverlayToaster`. It should be an uncommon code path in most applications, since we expect most usage to
* occur via the imperative toaster APIs.
*
* We can remove this indirection once `Toast2` fully replaces `Toast` in a future major version.
*
* TODO(@adidahiya): Blueprint v6.0
*/
private renderChildren;
private dismissIfAtLimit;
private renderToast;
private createToastOptions;
private getPositionClasses;
private getDismissHandler;
private handleClose;
}