Use the Toast component to display short messages to users temporarily on the corner of the browser. Use to provide feedback, alerts, or notifications.
Preview
To trigger the toast, import the toast function from webcoreui, and call it when the button is clicked. The function expects a query selector that select the Toast component.
Positions
The Toast component can be configured to be shown in different positions on the screen. By default, it’ll be visible in the bottom-right corner. To change its position, set the position prop to one of bottom-left, top-left, top-right, bottom-full, or top-full.
Toast with Titles
Toasts can be created with titles using the title and titleTag props:
Themes
The Toast component comes with four different themes out of the box that can be configured with the theme prop: info, success, warning, alert:
Toast with Custom Icon
The Toast element can also be triggered with a custom icon in the following way:
For Astro and Svelte components, pass a children with a slot named icon. For the React component, pass your icon to the icon prop.
JavaScript API
The Toast component also comes with a JavaScript API that lets you trigger the toast, as well as set the default timeout for toasts after which they disappear, or hide them programmatically.
The toast function can also accept a configuration object that lets you programmatically change the content and behavior of your toast:
Function
Purpose
setDefaultTimeout
Sets the default timeout. Defaults to 5 seconds. Expects time in milliseconds.
toast
Shows Toast component. Expects a query selector, or a toast config.
hideToast
Hides active toast. Expects a query selector.
API
Timeline Prop
Purpose
position
Sets the position of the toast. Defaults to bottom-right.
element
Sets the HTML element of the toast. Defaults to section.
title
Sets a title for the toast.
titleTag
Sets the HTML element for the title of the toast. Defaults to strong.
className
Pass additional CSS classes for the toast.
theme
Sets the theme of the toast. Can be one of info, success, warning, alert.
React prop
Purpose
icon
Pass your Icon component to use a custom icon with the toast.