Accent color
# SnackBar
**Also known as:** Toast
## Description
SnackBars provide brief notifications. The component is also known as a toast.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| AutoDismiss | `bool` | false | Whether or not automatically dismiss the snack bar. |
| AutoDismissTime | `TimeSpan?` | null | How long does it take to automatically dismiss the snack bar (default is 3 seconds). |
| BodyTemplate | `RenderFragment<string>?` | null | Used to customize how the content inside the body is rendered. |
| Classes | `BitSnackBarClassStyles?` | null | Custom CSS classes for different parts of the snack bar. |
| DismissIcon | `BitIconInfo?` | null | Gets or sets the icon of the dismiss button using custom CSS classes for external icon libraries. Takes precedence over DismissIconName when both are set. |
| DismissIconName | `string?` | null | The icon name of the dismiss button from the built-in Fluent UI icons. |
| Multiline | `bool` | false | Enables the multiline mode of both title and body. |
| OnDismiss | `EventCallback` | | Callback for when any snack bar is dismissed. |
| Persistent | `bool` | false | Makes the snack bar non-dismissible in UI and removes the dismiss button. |
| Position | `BitSnackBarPosition?` | null | The position of the snack bars to show. |
| Styles | `BitSnackBarClassStyles?` | null | Custom CSS styles for different parts of the snack bar. |
| TitleTemplate | `RenderFragment<string>?` | null | Used to customize how content inside the title is rendered. |
| AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. |
| ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | `string?` | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | `bool` | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
## Public Members
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Info | `Task<BitSnackBarItem> Info(string title, string? body = "", bool persistent = false)` | | Shows a new snackbar with Info color. |
| Success | `Task<BitSnackBarItem> Success(string title, string? body = "", bool persistent = false)` | | Shows a new snackbar with Success color. |
| Warning | `Task<BitSnackBarItem> Warning(string title, string? body = "", bool persistent = false)` | | Shows a new snackbar with Warning color. |
| SevereWarning | `Task<BitSnackBarItem> SevereWarning(string title, string? body = "", bool persistent = false)` | | Shows a new snackbar with SevereWarning color. |
| Error | `Task<BitSnackBarItem> Error(string title, string? body = "", bool persistent = false)` | | Shows a new snackbar with Error color. |
| Show | `Task<BitSnackBarItem> Show(string title, string? body = "", BitColor color = BitColor.Info, string? cssClass = null, string? cssStyle = null, bool persistent = false)` | | Shows a new snackbar. |
| Show | `Task<BitSnackBarItem> Show(BitSnackBarItem item)` | | Shows a new snackbar. |
| Close | `Task Close(BitSnackBarItem item)` | | Closes a snackbar item. |
| UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. |
## Enums
### BitSnackBarPosition Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| TopStart | 0 | |
| TopCenter | 1 | |
| TopEnd | 2 | |
| BottomStart | 3 | |
| BottomCenter | 4 | |
| BottomEnd | 5 | |
### BitColor Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Primary | 0 | Info Primary general color. |
| Secondary | 1 | Secondary general color. |
| Tertiary | 2 | Tertiary general color. |
| Info | 3 | Info general color. |
| Success | 4 | Success general color. |
| Warning | 5 | Warning general color. |
| SevereWarning | 6 | SevereWarning general color. |
| Error | 7 | Error general color. |
| PrimaryBackground | 8 | Primary background color. |
| SecondaryBackground | 9 | Secondary background color. |
| TertiaryBackground | 10 | Tertiary background color. |
| PrimaryForeground | 11 | Primary foreground color. |
| SecondaryForeground | 12 | Secondary foreground color. |
| TertiaryForeground | 13 | Tertiary foreground color. |
| PrimaryBorder | 14 | Primary border color. |
| SecondaryBorder | 15 | Secondary border color. |
| TertiaryBorder | 16 | Tertiary border color. |
### BitVisibility Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
### BitDir Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
## Sub Classes
### BitIconInfo Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Name | `string?` | null | Gets or sets the name of the icon. |
| BaseClass | `string?` | null | Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. |
| Prefix | `string?` | null | Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty. |
### BitSnackBarClassStyles Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Root | `string?` | null | Custom CSS classes/styles for the root element of the BitSnackBar. |
| Container | `string?` | null | Custom CSS classes/styles for the main container of the BitSnackBar. |
| Header | `string?` | null | Custom CSS classes/styles for the header of the BitSnackBar. |
| DismissButton | `string?` | null | Custom CSS classes/styles for the dismiss button of the BitSnackBar. |
| DismissIcon | `string?` | null | Custom CSS classes/styles for the dismiss icon of the BitSnackBar. |
| Title | `string?` | null | Custom CSS classes/styles for the title of the BitSnackBar. |
| Body | `string?` | null | Custom CSS classes/styles for the body of the BitSnackBar. |
| ProgressBar | `string?` | null | Custom CSS classes/styles for the progress bar of the BitSnackBar. |
### BitSnackBarItem Properties
A class to represent each snack bar item.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Id | `Guid` | Guid.NewGuid() | The unique identifier of the snack bar item. |
| Title | `string` | null | The title text of the snack bar item. |
| Body | `string?` | null | The body text of the snack bar item. |
| Color | `BitColor?` | null | The color theme of the snack bar item. |
| CssClass | `string?` | null | Custom CSS class to apply to the snack bar item. |
| CssStyle | `string?` | null | Custom CSS style to apply to the snack bar item. |
| Persistent | `bool` | false | Makes this specific snack bar item non-dismissible and removes its dismiss button. |
## Examples
\n**Basic**:
```razor
Open SnackBar
```
```csharp
private BitSnackBar basicRef = default!;
private async Task OpenBasicSnackBar()
{
await basicRef.Info("This is title", "This is body");
}
```
\n**Customization**:
```razor
Show
```
```csharp
private BitDir direction;
private bool basicSnackBarMultiline;
private bool basicSnackBarAutoDismiss;
private int basicSnackBarDismissSeconds = 3;
private BitSnackBar customizationRef = default!;
private string basicSnackBarBody = "This is body";
private string basicSnackBarTitle = "This is title";
private BitColor basicSnackBarColor = BitColor.Info;
private BitSnackBarPosition basicSnackBarPosition = BitSnackBarPosition.BottomEnd;
private async Task OpenBasicSnackBar()
{
await basicSnackBarRef.Show(basicSnackBarTitle, basicSnackBarBody, basicSnackBarColor);
}
```
\n**Persistent**:
```razor
Open SnackBar
Close SnackBar
```
```csharp
private BitSnackBarItem? persistentItem;
private BitSnackBar persistentRef = default!;
private async Task OpenPersistentSnackBar()
{
await ClosePersistentSnackBar();
persistentItem = await persistentRef.Info("This is persistent title", "This is persistent body");
}
private async Task ClosePersistentSnackBar()
{
if (persistentItem is not null)
{
await persistentRef.Close(persistentItem);
persistentItem = null;
}
}
```
\n**Templates**:
```razor
Dismiss Icon Name
Title Template
Body Template
```
```csharp
private string? bodyTemplateAnswer;
private BitSnackBar bodyTemplateRef = default!;
private BitSnackBar titleTemplateRef = default!;
private BitSnackBar dismissIconNameRef = default!;
private async Task OpenDismissIconName()
{
await dismissIconNameRef.Success("This is title", "This is body");
}
private async Task OpenTitleTemplate()
{
await titleTemplateRef.Warning("This is title", "This is body");
}
private async Task OpenBodyTemplate()
{
await bodyTemplateRef.Error("This is title", "This is body");
}
```
\n**External Icons**:
```razor
FontAwesome dismiss icon
CSS classes dismiss icon
Bootstrap dismiss icon
Implicit CSS dismiss icon
```
```csharp
private BitSnackBar dismissIconFaRef = default!;
private BitSnackBar dismissIconCssRef = default!;
private BitSnackBar dismissIconBiRef = default!;
private BitSnackBar dismissIconImplicitRef = default!;
private async Task OpenDismissIconFa()
{
await dismissIconFaRef.Info("Notification", "Click the FontAwesome dismiss icon to close.");
}
private async Task OpenDismissIconCss()
{
await dismissIconCssRef.Info("Notification", "Click the CSS class dismiss icon to close.");
}
private async Task OpenDismissIconBi()
{
await dismissIconBiRef.Info("Notification", "Click the Bootstrap dismiss icon to close.");
}
private async Task OpenDismissIconImplicit()
{
await dismissIconImplicitRef.Info("Notification", "Click the implicit CSS dismiss icon to close.");
}
```
\n**Style & Class**:
```razor
Custom style
Custom style
Custom styles
Custom classes
```
```csharp
private BitSnackBar snackBarStyleRef = default!;
private BitSnackBar snackBarClassRef = default!;
private BitSnackBar snackBarStylesRef = default!;
private BitSnackBar snackBarClassesRef = default!;
private async Task OpenSnackBarStyle()
{
await snackBarClassRef.Show("This is title", "This is body", cssStyle: "background-color: dodgerblue; border-radius: 0.5rem;");
}
private async Task OpenSnackBarClass()
{
await snackBarStyleRef.Show("This is title", "This is body", cssClass: "custom-class");
}
private async Task OpenSnackBarStyles()
{
await snackBarStylesRef.Show("This is title", "This is body");
}
private async Task OpenSnackBarClasses()
{
await snackBarClassesRef.Show("This is title", "This is body");
}
```
@title
@body
Yes
No
Answer: @bodyTemplateAnswer