1 | import * as React from "react";
|
2 | import { AbstractPureComponent2, Position } from "../../common";
|
3 | import { Props } from "../../common/props";
|
4 | import { IToastProps } from "./toast";
|
5 | export declare type IToastOptions = IToastProps & {
|
6 | key: string;
|
7 | };
|
8 | export declare type ToasterPosition = typeof Position.TOP | typeof Position.TOP_LEFT | typeof Position.TOP_RIGHT | typeof Position.BOTTOM | typeof Position.BOTTOM_LEFT | typeof Position.BOTTOM_RIGHT;
|
9 | /** Instance methods available on a `<Toaster>` component instance. */
|
10 | export interface IToaster {
|
11 | /**
|
12 | * Shows a new toast to the user, or updates an existing toast corresponding to the provided key (optional).
|
13 | *
|
14 | * Returns the unique key of the toast.
|
15 | */
|
16 | show(props: IToastProps, key?: string): string;
|
17 | /** Dismiss the given toast instantly. */
|
18 | dismiss(key: string): void;
|
19 | /** Dismiss all toasts instantly. */
|
20 | clear(): void;
|
21 | /** Returns the props for all current toasts. */
|
22 | getToasts(): IToastOptions[];
|
23 | }
|
24 | /**
|
25 | * Props supported by the `<Toaster>` component.
|
26 | * These props can be passed as an argument to the static `Toaster.create(props?, container?)` method.
|
27 | */
|
28 | export interface IToasterProps extends Props {
|
29 | /**
|
30 | * Whether a toast should acquire application focus when it first opens.
|
31 | * This is disabled by default so that toasts do not interrupt the user's flow.
|
32 | * Note that `enforceFocus` is always disabled for `Toaster`s.
|
33 | *
|
34 | * @default false
|
35 | */
|
36 | autoFocus?: boolean;
|
37 | /**
|
38 | * Whether pressing the `esc` key should clear all active toasts.
|
39 | *
|
40 | * @default true
|
41 | */
|
42 | canEscapeKeyClear?: boolean;
|
43 | /** Optional toast elements. */
|
44 | children?: React.ReactNode;
|
45 | /**
|
46 | * Whether the toaster should be rendered into a new element attached to `document.body`.
|
47 | * If `false`, then positioning will be relative to the parent element.
|
48 | *
|
49 | * This prop is ignored by `Toaster.create()` as that method always appends a new element
|
50 | * to the container.
|
51 | *
|
52 | * @default true
|
53 | */
|
54 | usePortal?: boolean;
|
55 | /**
|
56 | * Position of `Toaster` within its container.
|
57 | *
|
58 | * @default Position.TOP
|
59 | */
|
60 | position?: ToasterPosition;
|
61 | /**
|
62 | * The maximum number of active toasts that can be displayed at once.
|
63 | *
|
64 | * When the limit is about to be exceeded, the oldest active toast is removed.
|
65 | *
|
66 | * @default undefined
|
67 | */
|
68 | maxToasts?: number;
|
69 | }
|
70 | export interface IToasterState {
|
71 | toasts: IToastOptions[];
|
72 | }
|
73 | export declare class Toaster extends AbstractPureComponent2<IToasterProps, IToasterState> implements IToaster {
|
74 | static displayName: string;
|
75 | static defaultProps: IToasterProps;
|
76 | /**
|
77 | * Create a new `Toaster` instance that can be shared around your application.
|
78 | * The `Toaster` will be rendered into a new element appended to the given container.
|
79 | */
|
80 | static create(props?: IToasterProps, container?: HTMLElement): IToaster;
|
81 | state: IToasterState;
|
82 | private toastId;
|
83 | show(props: IToastProps, key?: string): string;
|
84 | dismiss(key: string, timeoutExpired?: boolean): void;
|
85 | clear(): void;
|
86 | getToasts(): IToastOptions[];
|
87 | render(): JSX.Element;
|
88 | protected validateProps({ maxToasts }: IToasterProps): void;
|
89 | private isNewToastKey;
|
90 | private dismissIfAtLimit;
|
91 | private renderToast;
|
92 | private createToastOptions;
|
93 | private getPositionClasses;
|
94 | private getDismissHandler;
|
95 | private handleClose;
|
96 | }
|
97 | export declare const OverlayToaster: typeof Toaster;
|
98 | export declare type OverlayToasterProps = IToasterProps;
|