toastification
Version:
Toast Notifications for TypeScript & Lestin
206 lines (205 loc) • 6.69 kB
TypeScript
import type Lestin from "lestin";
/**
* An enumeration of the different types of toasts that can be created.
*/
export declare enum ToastType {
/**
* A toast indicating a successful operation.
*/
Successful = "Success",
/**
* A toast indicating an error.
*/
Error = "Error",
/**
* A toast providing information.
*/
Info = "Info"
}
/**
* An object containing data for each type of toast.
*/
export declare const ToastTypeData: {
[name in keyof typeof ToastType]: {
classname: string;
text: string;
color: string;
};
};
/**
* An interface representing the properties that can be passed to a Toast instance to customize its appearance and behavior.
*/
export interface IToast_Props {
/**
* How long to wait before automatically dismissing the toast (in milliseconds).
*/
duration?: number;
/**
* The background color of the toast.
*/
backColor?: string;
/**
* The title to display in the toast.
*/
title?: string;
/**
* Whether the toast should be pinned or not.
*/
isPinned?: boolean;
/**
* Whether to hide the pin button or not.
*/
noPin?: boolean;
/**
* Whether to hide the dismiss button or not.
*/
noDismiss?: boolean;
/**
* The text alignment of the toast text.
*/
textAlign?: "start" | "end" | "center";
/**
* The font size of the toast text.
*/
textSize?: string;
/**
* The font weight of the toast text.
*/
textWeight?: string;
/**
* The text alignment of the toast title.
*/
titleAlign?: "start" | "end" | "center";
/**
* The font size of the toast title.
*/
titleSize?: string;
/**
* The font weight of the toast title.
*/
titleWeight?: string;
/**
* An array of buttons to display in the toast.
*/
buttons?: IToastButton_Props[];
/**
* Indicates whether the component should display a loader.
*/
hasLoader?: boolean;
/**
* Specifies whether only a loader should be displayed.
*/
onlyLoader?: boolean;
}
/**
* An interface representing the properties of a button in a toast.
*/
interface IToastButton_Props {
/**
* The text to display on the button.
*/
text: string;
/**
* The CSS class to apply to the button.
*/
style?: string;
/**
* The function to call when the button is clicked.
*/
onClick: Lestin.MouseEventHandler<HTMLButtonElement>;
}
/**
* A class representing a toast notification.
*/
export declare class Toast {
#private;
/**
* The HTML element representing the toast.
*/
readonly toastElement: HTMLElement;
/**
* The current percentage of the progress bar.
*/
currentPercent: number | null;
/**
* Whether the toast is pinned or not.
*/
get isPinned(): boolean;
/**
* Creates a new Toast instance.
*
* @param {ToastType} [toastType=ToastType.Info] - The type of toast to create.
* @param {string} [toastText=""] - The text to display in the toast.
* @param {IToast_Props} [options={}] - An object containing options for customizing the appearance and behavior of the toast.
*/
constructor(toastType?: ToastType, toastText?: string, options?: IToast_Props);
BuildToast(toastType?: ToastType, toastText?: string, options?: IToast_Props): this;
BuildSuccessToast(toastText?: string, options?: IToast_Props): Toast;
BuildErrorToast(toastText?: string, options?: IToast_Props): Toast;
BuildInfoToast(toastText?: string, options?: IToast_Props): Toast;
BuildLoaderToast(toastText?: string, options?: IToast_Props): Toast;
/**
* Pins the toast so that it does not automatically dismiss.
*
* @param {number} [percent=0] - The percentage of the progress bar to fill.
* @returns {Toast} - The Toast instance.
*/
Pin(percent?: number): Toast;
/**
* Sets the text of the toast.
*
* @param {string} [text=""] - The new text to display in the toast.
* @returns {Toast} - The Toast instance.
*/
SetText(text?: string): Toast;
/**
* Dismisses the toast.
*
* @param {number} [timeMs=0] - How long to wait before dismissing the toast (in milliseconds).
* @returns {number} - The ID of the timeout that was set.
*/
Dismiss(timeMs?: number): number | any;
/**
* Sets the percentage of the progress bar to fill.
*
* @param {number} [percentage=0] - The new percentage to fill the progress bar with.
* @returns {Toast} - The Toast instance.
*/
SetPercent(percentage?: number): Toast;
/**
* Sets an interval for automatically dismissing the toast.
*
* @param {number} [durationMs=toast_DefaultProps.duration] - How long to wait before dismissing the toast (in milliseconds).
* @param {number} [initialPercent=0] - The initial percentage of the progress bar to fill.
* @returns {Toast} - The Toast instance.
*/
SetInterval(durationMs?: number, initialPercent?: number): Toast;
SetGoing: (durationMs?: number, initialPercent?: number) => Toast;
SetToastType(toastType: ToastType): Toast;
/**
* Sets the inner HTML content of the toast element.
*
* @param {string} content - The new HTML content to set.
*/
set innerHTML(content: string);
}
/**
* A function component that returns a `ToastBox` element.
*
* @returns {HTMLDivElement} - A `ToastBox` element.
*/
export declare const ToastBox: () => HTMLDivElement;
/**
* Creates and displays a new toast notification.
*
* @param {ToastType} [toastType=ToastType.Info] - The type of toast to create.
* @param {string} [toastText=""] - The text to display in the toast.
* @param {IToast_Props} [options={}] - An object containing options for customizing the appearance and behavior of the toast.
* @returns {Toast} - The new Toast instance that was created.
*/
export declare function ShowToast(toastType?: ToastType, toastText?: string, options?: IToast_Props, toastBoxParent?: HTMLElement): Toast;
export declare function ShowSuccessToast(toastText?: string, options?: IToast_Props, toastBoxParent?: HTMLElement): Toast;
export declare function ShowErrorToast(toastText?: string, options?: IToast_Props, toastBoxParent?: HTMLElement): Toast;
export declare function ShowInfoToast(toastText?: string, options?: IToast_Props, toastBoxParent?: HTMLElement): Toast;
export declare function ShowLoaderToast(toastText?: string, options?: IToast_Props, toastBoxParent?: HTMLElement): Toast;
export {};