notistack-v2-maintained
Version:
Highly customizable notification snackbars (toasts) that can be stacked on top of each other
66 lines (65 loc) • 2.81 kB
TypeScript
import { Component, JSX } from "react";
import { OptionsObject, ProviderContext, RequiredBy, SnackbarKey, SnackbarMessage, SnackbarProviderProps, TransitionHandlerProps } from "./types";
type Reducer = (state: State) => State;
export interface Snack extends RequiredBy<OptionsObject, "key" | "variant" | "anchorOrigin"> {
message: SnackbarMessage;
open: boolean;
entered: boolean;
requestClose: boolean;
}
interface State {
snacks: Snack[];
queue: Snack[];
contextValue: ProviderContext;
}
export declare const SnackbarContext: import("react").Context<ProviderContext>;
export declare function useSnackbar(): ProviderContext;
export declare class SnackbarProvider extends Component<SnackbarProviderProps, State> {
constructor(props: SnackbarProviderProps);
get maxSnack(): number;
/**
* Adds a new snackbar to the queue to be presented.
* Returns generated or user defined key referencing the new snackbar or null
*/
enqueueSnackbar: (message: SnackbarMessage, opts?: OptionsObject) => SnackbarKey;
/**
* Reducer: Display snack if there's space for it. Otherwise, immediately
* begin dismissing the oldest message to start showing the new one.
*/
handleDisplaySnack: Reducer;
/**
* Reducer: Display items (notifications) in the queue if there's space for them.
*/
processQueue: Reducer;
/**
* Reducer: Hide oldest snackbar on the screen because there exists a new one which we have to display.
* (ignoring the one with 'persist' flag. i.e. explicitly told by user not to get dismissed).
*
* Note 1: If there is already a message leaving the screen, no new messages are dismissed.
* Note 2: If the oldest message has not yet entered the screen, only a request to close the
* snackbar is made. Once it entered the screen, it will be immediately dismissed.
*/
handleDismissOldest: Reducer;
/**
* Set the entered state of the snackbar with the given key.
*/
handleEnteredSnack: TransitionHandlerProps["onEntered"];
/**
* Hide a snackbar after its timeout.
*/
handleCloseSnack: TransitionHandlerProps["onClose"];
/**
* Close snackbar with the given key
*/
closeSnackbar: ProviderContext["closeSnackbar"];
/**
* When we set open attribute of a snackbar to false (i.e. after we hide a snackbar),
* it leaves the screen and immediately after leaving animation is done, this method
* gets called. We remove the hidden snackbar from state and then display notifications
* waiting in the queue (if any). If after this process the queue is not empty, the
* oldest message is dismissed.
*/
handleExitedSnack: TransitionHandlerProps["onExited"];
render(): JSX.Element;
}
export {};