UNPKG

melt

Version:

The next generation of Melt UI. Built for Svelte 5.

184 lines (183 loc) 5.1 kB
import type { MaybeGetter } from "../types"; export type ToasterProps = { /** * The delay in milliseconds before the toast closes. Set to 0 to disable. * @default 5000 */ closeDelay?: MaybeGetter<number | undefined>; /** * The sensitivity of the toast for accessibility purposes. * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live * @default 'polite' */ type?: MaybeGetter<"assertive" | "polite" | undefined>; /** * The behaviour when a toast is hovered. * Pass in `null` to disable. * * @default 'pause' */ hover?: MaybeGetter<"pause" | "pause-all" | null | undefined>; }; export type AddToastArgs<T = object> = { /** * The id of the toast. If undefined, a random one will be generated */ id?: string; /** * The delay in milliseconds before the toast closes. Set to 0 to disable. * If `undefined`, uses the `closeDelay` defined in the parent toaster. */ closeDelay?: number; /** * The sensitivity of the toast for accessibility purposes. * If `undefined`, uses the `type` defined in the parent toaster. */ type?: "assertive" | "polite"; /** * The data passed to the toaster. */ data: T; }; export type UpdateToastArgs<T = object> = { /** * The id of the toast. */ id: string; /** * The delay in milliseconds before the toast closes. Set to 0 to disable. * If `undefined`, uses the `closeDelay` defined in the parent toaster. */ closeDelay?: number; /** * The sensitivity of the toast for accessibility purposes. * If `undefined`, uses the `type` defined in the parent toaster. */ type?: "assertive" | "polite"; /** * The data passed to the toaster. */ data: T; }; export declare class Toaster<T = object> { #private; ids: { root: string; }; closeDelay: number; type: "assertive" | "polite"; hover: "pause" | "pause-all" | null; /** The active toasts. */ toasts: Toast<T>[]; constructor(props?: ToasterProps); /** * Adds a toast. */ addToast: (props: AddToastArgs<T>) => Toast<T>; /** * Removes the toast with the specified ID. * @param id The id of the toast. */ removeToast: (id: string) => void; /** * Updates a toast's data. * @param id The id of the toast. * @param data The updated data. */ updateToast: (args: UpdateToastArgs<T>) => void; /** * Spread attributes for the container of the toasts. */ get root(): { readonly "data-melt-toaster-root": ""; readonly id: string; readonly popover: "manual"; }; } type ToastProps<T = object> = { /** * The parent toaster instance */ toaster: Toaster<T>; /** * The toast's unique ID. */ id: string; /** * How many milliseconds the toast will stay open. */ closeDelay: number; /** * The sensitivity of the toast for accessibility purposes. * https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live */ type: "assertive" | "polite"; /** * The data that was passed when calling `addToast` */ data: T; }; declare class Toast<T = object> { #private; readonly toaster: Toaster<T>; readonly id: string; /** The original data you passed to the `addToast` function. */ data: T; closeDelay: number; type: "assertive" | "polite"; /** State */ ids: { title: string; description: string; content: string; close: string; }; readonly createdAt: number; timeElapsed: number; readonly percentage: number; constructor(props: ToastProps<T>); /** Remove toast. */ readonly removeSelf: () => void; /** @internal */ readonly cleanup: () => void; /** Pause toast timer. */ readonly pause: () => void; /** Reset toast timer. */ readonly reset: () => void; /** Resume toast timer */ readonly resume: () => void; /** * Spread attributes for a toast's content (wrapper) element. */ get content(): { readonly "data-melt-toaster-toast-content": ""; readonly id: string; readonly role: "alert"; readonly "aria-labelledby": string; readonly "aria-describedby": string; readonly "aria-live": "assertive" | "polite"; readonly tabindex: -1; readonly onpointerenter: (e: PointerEvent) => void; readonly onpointerleave: (e: PointerEvent) => void; }; /** * Spread attributes for a toast's title element. */ get title(): { id: string; }; /** * Soread attributes for a toast's description element. */ get description(): { id: string; }; /** * Spread attributes for a toast's close button element. */ get close(): { readonly "data-melt-toaster-toast-close": ""; readonly onclick: () => void; }; } export {};