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/toast.js"
// Or
const { toast } = sys42

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

Method parameters

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

Options

PropertyTypeDescription
messageStringRequired. The message to display in the toast.
pictoPictoA picto element.
containedBoolean
iconStringIcon path.
labelString
footerString
beforeContentString
closeableBoolean
afterContentString
closeOnContextMenuBoolean
animateFromObject: {translate: String(percentage), opacity: Number}Default: { translate: "100%", opacity: 0 }
timeoutIntegerDefault: 500
animateToObject: {translate: String(percentage), opacity: Number}
containerHTMLElementDefault: document.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);