ToastService
The ToastService is a service that can be used to show toasts. It can be injected into a page and used to show different type of toasts.
For a component to be useable by the ToastService, it needs to implement IToastContentComponent<T>
where T
represent the type of the data to be shown in the toast.
The ToastService is automatically registered in the DI container with the AddFluentUIComponents()
call.
Toast container
Toasts are rendered through the <FluentToastProvider />
component. This component needs to be added to the main layout of your application/site.
You typically do this in the MainLayout.razor
file at the end of the <main>
section like this:
<main>
<nav>
<!-- -->
</nav>
<div class="content">
<article id="article">
@Body
</article>
</div>
<FluentToastProvider MaxToastCount="10" />
</main>
IMPORTANT!!
For the
<FluentToastProvider/>
to work properly, it needs interactivity! If you are using "per page" interactivity or ASP.NET Core 8 or above with Server Side Rendering , make sure to add a@rendermode
to either the provider itself or the component the provider is placed in.
See the documentation below for more information about the FluentToastProvider
parameters.
Examples
See the toast page for examples of the different types of available toasts:
- Confirmation toast
- Communication toast
- Progress toast
Documentation
ToastService Class
Methods
Name | Parameters | Type | Description |
---|---|---|---|
ClearAll | bool includeQueue | void | Removes all toasts |
ClearCustomIntentToasts | bool includeQueue | void | Removes all toasts with toast intent Custom |
ClearDownloadToasts | bool includeQueue | void | Removes all toasts with toast intent Download |
ClearErrorToasts | bool includeQueue | void | Removes all toasts with toast intent Error |
ClearEventToasts | bool includeQueue | void | Removes all toasts with toast intent Event |
ClearInfoToasts | bool includeQueue | void | Removes all toasts with toast intent Info |
ClearIntent | ToastIntent intent bool includeQueue | void | Removes all toasts with a specified intent. |
ClearMentionToasts | bool includeQueue | void | Removes all toasts with toast intent Mention |
ClearProgressToasts | bool includeQueue | void | Removes all toasts with toast intent Progress |
ClearQueue | void | Removes all queued toasts | |
ClearQueueCustomIntentToasts | void | Removes all queued toasts with toast intent Custom | |
ClearQueueDownloadToasts | void | Removes all queued toasts with toast intent Download | |
ClearQueueErrorToasts | void | Removes all queued toasts with toast intent Error | |
ClearQueueEventToasts | void | Removes all queued toasts with toast intent Event | |
ClearQueueInfoToasts | void | Removes all queued toasts with toast intent o | |
ClearQueueMentionToasts | void | Removes all queued toasts with toast intent Mention | |
ClearQueueProgressToasts | void | Removes all queued toasts with toast intent Progress | |
ClearQueueSuccessToasts | void | Removes all queued toasts with toast intent Success | |
ClearQueueToasts | ToastIntent intent | void | Removes all queued toasts with a specified intent. |
ClearQueueUploadToasts | void | Removes all queued toasts with toast intent Upload | |
ClearQueueWarningToasts | void | Removes all queued toasts with toast intent Warning | |
ClearSuccessToasts | bool includeQueue | void | Removes all toasts with toast intent Success |
ClearUploadToasts | bool includeQueue | void | Removes all toasts with toast intent Upload |
ClearWarningToasts | bool includeQueue | void | Removes all toasts with toast intent Warning |
CloseToast | string id | void | |
ShowCommunicationToast | ToastParameters<CommunicationToastContent> parameters | void | |
ShowConfirmationToast | ToastParameters<ConfirmationToastContent> parameters | void | |
ShowCustom | string title int? timeout string topAction EventCallback<ToastResult>? callback (Icon Value, Color Color)? icon | void | Shows a simple custom confirmation toast. Only shows icon, title and close button or action. |
ShowDownload | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple download confirmation toast. Only shows icon, title and close button or action. |
ShowError | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple error confirmation toast. Only shows icon, title and close button or action. |
ShowEvent | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple event confirmation toast. Only shows icon, title and close button or action. |
ShowInfo | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple information confirmation toast. Only shows icon, title and close button or action. |
ShowMention | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple mention confirmation toast. Only shows icon, title and close button or action. |
ShowProgress | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple progress confirmation toast. Only shows icon, title and close button or action. |
ShowProgressToast | ToastParameters<ProgressToastContent> parameters | void | |
ShowSuccess | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple succes confirmation toast. Only shows icon, title and close button or action. |
ShowToast | ToastIntent intent string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a toast using the supplied parameters |
ShowToast<T, TData> | ToastParameters<TData> parameters | void | Shows the toast with the component type |
ShowToast<TContent> | Type component ToastParameters parameters TContent content | void | Shows a toast with the component type as the body, passing the specified parameters |
ShowUpload | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple upload confirmation toast. Only shows icon, title and close button or action. |
ShowWarning | string title int? timeout string topAction EventCallback<ToastResult>? callback | void | Shows a simple warning confirmation toast. Only shows icon, title and close button or action. |
UpdateToast<TContent> | string id ToastParameters<TContent> parameters | void | Updates a toast |
FluentToastProvider Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
MaxToastCount | int | 4 | Gets or sets the maximum number of toasts that can be shown at once. Default is 4. |
Position | ToastPosition | TopRight | Gets or sets the position on screen where the toasts are shown. See ToastPosition Default is ToastPosition.TopRight |
RemoveToastsOnNavigation | bool | True | Gets or sets whether to remove toasts when the user navigates to a new page. Default is true. |
ShowCloseButton | bool | True | Gets or sets whether to show a close button on a toast. Default is true. [Obsolete('This parameter will be removed in a future version. It is and should not not used.')] |
Timeout | int | 7000 | Gets or sets the number of milliseconds a toast remains visible. Default is 7000 (7 seconds). |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
RemoveToast | string toastId | void |