Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve BitSnackBar demo (#8568) #8580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public partial class BitSnackBar : BitComponentBase



/// <summary>
/// Shows the snackbar.
/// </summary>
public async Task Show(string title, string? body = "", BitSnackBarType type = BitSnackBarType.None, string? cssClass = null, string? cssStyle = null)
{
var item = new BitSnackBarItem
Expand Down Expand Up @@ -83,12 +86,24 @@ public async Task Show(string title, string? body = "", BitSnackBarType type = B
await InvokeAsync(StateHasChanged);
}

/// <summary>
/// Shows the snackbar with Info type.
/// </summary>
public Task Info(string title, string? body = "") => Show(title, body, BitSnackBarType.Info);

/// <summary>
/// Shows the snackbar with Success type.
/// </summary>
public Task Success(string title, string? body = "") => Show(title, body, BitSnackBarType.Success);

/// <summary>
/// Shows the snackbar with Warning type.
/// </summary>
public Task Warning(string title, string? body = "") => Show(title, body, BitSnackBarType.Warning);

/// <summary>
/// Shows the snackbar with Error type.
/// </summary>
public Task Error(string title, string? body = "") => Show(title, body, BitSnackBarType.Error);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
ComponentDescription="SnackBars provide brief notifications. The component is also known as a toast."
ComponentParameters="componentParameters"
ComponentSubEnums="componentSubEnums"
ComponentSubClasses="componentSubClasses">
<ComponentExampleBox Title="Type & Position" RazorCode="@example1RazorCode" CsharpCode="@example1CsharpCode" Id="example1">
ComponentSubClasses="componentSubClasses"
ComponentPublicMembers="componentPublicMembers">
<ComponentExampleBox Title="Basic" RazorCode="@example1RazorCode" CsharpCode="@example1CsharpCode" Id="example1">
<ExamplePreview>
<BitSnackBar @ref="basicRef" />
<BitButton OnClick="OpenBasicSnackBar">Open SnackBar</BitButton>
</ExamplePreview>
</ComponentExampleBox>

<ComponentExampleBox Title="Customization" RazorCode="@example2RazorCode" CsharpCode="@example2CsharpCode" Id="example2">
<ExamplePreview>
<div class="example-box">
<BitSnackBar @ref="basicSnackBarRef"
<BitSnackBar @ref="customizationRef"
Dir="direction"
Position="@basicSnackBarPosition"
AutoDismiss="@basicSnackBarAutoDismiss"
Expand Down Expand Up @@ -51,146 +59,63 @@
<BitNumberField @bind-Value="basicSnackBarDismissSeconds" Step="1" Min="1" Label="Dismiss Time (based on second)" />
</div>
</div>
<BitButton Style="margin-top: 20px;" OnClick="OpenBasicSnackBar">Show</BitButton>
<br />
<BitButton OnClick="OpenCustomizationSnackBar">Show</BitButton>
</ExamplePreview>
</ComponentExampleBox>

<ComponentExampleBox Title="Templates" RazorCode="@example2RazorCode" CsharpCode="@example2CsharpCode" Id="example2">
<ComponentExampleBox Title="Templates" RazorCode="@example3RazorCode" CsharpCode="@example3CsharpCode" Id="example3">
<ExamplePreview>
<div class="example-box">
<div>
<BitSnackBar @ref="dismissIconNameRef" DismissIconName="@BitIconName.Go" />
<BitButton OnClick="OpenDismissIconName">Dismiss Icon Name</BitButton>
</div>

<div>
<BitSnackBar @ref="titleTemplateRef" AutoDismiss="false">
<TitleTemplate Context="title">
<div style="display: flex; flex-direction: row; gap: 10px;">
<span>@title</span>
<BitProgress Thickness="20" Style="width: 40px;" Indeterminate />
</div>
</TitleTemplate>
</BitSnackBar>
<BitButton OnClick="OpenTitleTemplate">Title Template</BitButton>
</div>

<div>
<BitSnackBar @ref="bodyTemplateRef" AutoDismiss="false">
<BodyTemplate Context="body">
<div style="display: flex; flex-flow: column nowrap; gap: 5px;">
<span style="font-size: 12px; margin-bottom: 5px;">@body</span>
<div style="display: flex; gap: 10px;">
<BitButton OnClick="@(() => bodyTemplateAnswer = "Yes")">Yes</BitButton>
<BitButton OnClick="@(() => bodyTemplateAnswer = "No")">No</BitButton>
</div>
<span>Answer: @bodyTemplateAnswer</span>
</div>
</BodyTemplate>
</BitSnackBar>
<BitButton OnClick="OpenBodyTemplate">Body Template</BitButton>
</div>
</div>
<BitSnackBar @ref="dismissIconNameRef" DismissIconName="@BitIconName.Go" />
<BitButton OnClick="OpenDismissIconName">Dismiss Icon Name</BitButton>
<br /><br />
<BitSnackBar @ref="titleTemplateRef" AutoDismiss="false">
<TitleTemplate Context="title">
<div style="display: flex; flex-direction: row; gap: 10px;">
<span>@title</span>
<BitProgress Thickness="20" Style="width: 40px;" Indeterminate />
</div>
</TitleTemplate>
</BitSnackBar>
<BitButton OnClick="OpenTitleTemplate">Title Template</BitButton>
<br /><br />
<BitSnackBar @ref="bodyTemplateRef" AutoDismiss="false">
<BodyTemplate Context="body">
<div style="display: flex; flex-flow: column nowrap; gap: 5px;">
<span style="font-size: 12px; margin-bottom: 5px;">@body</span>
<div style="display: flex; gap: 10px;">
<BitButton OnClick="@(() => bodyTemplateAnswer = "Yes")">Yes</BitButton>
<BitButton OnClick="@(() => bodyTemplateAnswer = "No")">No</BitButton>
</div>
<span>Answer: @bodyTemplateAnswer</span>
</div>
</BodyTemplate>
</BitSnackBar>
<BitButton OnClick="OpenBodyTemplate">Body Template</BitButton>
</ExamplePreview>
</ComponentExampleBox>

<ComponentExampleBox Title="Style & Class" RazorCode="@example3RazorCode" CsharpCode="@example3CsharpCode" Id="example3">
<ComponentExampleBox Title="Style & Class" RazorCode="@example4RazorCode" CsharpCode="@example4CsharpCode" Id="example4">
<ExamplePreview>
<div class="example-box column">
<div>
<BitLabel>Item's Style & Class:</BitLabel>
<div>
<BitSnackBar @ref="snackBarStyleRef" />
<BitButton OnClick="OpenSnackBarStyle">Custom style</BitButton>
</div>
<br />
<div>
<BitSnackBar @ref="snackBarClassRef" />
<BitButton OnClick="OpenSnackBarClass">Custom style</BitButton>
</div>
</div>
<br />
<div>
<BitLabel>Styles & Classes:</BitLabel>
<div>
<BitSnackBar @ref="snackBarStylesRef"
Styles="@(new() { Container = "width: 16rem; background-color: purple;",
Header = "background-color: rebeccapurple; padding: 0.2rem;" })" />
<BitButton OnClick="OpenSnackBarStyles">Custom styles</BitButton>
</div>
<br />
<div>
<BitSnackBar @ref="snackBarClassesRef"
Classes="@(new() { Container = "custom-container",
ProgressBar = "custom-progress" })" />
<BitButton OnClick="OpenSnackBarClasses">Custom classes</BitButton>
</div>
</div>
<div>
<div>Item's Style & Class:</div><br />
<BitSnackBar @ref="snackBarStyleRef" />
<BitButton OnClick="OpenSnackBarStyle">Custom style</BitButton>
<br /><br />
<BitSnackBar @ref="snackBarClassRef" />
<BitButton OnClick="OpenSnackBarClass">Custom style</BitButton>
<br /><br /><br /><br />
<div>Styles & Classes:</div><br />
<BitSnackBar @ref="snackBarStylesRef"
Styles="@(new() { Container = "width: 16rem; background-color: purple;",
Header = "background-color: rebeccapurple; padding: 0.2rem;" })" />
<BitButton OnClick="OpenSnackBarStyles">Custom styles</BitButton>
<br /><br />
<BitSnackBar @ref="snackBarClassesRef"
Classes="@(new() { Container = "custom-container",
ProgressBar = "custom-progress" })" />
<BitButton OnClick="OpenSnackBarClasses">Custom classes</BitButton>
</div>
</ExamplePreview>
</ComponentExampleBox>
</ComponentDemo>

@code {
private BitSnackBar basicSnackBarRef = new();
private BitDir direction;
private BitSnackBarType basicSnackBarType = BitSnackBarType.Info;
private BitSnackBarPosition basicSnackBarPosition = BitSnackBarPosition.BottomRight;
private string basicSnackBarTitle = string.Empty;
private string basicSnackBarBody = string.Empty;
private bool basicSnackBarAutoDismiss = true;
private int basicSnackBarDismissSeconds = 3;

private async Task OpenBasicSnackBar()
{
await basicSnackBarRef.Show(basicSnackBarTitle, basicSnackBarBody, basicSnackBarType);
}


private BitSnackBar dismissIconNameRef = new();
private BitSnackBar titleTemplateRef = new();
private BitSnackBar bodyTemplateRef = new();

private string? bodyTemplateAnswer;

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");
}


private BitSnackBar snackBarStyleRef = new();
private BitSnackBar snackBarClassRef = new();
private BitSnackBar snackBarStylesRef = new();
private BitSnackBar snackBarClassesRef = new();

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");
}
}
</ComponentDemo>
Loading
Loading