Skip to main content

toast

The toast component is used to display temporary notifications or messages to the user.

info

A toast is a notification that appears on the top right of the desktop.
A notif is a tooltip-like notification that is anchored to a specific element.

Usage

Modular:

import { toast } from "/42/ui/components/toasts.js"
// Or
const { toast } = sys42

const myToast = toast({
message: "Hello, World!",
timeout: 3000
})

Method parameters

ParameterTypeRequiredDefaultDescription
messageString/objectNot if options is presentShort dialog message
optionsObjectNot if message is presentContains all toast configuration properties.

Options

PropertyTypeRequiredDefaultDescription
messageStringYesThe message to display in the toast.
pictoPictoNoA picto element.
containedBooleanNo
iconStringNoIcon path.
labelStringNo
footerStringNo
beforeContentStringNo
closeableBooleanNo
afterContentStringNo
closeOnContextMenuBooleanNo
animateFromObject: {translate: String(percentage), opacity: Number}No{ translate: "100%", opacity: 0 }
timeoutIntegerNo500
animateToObject: {translate: String(percentage), opacity: Number}No
containerHTMLElementNodocument.documentElement

Examples

Basic Toast

const options = {
message: "Hello, World!",
timeout: 3000
};
toast(options);

Toast with Icon and Picto

const options = {
message: "File uploaded successfully!",
icon: "/path/to/icon.png",
picto: "checkmark"
};
toast(options);

Toast with Custom Animation

const options = {
message: "Loading...",
animateFrom: { translate: "-50%", opacity: 0 },
animateTo: { translate: "0%", opacity: 1 },
timeout: 1000
};
toast(options);