Skip to content

Toast

The Toast component displays temporary notification messages that appear at the top-right of the screen. It provides a flexible way to show success messages, errors, or other notifications to users.

import {
Button,
Toast,
createToaster,
} from '@fintech-sandpit/ui/react';
import { faXmark } from '@fortawesome/free-solid-svg-icons';
import { Icon } from '@fintech-sandpit/ui/react';
const toaster = createToaster({
placement: 'bottom-start',
});
function MyComponent() {
const showToast = () => {
toaster.create({
type: 'success',
title: 'Success!',
description: 'Your changes have been saved.',
});
};
return (
<>
<Toast.Toaster toaster={toaster}>
{toast => (
<Toast.Root key={toast.id}>
<Toast.Title>
{toast.title}
</Toast.Title>
<Toast.Description>
{toast.description}
</Toast.Description>
{toast.closable && <Toast.CloseTrigger />}
</Toast.Root>
)}
</Toast.Toaster>
<Button
colorScheme="primary"
onClick={showToast}
>
Show Toast
</Button>
</>
);
}
NameTypeDefaultDescription
placementToasterPlacementtop-endPlacement of the toast container
gapnumber8Gap between toast items
NameTypeDefaultDescription
titlestringTitle of the toast
descriptionstringDescription text of the toast
typeToastTypeinfoType of the toast
durationnumber5000Duration in milliseconds before auto-dismissing (0 to disable)

The root component (Toaster) that manages all toast notifications. Should be placed at the root of your application, typically in the main layout or App component.

Individual toast component. Typically rendered automatically by the Toaster, but can be used directly for custom implementations.

The title component for a toast notification.

The description component for a toast notification.

A button that closes the toast when clicked. Automatically included in toast notifications.

A hook that provides methods to create and manage toast notifications.

Methods:

  • create(options) - Creates a new toast notification
  • dismiss(id) - Dismisses a specific toast by ID
  • dismissAll() - Dismisses all toast notifications
type ToasterPlacement = 'top-start' | 'top' | 'top-end' | 'bottom-start' | 'bottom' | 'bottom-end'
type ToastType = 'info' | 'success' | 'warning' | 'error' | 'loading'