Skip to main content

Toast

A toast is a non-modal, unobtrusive window element used to display brief, auto-expiring windows of information to a user.

Basic usage


First, you need to add the bl-toast-container component to your page. This component will be used to display the toasts.

<bl-toast-container></bl-toast-container>

Then, you can use the Toast class to display toasts.

import { Toast } from 'bloum';
Toast.info('This is an info toast');

You can also use the Toast class directly in your HTML because it is exposed in the global scope.

<button onclick="Toast.info('This is an info toast')">
Show info toast
</button>
<bl-toast-container></bl-toast-container>

Status


import { Toast } from 'bloum';
Toast.success('This is a success toast');
Toast.warning('This is a warning toast');
Toast.error('This is an error toast');
Toast.info('This is an info toast');

Dismissable


import { Toast } from 'bloum';
Toast.info('This is an info toast', { isClosable: true });
Toast.info("This toast won't disappear", { isClosable: true, duration: 0 });

Description


import { Toast } from 'bloum';
Toast.info('This is an info toast', { description: 'This is a description' });

API

ToastOptions

Use the ToastOptions interface to customize the toasts:

NameTypeDefaultDescription
titlestringundefinedrequired The title of the toast.
descriptionstringundefinedAn optional description of the toast.
isClosablebooleanfalseWhether the toast can be dismissed by the user or not.
durationnumber8000The duration of the toast in milliseconds. Use 0 or a negative value to prevent the toast from disappearing.
statusstringinfoThe status of the toast. Can be info, success, warning or error.
onClosefunctionundefinedA callback function that will be called when the toast is dismissed.

Toast.info(title, options)

Display an info toast.

NameTypeDefaultDescription
titlestringundefinedThe message of the toast.
optionsToastOptionsundefinedThe options of the toast.

Toast.success(title, options)

Display a success toast.

NameTypeDefaultDescription
titlestringundefinedThe message of the toast.
optionsToastOptionsundefinedThe options of the toast.

Toast.warning(title, options)

Display a warning toast.

NameTypeDefaultDescription
titlestringundefinedThe message of the toast.
optionsToastOptionsundefinedThe options of the toast.

Toast.error(title, options)

Display an error toast.

NameTypeDefaultDescription
titlestringundefinedThe message of the toast.
optionsToastOptionsundefinedThe options of the toast.

Toast.show(options)

Display a toast.

NameTypeDefaultDescription
optionsToastOptionsundefinedThe options of the toast.