Interface IMBSnackbarService
Interface for the Material.Blazor snackbar service, developed from the code base of Blazored Snackbar by Chris Sainty. Works in conjunction with a MBAnchor that must be placed in either App.razor or MainLayout.razor to avoid an exception being thrown when you first attempt to show a snackbar notification.
Throws a InvalidOperationException if ShowSnackbar(String, Action, String, String, Nullable<MBNotifierCloseMethod>, Boolean, Boolean, Nullable<Int32>, Boolean) is called without an MBAnchor component used in the app.
You can optionally add configuration when you add this to the service collection:
services.AddMBServices(snackbarServiceConfiguration: new MBSnackbarServiceConfiguration()
{
Timeout = 4000,
CloseMethod = MBSnackbarCloseMethod.Timeout,
... etc
});
Namespace: Material.Blazor
Assembly: Material.Blazor.dll
Syntax
public interface IMBSnackbarService
Properties
| Improve this Doc View SourceConfiguration
Snackbar service configuration
Declaration
MBSnackbarServiceConfiguration Configuration { get; set; }
Property Value
Type | Description |
---|---|
MBSnackbarServiceConfiguration |
Methods
| Improve this Doc View SourceShowSnackbar(String, Action, String, String, Nullable<MBNotifierCloseMethod>, Boolean, Boolean, Nullable<Int32>, Boolean)
Shows a snackbar using the supplied settings. Only the level and message parameters are required, with the remainder haveing defaults specified by the MBSnackbarServiceConfiguration that you can supply when registering services. Failing that Material.Blazor provides defaults.
Declaration
void ShowSnackbar(string message, Action action = null, string actionText = null, string additionalClass = null, MBNotifierCloseMethod? closeMethod = null, bool leading = false, bool stacked = false, int? timeout = null, bool debug = false)
Parameters
Type | Name | Description |
---|---|---|
String | message | Body text in the snackbar |
Action | action | The action that is performed when the button in the snackbar is clicked (optional. if set, 'actionText' must also be set) |
String | actionText | The text to display in the action button in the snackbar (optional. if set, 'action' must also be set) |
String | additionalClass | The name of a class to be added to the snackbar surface |
Nullable<MBNotifierCloseMethod> | closeMethod | Snackbars are intended to dismiss on their own after a few seconds, but a dedicated dismiss icon may be optionally included as well for accessibility purposes |
Boolean | leading | By default, snackbars are centered horizontally within the viewport. On larger screens, they can optionally be displayed on the leading edge of the screen (the left side in LTR, or the right side in RTL) |
Boolean | stacked | Action buttons with long text should be positioned below the label instead of alongside it |
Nullable<Int32> | timeout | Length of time before autodismiss |
Boolean | debug | If true only shows snackbars when compiling in DEBUG mode |
Events
| Improve this Doc View SourceOnAdd
A event that will be invoked when showing a snackbar
Declaration
event Action<MBSnackbarSettings> OnAdd
Event Type
Type | Description |
---|---|
Action<MBSnackbarSettings> |
OnTriggerStateHasChanged
A event that will be invoked when snackbars should call StateHasChanged. This will be when the configuration is updated.
Declaration
event Action OnTriggerStateHasChanged
Event Type
Type | Description |
---|---|
Action |