UNPKG

3.02 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent } from "../../common";
3import type { DOMMountOptions } from "../../common/utils/mountOptions";
4import type { OverlayToasterProps } from "./overlayToasterProps";
5import type { Toaster, ToastOptions } from "./toaster";
6import type { ToastProps } from "./toastProps";
7export interface OverlayToasterState {
8 toasts: ToastOptions[];
9 toastRefs: Record<string, React.RefObject<HTMLElement>>;
10}
11export type OverlayToasterCreateOptions = DOMMountOptions<OverlayToasterProps>;
12export declare const OVERLAY_TOASTER_DELAY_MS = 50;
13/**
14 * OverlayToaster component.
15 *
16 * @see https://blueprintjs.com/docs/#core/components/toast
17 */
18export declare class OverlayToaster extends AbstractPureComponent<OverlayToasterProps, OverlayToasterState> implements Toaster {
19 static displayName: string;
20 static defaultProps: OverlayToasterProps;
21 /**
22 * Create a new `Toaster` instance that can be shared around your application.
23 * The `Toaster` will be rendered into a new element appended to the given container.
24 */
25 static create(props?: OverlayToasterProps, container?: HTMLElement): Toaster;
26 /**
27 * Similar to {@link OverlayToaster.create}, but returns a Promise to a
28 * Toaster instance after it's rendered and mounted to the DOM.
29 *
30 * This API will replace the synchronous {@link OverlayToaster.create} in a
31 * future major version of Blueprint to reflect React 18+'s new asynchronous
32 * rendering API.
33 */
34 static createAsync(props?: OverlayToasterProps, options?: OverlayToasterCreateOptions): Promise<Toaster>;
35 state: OverlayToasterState;
36 private queue;
37 private toastId;
38 private toastRefs;
39 /** Compute a new collection of toast refs (usually after updating toasts) */
40 private getToastRefs;
41 show(props: ToastProps, key?: string): string;
42 private maybeUpdateExistingToast;
43 private immediatelyShowToast;
44 private startQueueTimeout;
45 private handleQueueTimeout;
46 private updateToastsInState;
47 dismiss(key: string, timeoutExpired?: boolean): void;
48 clear(): void;
49 getToasts(): ToastOptions[];
50 render(): React.JSX.Element;
51 protected validateProps({ maxToasts }: OverlayToasterProps): void;
52 /**
53 * If provided `Toast` children, automaticaly upgrade them to `Toast2` elements so that `Overlay2` can inject
54 * refs into them for use by `CSSTransition`. This is a bit hacky but ensures backwards compatibility for
55 * `OverlayToaster`. It should be an uncommon code path in most applications, since we expect most usage to
56 * occur via the imperative toaster APIs.
57 *
58 * We can remove this indirection once `Toast2` fully replaces `Toast` in a future major version.
59 *
60 * TODO(@adidahiya): Blueprint v6.0
61 */
62 private renderChildren;
63 private dismissIfAtLimit;
64 private renderToast;
65 private createToastOptions;
66 private getPositionClasses;
67 private getDismissHandler;
68 private handleClose;
69}