|
|
|
@ -19,6 +19,65 @@ |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" OnClick="@ShowDToast">Open</FluentButton> |
|
|
|
|
</FluentCard> |
|
|
|
|
|
|
|
|
|
<h4 class="mt-4">Toast with options</h4> |
|
|
|
|
<FluentCard Class="mt-3" Width="auto" Height="auto"> |
|
|
|
|
<p> |
|
|
|
|
Click ont this button to open a Toast with option. |
|
|
|
|
The toast is created by specifting an intent, message, action and a random timout between 2 and 5 seconds. |
|
|
|
|
</p> |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" OnClick="@ShowWOToast">Open</FluentButton> |
|
|
|
|
<p> |
|
|
|
|
<b>Message</b>: @woMessage?.ToString() |
|
|
|
|
</p> |
|
|
|
|
</FluentCard> |
|
|
|
|
|
|
|
|
|
<h4 class="mt-4">Confirmation Toasts</h4> |
|
|
|
|
<FluentCard Class="mt-3" Width="auto" Height="auto"> |
|
|
|
|
<FluentStack Wrap="true" VerticalGap="10"> |
|
|
|
|
@foreach (var intent in toastIntentArray) |
|
|
|
|
{ |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" |
|
|
|
|
OnClick="@(() => ToastService.ShowToast(intent, $"{intent.ToString()} confrmation."))"> |
|
|
|
|
@intent.ToString() Toast |
|
|
|
|
</FluentButton> |
|
|
|
|
} |
|
|
|
|
</FluentStack> |
|
|
|
|
</FluentCard> |
|
|
|
|
|
|
|
|
|
<h4 class="mt-4">Communication Toasts</h4> |
|
|
|
|
<FluentCard Class="mt-3" Width="auto" Height="auto"> |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" OnClick="@ShowCoToast"> |
|
|
|
|
Show Communication Toast |
|
|
|
|
</FluentButton> |
|
|
|
|
<p> |
|
|
|
|
<b>Message</b>: @coMessage?.ToString() |
|
|
|
|
</p> |
|
|
|
|
</FluentCard> |
|
|
|
|
|
|
|
|
|
<h4 class="mt-4">Progress Toasts</h4> |
|
|
|
|
<FluentCard Class="mt-3" Width="auto" Height="auto"> |
|
|
|
|
<FluentStack Orientation="Orientation.Horizontal" Wrap="true"> |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" OnClick="@ShowPToast"> |
|
|
|
|
Show Toast |
|
|
|
|
</FluentButton> |
|
|
|
|
<FluentButton @ref="pUpdateButton" Appearance="Appearance.Accent" OnClick="@UpdateProgress"> |
|
|
|
|
Update |
|
|
|
|
</FluentButton> |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" OnClick="@Reset"> |
|
|
|
|
Reset |
|
|
|
|
</FluentButton> |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" OnClick="@Close"> |
|
|
|
|
Close |
|
|
|
|
</FluentButton> |
|
|
|
|
<FluentButton Appearance="Appearance.Accent" OnClick="@ShowPIndeterminateToast"> |
|
|
|
|
Show Indeterminate Toast |
|
|
|
|
</FluentButton> |
|
|
|
|
</FluentStack> |
|
|
|
|
<p> |
|
|
|
|
<b>Message</b>: @pMessage?.ToString() |
|
|
|
|
</p> |
|
|
|
|
</FluentCard> |
|
|
|
|
|
|
|
|
|
@code { |
|
|
|
|
int dcounter = 1; |
|
|
|
|
void ShowDToast() |
|
|
|
@ -27,4 +86,126 @@ |
|
|
|
|
var message = $"Simple Toast #{dcounter++}"; |
|
|
|
|
ToastService.ShowToast(intent, message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int woCouner = 1; |
|
|
|
|
string? woMessage; |
|
|
|
|
void ShowWOToast() |
|
|
|
|
{ |
|
|
|
|
var intent = Enum.GetValues<ToastIntent>()[Random.Shared.Next(10)]; |
|
|
|
|
int timeout = Random.Shared.Next(2000, 5000); |
|
|
|
|
var message = $"Simple Toast with options #{dcounter++} (Timeout: {timeout}ms)"; |
|
|
|
|
|
|
|
|
|
ToastService.ShowToast( |
|
|
|
|
intent, |
|
|
|
|
message, |
|
|
|
|
timeout, |
|
|
|
|
"Action", |
|
|
|
|
EventCallback.Factory.Create<ToastResult>(this, (e) => woMessage = $"Toast with options clicked!") |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static ToastIntent[] toastIntentArray = Enum.GetValues<ToastIntent>(); |
|
|
|
|
|
|
|
|
|
string? coMessage; |
|
|
|
|
void ShowCoToast() |
|
|
|
|
{ |
|
|
|
|
ToastService.ShowCommunicationToast(new ToastParameters<CommunicationToastContent>() |
|
|
|
|
{ |
|
|
|
|
Intent = ToastIntent.Success, |
|
|
|
|
Title = "This is communication toast", |
|
|
|
|
Timeout = 4000, |
|
|
|
|
PrimaryAction = "Primary Action", |
|
|
|
|
OnPrimaryAction = EventCallback.Factory.Create<ToastResult>(this, (e) => coMessage = "PrimaryAction clicked"), |
|
|
|
|
SecondaryAction = "Secondary Action", |
|
|
|
|
OnSecondaryAction = EventCallback.Factory.Create<ToastResult>(this, (e) => coMessage = "SecondaryAction clicked"), |
|
|
|
|
Content = new CommunicationToastContent() |
|
|
|
|
{ |
|
|
|
|
Subtitle = "A communication toast subtitle", |
|
|
|
|
Details = "A communication toast details. This toast can help you give more information." |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FluentButton? pUpdateButton; |
|
|
|
|
static string pId = "progressToast"; |
|
|
|
|
CancellationTokenSource pCancel = new CancellationTokenSource(); |
|
|
|
|
ToastParameters<ProgressToastContent> pToastData; |
|
|
|
|
ToastParameters<ProgressToastContent> pToastDataIndeterminate; |
|
|
|
|
string? pMessage; |
|
|
|
|
|
|
|
|
|
protected override void OnInitialized() |
|
|
|
|
{ |
|
|
|
|
pToastData = new ToastParameters<ProgressToastContent>() |
|
|
|
|
{ |
|
|
|
|
Id = pId, |
|
|
|
|
Intent = ToastIntent.Progress, |
|
|
|
|
Title = "Processing data", |
|
|
|
|
Timeout = 0, |
|
|
|
|
TopAction = "Cancel", |
|
|
|
|
OnTopAction = EventCallback.Factory.Create<ToastResult>(this, (e) => pMessage = "Cancel clicked"), |
|
|
|
|
Content = new ProgressToastContent() |
|
|
|
|
{ |
|
|
|
|
Details = "This may take a while.", |
|
|
|
|
Progress = 0, |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
pToastDataIndeterminate = new ToastParameters<ProgressToastContent>() |
|
|
|
|
{ |
|
|
|
|
Id = $"{pId}Indeterminate", |
|
|
|
|
Intent = ToastIntent.Progress, |
|
|
|
|
Title = "Processing data", |
|
|
|
|
Timeout = 5000, |
|
|
|
|
TopAction = "Cancel", |
|
|
|
|
OnTopAction = EventCallback.Factory.Create<ToastResult>(this, (e) => pMessage = "Cancel clicked"), |
|
|
|
|
Content = new ProgressToastContent() |
|
|
|
|
{ |
|
|
|
|
Details = "This will close after the 7000ms", |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected override void OnAfterRender(bool firstRender) |
|
|
|
|
{ |
|
|
|
|
if (firstRender) |
|
|
|
|
pUpdateButton.SetDisabled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ShowPToast() |
|
|
|
|
{ |
|
|
|
|
pUpdateButton.SetDisabled(false); |
|
|
|
|
ToastService.ShowProgressToast(pToastData); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ShowPIndeterminateToast() |
|
|
|
|
{ |
|
|
|
|
ToastService.ShowProgressToast(pToastDataIndeterminate); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async Task UpdateProgress() |
|
|
|
|
{ |
|
|
|
|
pUpdateButton.SetDisabled(true); |
|
|
|
|
for (int i = 0; i < 101; i++) |
|
|
|
|
{ |
|
|
|
|
pToastData.Content.Progress = i; |
|
|
|
|
ToastService.UpdateToast(pId, pToastData); |
|
|
|
|
await Task.Delay(100, pCancel.Token); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Reset() |
|
|
|
|
{ |
|
|
|
|
pCancel.Cancel(); |
|
|
|
|
pToastData.Content.Progress = 0; |
|
|
|
|
ToastService.UpdateToast(pId, pToastData); |
|
|
|
|
pCancel = new CancellationTokenSource(); |
|
|
|
|
pUpdateButton.SetDisabled(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Close() |
|
|
|
|
{ |
|
|
|
|
Reset(); |
|
|
|
|
ToastService.CloseToast(pId); |
|
|
|
|
pUpdateButton.SetDisabled(true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|