Skip to content

AisToast ​

AisToast displays a brief, non-critical message in a way that attracts the user’s attention without interrupting the current task. Toasts are displayed around a container's periphery and are dismissed with a click or after a specified duration. By default, AisToast uses AisAlert to display the message and the useAisToast composable to build message objects. Developers may customize the look-and-feel of the toast by using the display slot.

AisToast and useAisToast are designed such that the component is decoupled from how its messages are stored and manipulated. Many applications will want an app-wide messaging system where AisToast is configured on the layout and backed by a global Pinia store. In this case, components can import the store, initialize the composable, and write messages the layout will automatically render. In other cases, like the examples on this page, the toast component, message array, and composable will be located together.

Introduction ​

Explore the example below to get a feel for AisToast. By default, the component will display messages as secondary alerts in the bottom-right corner of the browser window. AisToast can display multiple messages, which will stack. All messages will share the same placement. Details like variant, icon, and duration are specified on a per-message basis.

Props ​

messages ​

messages is a required prop that takes an array of AisUserMessage objects to be displayed by AisToast. useAisToast exposes the message(msg, options) function (and related variants) to create the objects. The remove(uuid) function can be used to remove a message when it is dismissed or its duration expires. See the AisUserMessage definition below for details.

ts
import {AisVariant} from "@/types/AisVariant";

export interface AisUserMessage {
    uuid?: string,
    title?: string,
    message?: string,
    details?: string[],
    variant?: AisVariant,
    icon?: any,
    dismissible?: boolean,
    duration?: number,
    dismissLabel?: string,
}

placement ​

This prop dictates the placement of the toast messages. By default, toasts are positioned relative to the browser window, but that can be changed with the position prop. The valid placements are top-right, top-center, top-left, bottom-right, bottom-center, and bottom-left.

position ​

postion dictates the type of CSS positioning used for AisToast. fixed is the default value, which positions the toasts relative to the browser window. Note the first example uses Vue's <Teleport> component to attach the toast group directly to the document <body>. This is a best-practice when using fixed positioning.

Use absolute to position the toast messages relative to an ancestor. This allows toasts to be used in a smaller more targeted part of your interface as illustrated in the example below. See absolute positioning in the TailwindCSS docs for details. Absolute positioning will position the element relative to its first ancestor with relative positioning.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac ultricies sapien, id bibendum ex. Integer vitae mi varius, tincidunt lacus sit amet, elementum enim. Sed interdum mauris in ultricies consectetur. Praesent mollis ex ut placerat lacinia. Integer nec ligula pharetra, semper lorem id, ultricies purus. Nunc sollicitudin mollis erat, vel suscipit erat sodales eu. Nulla vitae laoreet ligula, at blandit purus. Curabitur ut erat eu tellus ultrices molestie at vel neque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porta nibh egestas diam tempus placerat. Proin accumsan auctor risus, non congue lacus mollis non. Proin sed magna ut dui vulputate malesuada in in enim. Donec ultricies nibh ac pretium cursus. Integer at sapien tempus, rutrum tellus non, rutrum sem. Curabitur id metus lacus.

Additional props ​

See the Component Reference for additional props to customize AisToast details.

Events ​

@dismiss ​

The @dismiss event is triggered when a user closes a specific toast message. The event payload is the uuid of the message, which can be passed to the remove() function exposed by useAisToast.

Slots ​

display ​

Use the display slot to customize the markup for the toast message. The current message object is passed to the slot along with the triggerDismissEvent method.

Component Reference ​

Props ​

Property
Type(s)
Required
Default
Description
Deprecated
margin
String
'm-0 sm:m-4'
Margin around the toast group - use Tailwind classes
false
messages
Array
Array of active toast messages
false
placement
ToastPlacement
'top-center'
Placement of the toast group relative to its container
false
position
ToastPosition
'fixed'
TailwindCSS position class
false
width
String
'w-screen sm:w-auto max-w-full md:max-w-fit lg:max-w-lg xl:max-w-lg'
TailwindCSS classes dictating the width of the toast group
false
zIndex
String
'z-toast'
TailwindCSS z-index class. Defaults to z-toast, the top layer of the library scale
false

Slots ​

Name
Scoped
Description
display
Scoped slot for custom rendering the toast message

Events ​

Event
Arguments
Description
dismiss
  • UUID
    string
    -
    of the toast to remove
Emitted when a toast is clicked to dismiss